Search in sources :

Example 11 with DSLContext

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;
}
Also used : Field(org.jooq.Field) TableField(org.jooq.TableField) DSLContext(org.jooq.DSLContext) BigInteger(java.math.BigInteger) Timestamp(java.sql.Timestamp)

Example 12 with DSLContext

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);
    }
}
Also used : DSLContext(org.jooq.DSLContext) IOException(org.jooq.exception.IOException)

Example 13 with DSLContext

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();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext)

Example 14 with DSLContext

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();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext)

Example 15 with DSLContext

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();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext)

Aggregations

DSLContext (org.jooq.DSLContext)109 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)55 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 List (java.util.List)17 DIConfiguration (com.khartec.waltz.service.DIConfiguration)14 Collectors (java.util.stream.Collectors)14 EntityKind (com.khartec.waltz.model.EntityKind)11 ArrayList (java.util.ArrayList)9 DSL (org.jooq.impl.DSL)9 EntityReference (com.khartec.waltz.model.EntityReference)8 Timestamp (java.sql.Timestamp)8 Random (java.util.Random)8 IntStream (java.util.stream.IntStream)8 Application (com.khartec.waltz.model.application.Application)7 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)6 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)6 Field (org.jooq.Field)6 Record1 (org.jooq.Record1)6 Test (org.junit.Test)6