use of org.jooq.DSLContext in project Skree by Skelril.
the class WorldServiceImpl method onPlayerAuth.
@Listener(order = Order.PRE)
public void onPlayerAuth(ClientConnectionEvent.Auth event) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
UUID uuid = event.getProfile().getUniqueId();
Record1<Timestamp> result = create.select(PLAYERS.LAST_LOGIN).from(PLAYERS).where(PLAYERS.UUID.equal(uuid.toString())).fetchOne();
Timestamp timestamp = result.getValue(PLAYERS.LAST_LOGIN);
lastPlayerLogin.put(uuid, timestamp.getTime());
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class DatabaseServiceImpl method onLogin.
@Listener
public void onLogin(ClientConnectionEvent.Auth event) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
UUID uuid = event.getProfile().getUniqueId();
long time = System.currentTimeMillis();
Timestamp timeStamp = new Timestamp(time);
create.insertInto(PLAYERS).columns(PLAYERS.UUID, PLAYERS.FIRST_LOGIN, PLAYERS.LAST_LOGIN).values(uuid.toString(), timeStamp, timeStamp).onDuplicateKeyUpdate().set(PLAYERS.TIMES_PLAYED, PLAYERS.TIMES_PLAYED.add(1)).set(PLAYERS.LAST_LOGIN, timeStamp).execute();
sessionStartTime.put(uuid, time);
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class DatabaseServiceImpl method onLogout.
@Listener
public void onLogout(ClientConnectionEvent.Disconnect event) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
UUID uuid = event.getTargetEntity().getUniqueId();
long diff = System.currentTimeMillis() - sessionStartTime.remove(uuid);
long diffSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
create.update(PLAYERS).set(PLAYERS.SECONDS_PLAYED, PLAYERS.SECONDS_PLAYED.add(diffSeconds)).where(PLAYERS.UUID.equal(uuid.toString())).execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class RegionDatabaseHandle method writePointRemovalFromDB.
private void writePointRemovalFromDB(Collection<RegionPoint> oldPoints) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
con.setAutoCommit(false);
for (RegionPoint point : oldPoints) {
create.deleteFrom(REGION_POINTS).where(REGION_POINTS.REGION_ID.equal(DSL.select(REGIONS.ID).from(REGIONS).where(REGIONS.UUID.equal(regionID.toString()))).and(REGION_POINTS.X.equal(DSL.value(point.getX()))).and(REGION_POINTS.Y.equal(DSL.value(point.getY()))).and(REGION_POINTS.Z.equal(DSL.value(point.getZ())))).execute();
}
con.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.jooq.DSLContext in project Skree by Skelril.
the class RegionManager method writeAddRegion.
private void writeAddRegion(Collection<RegionDatabaseHandle> newRegions) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
con.setAutoCommit(false);
int worldID = create.select(WORLDS.ID).from(WORLDS).where(WORLDS.NAME.equal(worldName)).fetchOne().value1();
for (RegionDatabaseHandle region : newRegions) {
create.insertInto(REGIONS).columns(REGIONS.UUID, REGIONS.WORLD_ID, REGIONS.X, REGIONS.Y, REGIONS.Z, REGIONS.NAME, REGIONS.POWER).values(region.getID().toString(), worldID, region.getMasterBlock().getX(), region.getMasterBlock().getY(), region.getMasterBlock().getZ(), region.getName(), region.getPowerLevel()).execute();
region.writeInit(con);
}
con.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
Aggregations