All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fluentjdbc.DatabaseSaveBuilderWithUUID Maven / Gradle / Ivy

There is a newer version: 0.5.3
Show newest version
package org.fluentjdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.UUID;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class DatabaseSaveBuilderWithUUID extends DatabaseSaveBuilder {


    public DatabaseSaveBuilderWithUUID(DatabaseTableImpl table, String idField, @Nullable UUID idValue) {
        super(table, idField, idValue);
    }

    @Override
    @Nullable
    protected UUID insert(Connection connection) {
        UUID idValue = this.idValue;
        if (idValue == null) {
            idValue = UUID.randomUUID();
        }
        table.insert()
                .setFields(fields, values)
                .setField(idField, idValue)
                .setFields(uniqueKeyFields, uniqueKeyValues)
                .execute(connection);
        return idValue;
    }

    @Override
    protected UUID getId(DatabaseRow row) throws SQLException {
        return UUID.fromString(row.getString(idField));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy