use of org.jooq.DSLContext in project jOOQ by jOOQ.
the class TableRecordImpl method storeInsert0.
final int storeInsert0(Field<?>[] storeFields) {
DSLContext create = create();
InsertQuery<R> insert = create.insertQuery(getTable());
addChangedValues(storeFields, insert);
// Don't store records if no value was set by client code
if (!insert.isExecutable()) {
if (log.isDebugEnabled())
log.debug("Query is not executable", insert);
return 0;
}
// [#1596] Set timestamp and/or version columns to appropriate values
BigInteger version = addRecordVersion(insert);
Timestamp timestamp = addRecordTimestamp(insert);
// [#814] Refresh identity and/or main unique key values
// [#1002] Consider also identity columns of non-updatable records
// [#1537] Avoid refreshing identity columns on batch inserts
Collection<Field<?>> key = setReturningIfNeeded(insert);
int result = insert.execute();
if (result > 0) {
for (Field<?> storeField : storeFields) changed(storeField, false);
// [#1596] If insert was successful, update timestamp and/or version columns
setRecordVersionAndTimestamp(version, timestamp);
// [#1859] If an insert was successful try fetching the generated values.
getReturningIfNeeded(insert, key);
fetched = true;
}
return result;
}
use of org.jooq.DSLContext in project jOOQ by jOOQ.
the class ResultImpl method formatInsert.
@Override
public final void formatInsert(Writer writer, Table<?> table, Field<?>... f) {
DSLContext ctx = DSL.using(configuration());
try {
for (R record : this) {
writer.append(ctx.renderInlined(insertInto(table, f).values(record.intoArray())));
writer.append(";\n");
}
writer.flush();
} catch (java.io.IOException e) {
throw new IOException("Exception while writing INSERTs", e);
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class RegionDatabaseHandle method writeMasterBlockChangeToDB.
private void writeMasterBlockChangeToDB(RegionPoint masterBlock) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
create.update(REGIONS).set(REGIONS.X, masterBlock.getX()).set(REGIONS.Y, masterBlock.getY()).set(REGIONS.Z, masterBlock.getZ()).where(REGIONS.UUID.equal(regionID.toString())).execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class RegionDatabaseHandle method writeNameChangeToDB.
private void writeNameChangeToDB(String newName) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
create.update(REGIONS).set(REGIONS.NAME, newName).where(REGIONS.UUID.equal(regionID.toString())).execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class RegionDatabaseHandle method writeMemberRemovalFromDB.
private void writeMemberRemovalFromDB(Collection<UUID> oldMembers) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
int rgID = create.select(REGIONS.ID).from(REGIONS).where(REGIONS.UUID.equal(regionID.toString())).fetchOne().value1();
con.setAutoCommit(false);
for (UUID member : oldMembers) {
create.deleteFrom(REGION_MEMBERS).where(REGION_MEMBERS.REGION_ID.equal(rgID).and(REGION_MEMBERS.PLAYER_ID.equal(DSL.select(PLAYERS.ID).from(PLAYERS).where(PLAYERS.UUID.equal(member.toString()))))).execute();
}
con.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
Aggregations