Skip to content

Rule Request: Don't use Strings in the database for UUIDs #648

Description

@jborgers

In a load test it turned out that database access was very slow and took many resources with the use of UUID in String format, used as index.
Example:

String fileId = FileUtils.generateUUID();
String actionsSql = "INSERT INTO actions (id,file_id, action) VALUES (?,?, ?)";
try (PreparedStatement actionsStmt = conn.prepareStatement(actionsSql)) {
    actionsStmt.setString(1, FileUtils.generateUUID());
    actionsStmt.setString(2, fileId);
    actionsStmt.setString(3, Actions.START);
}

Calling a method ending with UUID and setting it as String on a statement is a violation.

It should be:

    UUID fileId = FileUtils.generateUUID();
    [...]
    actionsStmt.setObject(1, FileUtils.generateUUID());
    actionsStmt.setObject(2, fileId);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions