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();
}
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();
}
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();
}
}
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();
});
}
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));
//
}
Aggregations