com.rapleaf.jack.queries.GenericInsertion Maven / Gradle / Ivy
package com.rapleaf.jack.queries;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLRecoverableException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rapleaf.jack.BaseDatabaseConnection;
import com.rapleaf.jack.util.JackUtility;
public class GenericInsertion extends AbstractExecution {
private static final Logger LOG = LoggerFactory.getLogger(GenericInsertion.class);
private final AbstractTable table;
private final Map> values;
private int rowCount = 0;
private GenericInsertion(BaseDatabaseConnection dbConnection, AbstractTable table) {
super(dbConnection);
this.table = table;
this.values = Maps.newLinkedHashMap();
}
public static Builder create(BaseDatabaseConnection dbConnection) {
return new Builder(dbConnection);
}
public static class Builder {
private final BaseDatabaseConnection dbConnection;
public Builder(BaseDatabaseConnection dbConnection) {
this.dbConnection = dbConnection;
}
public GenericInsertion into(AbstractTable table) {
return new GenericInsertion(dbConnection, table);
}
}
@SafeVarargs
public final GenericInsertion set(Column column, T value, T... values) {
checkRowCount(1 + values.length);
List allValues = Lists.newArrayListWithCapacity(1 + values.length);
allValues.add(value);
allValues.addAll(Arrays.asList(values));
return set(column, allValues);
}
public GenericInsertion set(Column column, List values) {
if (values == null) {
checkRowCount(1);
List processedValues = Lists.newArrayListWithCapacity(1);
processedValues.add(null);
return set(column, processedValues);
}
Preconditions.checkArgument(!values.isEmpty(), "Must provide at least one value");
checkRowCount(values.size());
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy