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

org.fluentjdbc.DatabaseSaveBuilderWithoutGeneratedKeys Maven / Gradle / Ivy

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

import javax.annotation.Nullable;
import java.sql.Connection;

/**
 * Subclass of {@link DatabaseSaveBuilder} which assumes the client code always specifies
 * primary key field
 */
public class DatabaseSaveBuilderWithoutGeneratedKeys extends DatabaseSaveBuilder {

    public DatabaseSaveBuilderWithoutGeneratedKeys(DatabaseTableImpl table, String idField, T id) {
        super(table, idField, id);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy