Search in sources :

Example 16 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class RegionDatabaseHandle method writePointAdditionToDBWithCon.

private void writePointAdditionToDBWithCon(Collection<RegionPoint> newPoints, Connection con) throws SQLException {
    DSLContext create = DSL.using(con);
    con.setAutoCommit(false);
    for (RegionPoint point : newPoints) {
        create.insertInto(REGION_POINTS).columns(REGION_POINTS.REGION_ID, REGION_POINTS.X, REGION_POINTS.Y, REGION_POINTS.Z).select(create.select(REGIONS.ID, DSL.value(point.getX()), DSL.value(point.getY()), DSL.value(point.getZ())).from(REGIONS).where(REGIONS.UUID.equal(regionID.toString()))).execute();
    }
    con.commit();
}
Also used : DSLContext(org.jooq.DSLContext)

Example 17 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class RegionDatabaseHandle method writeMemberAdditionToDBWithCon.

private void writeMemberAdditionToDBWithCon(Collection<UUID> newMembers, Connection con) throws SQLException {
    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 : newMembers) {
        create.insertInto(REGION_MEMBERS).columns(REGION_MEMBERS.PLAYER_ID, REGION_MEMBERS.REGION_ID).select(create.select(PLAYERS.ID, DSL.value(rgID)).from(PLAYERS).where(PLAYERS.UUID.equal(member.toString()))).execute();
    }
    con.commit();
}
Also used : DSLContext(org.jooq.DSLContext)

Example 18 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class RegionManager method load.

public void load() {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        int worldID = create.select(WORLDS.ID).from(WORLDS).where(WORLDS.NAME.equal(worldName)).fetchOne().value1();
        List<RegionDatabaseHandle> loaded = create.select(REGIONS.ID, REGIONS.UUID, REGIONS.X, REGIONS.Y, REGIONS.Z, REGIONS.NAME, REGIONS.POWER).from(REGIONS).where(REGIONS.WORLD_ID.equal(worldID)).fetch().stream().map(r -> {
            UUID regionID = UUID.fromString(r.getValue(REGIONS.UUID));
            RegionPoint masterBlock = new RegionPoint(r.getValue(REGIONS.X), r.getValue(REGIONS.Y), r.getValue(REGIONS.Z));
            String name = r.getValue(REGIONS.NAME);
            int power = r.getValue(REGIONS.POWER);
            Set<UUID> members = create.select(PLAYERS.UUID).from(REGION_MEMBERS).join(PLAYERS).on(REGION_MEMBERS.PLAYER_ID.equal(PLAYERS.ID)).where(REGION_MEMBERS.REGION_ID.equal(r.getValue(REGIONS.ID))).fetch().stream().map(a -> UUID.fromString(a.value1())).collect(Collectors.toSet());
            Set<RegionPoint> points = create.select(REGION_POINTS.X, REGION_POINTS.Y, REGION_POINTS.Z).from(REGION_POINTS).where(REGION_POINTS.REGION_ID.equal(r.getValue(REGIONS.ID))).fetch().stream().map(entry -> new RegionPoint(entry.value1(), entry.value2(), entry.value3())).collect(Collectors.toSet());
            return new RegionDatabaseHandle(regionID, worldName, masterBlock, name, power, members, points);
        }).collect(Collectors.toList());
        uncheckedAddRegion(loaded);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : CustomBlockTypes(com.skelril.skree.content.registry.block.CustomBlockTypes) SQLException(java.sql.SQLException) java.util(java.util) DSL(org.jooq.impl.DSL) Connection(java.sql.Connection) Tables(com.skelril.skree.db.schema.Tables) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) DSLContext(org.jooq.DSLContext) Sponge(org.spongepowered.api.Sponge) Collectors(java.util.stream.Collectors) SQLHandle(com.skelril.skree.db.SQLHandle) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext)

Example 19 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class SurveyQuestionDropdownEntryDao method saveEntries.

public void saveEntries(long questionId, List<SurveyQuestionDropdownEntry> entries) {
    checkNotNull(entries, "entries cannot be null");
    dsl.transaction(config -> {
        DSLContext tx = DSL.using(config);
        tx.delete(SURVEY_QUESTION_DROPDOWN_ENTRY).where(SURVEY_QUESTION_DROPDOWN_ENTRY.QUESTION_ID.eq(questionId)).execute();
        List<SurveyQuestionDropdownEntryRecord> records = entries.stream().map(TO_RECORD_MAPPER).collect(toList());
        tx.batchInsert(records).execute();
    });
}
Also used : SurveyQuestionDropdownEntryRecord(com.khartec.waltz.schema.tables.records.SurveyQuestionDropdownEntryRecord) DSLContext(org.jooq.DSLContext)

Example 20 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class AppHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    // Water & Vole
    // P&S Blotter
    // P & S Gorilla
    List<Application> jimmy = new SqlServerAppSearch().search(dsl, "Water & Vole", EntitySearchOptions.mkForEntity(EntityKind.APPLICATION));
    System.out.println(jimmy);
// ApplicationService applicationService = ctx.getBean(ApplicationService.class);
// DSLContext dsl = ctx.getBean(DSLContext.class);
// 
// List<String> tagList = applicationService.findAllTags();
// 
// tagList.forEach(System.out::println);
// 
// System.out.println("---------------");
// 
// applicationService.findByTag("not-good-at-flying").forEach(a -> System.out.println(a.name()));
// 
// System.out.println(applicationService.findTagsForApplication(521L));
// 
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SqlServerAppSearch(com.khartec.waltz.data.application.search.SqlServerAppSearch) DSLContext(org.jooq.DSLContext) Application(com.khartec.waltz.model.application.Application)

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