Search in sources :

Example 76 with DSLContext

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

Example 77 with DSLContext

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();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) UUID(java.util.UUID) Timestamp(java.sql.Timestamp) Listener(org.spongepowered.api.event.Listener)

Example 78 with DSLContext

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();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) UUID(java.util.UUID) Listener(org.spongepowered.api.event.Listener)

Example 79 with DSLContext

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

Example 80 with DSLContext

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