use of com.djrapitops.plan.storage.database.sql.building.Sql in project Plan by plan-player-analytics.
the class DatabaseTest method sqlDateParsingSanitySQLDoesNotApplyTimezone.
@Test
@Disabled
default void sqlDateParsingSanitySQLDoesNotApplyTimezone() {
Database db = db();
List<org.junit.jupiter.api.function.Executable> assertions = new ArrayList<>();
long now = System.currentTimeMillis();
for (int i = 0; i < 24; i++) {
long hourChange = TimeUnit.HOURS.toMillis(i);
assertions.add(() -> {
long time = now + hourChange;
int offset = 0;
Sql sql = db.getType().getSql();
String testSQL = SELECT + sql.dateToDayStamp(sql.epochSecondToDate(Long.toString((time + offset) / 1000))) + " as date";
String expected = deliveryUtilities().getFormatters().iso8601NoClockLong().apply(time);
String result = db.query(new QueryAllStatement<String>(testSQL) {
@Override
public String processResults(ResultSet set) throws SQLException {
return set.next() ? set.getString("date") : null;
}
});
assertEquals(expected, result, () -> "Expected <" + expected + "> but was: <" + result + "> for query <" + testSQL + ">");
});
}
assertAll(assertions);
}
use of com.djrapitops.plan.storage.database.sql.building.Sql in project Plan by plan-player-analytics.
the class DatabaseTest method sqlDateConversionSanityCheck.
@Test
default void sqlDateConversionSanityCheck() {
Database db = db();
long expected = System.currentTimeMillis() / 1000;
Sql sql = db.getType().getSql();
String testSQL = SELECT + sql.dateToEpochSecond(sql.epochSecondToDate(Long.toString(expected))) + " as ms";
long result = db.query(new QueryAllStatement<Long>(testSQL) {
@Override
public Long processResults(ResultSet set) throws SQLException {
return set.next() ? set.getLong("ms") : -1L;
}
});
assertEquals(expected, result);
}
use of com.djrapitops.plan.storage.database.sql.building.Sql in project Plan by plan-player-analytics.
the class WorldObj method updateWorldTimesTableWorldIDs.
private void updateWorldTimesTableWorldIDs() {
List<WorldObj> worldObjects = getWorldObjects();
Map<WorldObj, List<WorldObj>> oldToNewMap = worldObjects.stream().filter(worldObj -> worldObj.serverId == 0).collect(Collectors.toMap(Function.identity(), oldWorld -> worldObjects.stream().filter(worldObj -> worldObj.serverId != 0).filter(worldObj -> worldObj.equals(oldWorld)).collect(Collectors.toList())));
String sql = "UPDATE " + WorldTimesTable.TABLE_NAME + " SET " + WorldTimesTable.WORLD_ID + "=?" + WHERE + WorldTimesTable.WORLD_ID + "=?" + AND + "server_id=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<WorldObj, List<WorldObj>> entry : oldToNewMap.entrySet()) {
WorldObj old = entry.getKey();
for (WorldObj newWorld : entry.getValue()) {
statement.setInt(1, newWorld.id);
statement.setInt(2, old.id);
statement.setInt(3, newWorld.serverId);
statement.addBatch();
}
}
}
});
}
use of com.djrapitops.plan.storage.database.sql.building.Sql in project Plan by plan-player-analytics.
the class DatabaseTest method sqlDateParsingSanityCheck.
@Test
default void sqlDateParsingSanityCheck() {
Database db = db();
long time = System.currentTimeMillis();
int offset = TimeZone.getDefault().getOffset(time);
Sql sql = db.getType().getSql();
String testSQL = SELECT + sql.dateToDayStamp(sql.epochSecondToDate(Long.toString((time + offset) / 1000))) + " as date";
String expected = deliveryUtilities().getFormatters().iso8601NoClockLong().apply(time);
String result = db.query(new QueryAllStatement<String>(testSQL) {
@Override
public String processResults(ResultSet set) throws SQLException {
return set.next() ? set.getString("date") : null;
}
});
assertEquals(expected, result, () -> "Expected <" + expected + "> but was: <" + result + "> for query <" + testSQL + ">");
}
Aggregations