use of java.sql.Timestamp in project jforum2 by rafaelsteil.
the class GenericPostDAO method updatePostsTable.
protected void updatePostsTable(Post post) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.updatePost"));
p.setInt(1, post.getTopicId());
p.setInt(2, post.getForumId());
p.setInt(3, post.isBbCodeEnabled() ? 1 : 0);
p.setInt(4, post.isHtmlEnabled() ? 1 : 0);
p.setInt(5, post.isSmiliesEnabled() ? 1 : 0);
p.setInt(6, post.isSignatureEnabled() ? 1 : 0);
p.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
p.setInt(8, post.getEditCount() + 1);
p.setString(9, post.getUserIp());
p.setInt(10, post.getId());
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of java.sql.Timestamp in project presto by prestodb.
the class TestShardCleaner method testAbortOldTransactions.
@Test
public void testAbortOldTransactions() throws Exception {
TestingDao dao = dbi.onDemand(TestingDao.class);
long now = System.currentTimeMillis();
long txn1 = dao.insertTransaction(new Timestamp(now - HOURS.toMillis(26)));
long txn2 = dao.insertTransaction(new Timestamp(now - HOURS.toMillis(25)));
long txn3 = dao.insertTransaction(new Timestamp(now));
ShardDao shardDao = dbi.onDemand(ShardDao.class);
assertEquals(shardDao.finalizeTransaction(txn1, true), 1);
assertQuery("SELECT transaction_id, successful FROM transactions", row(txn1, true), row(txn2, null), row(txn3, null));
cleaner.abortOldTransactions();
assertQuery("SELECT transaction_id, successful FROM transactions", row(txn1, true), row(txn2, false), row(txn3, null));
}
use of java.sql.Timestamp in project presto by prestodb.
the class TestShardCleaner method testDeleteOldCompletedTransactions.
@Test
public void testDeleteOldCompletedTransactions() throws Exception {
TestingDao dao = dbi.onDemand(TestingDao.class);
ShardDao shardDao = dbi.onDemand(ShardDao.class);
long now = System.currentTimeMillis();
Timestamp yesterdayStart = new Timestamp(now - HOURS.toMillis(27));
Timestamp yesterdayEnd = new Timestamp(now - HOURS.toMillis(26));
Timestamp todayEnd = new Timestamp(now - HOURS.toMillis(1));
long txn1 = dao.insertTransaction(yesterdayStart);
long txn2 = dao.insertTransaction(yesterdayStart);
long txn3 = dao.insertTransaction(yesterdayStart);
long txn4 = dao.insertTransaction(yesterdayStart);
long txn5 = dao.insertTransaction(new Timestamp(now));
long txn6 = dao.insertTransaction(new Timestamp(now));
assertEquals(shardDao.finalizeTransaction(txn1, true), 1);
assertEquals(shardDao.finalizeTransaction(txn2, false), 1);
assertEquals(shardDao.finalizeTransaction(txn3, false), 1);
assertEquals(shardDao.finalizeTransaction(txn5, true), 1);
assertEquals(shardDao.finalizeTransaction(txn6, false), 1);
assertEquals(dao.updateTransactionEndTime(txn1, yesterdayEnd), 1);
assertEquals(dao.updateTransactionEndTime(txn2, yesterdayEnd), 1);
assertEquals(dao.updateTransactionEndTime(txn3, yesterdayEnd), 1);
assertEquals(dao.updateTransactionEndTime(txn5, todayEnd), 1);
assertEquals(dao.updateTransactionEndTime(txn6, todayEnd), 1);
shardDao.insertCreatedShard(randomUUID(), txn2);
shardDao.insertCreatedShard(randomUUID(), txn2);
assertQuery("SELECT transaction_id, successful, end_time FROM transactions", // old successful
row(txn1, true, yesterdayEnd), // old failed, shards present
row(txn2, false, yesterdayEnd), // old failed, no referencing shards
row(txn3, false, yesterdayEnd), // old not finished
row(txn4, null, null), // new successful
row(txn5, true, todayEnd), // new failed, no referencing shards
row(txn6, false, todayEnd));
cleaner.deleteOldCompletedTransactions();
assertQuery("SELECT transaction_id, successful, end_time FROM transactions", row(txn2, false, yesterdayEnd), row(txn4, null, null), row(txn5, true, todayEnd), row(txn6, false, todayEnd));
}
use of java.sql.Timestamp in project presto by prestodb.
the class H2QueryRunner method rowMapper.
private static ResultSetMapper<MaterializedRow> rowMapper(final List<? extends Type> types) {
return new ResultSetMapper<MaterializedRow>() {
@Override
public MaterializedRow map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
int count = resultSet.getMetaData().getColumnCount();
checkArgument(types.size() == count, "type does not match result");
List<Object> row = new ArrayList<>(count);
for (int i = 1; i <= count; i++) {
Type type = types.get(i - 1);
if (BOOLEAN.equals(type)) {
boolean booleanValue = resultSet.getBoolean(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(booleanValue);
}
} else if (TINYINT.equals(type)) {
byte byteValue = resultSet.getByte(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(byteValue);
}
} else if (SMALLINT.equals(type)) {
short shortValue = resultSet.getShort(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(shortValue);
}
} else if (INTEGER.equals(type)) {
int intValue = resultSet.getInt(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(intValue);
}
} else if (BIGINT.equals(type)) {
long longValue = resultSet.getLong(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(longValue);
}
} else if (REAL.equals(type)) {
float floatValue = resultSet.getFloat(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(floatValue);
}
} else if (DOUBLE.equals(type)) {
double doubleValue = resultSet.getDouble(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(doubleValue);
}
} else if (isVarcharType(type)) {
String stringValue = resultSet.getString(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(stringValue);
}
} else if (isCharType(type)) {
String stringValue = resultSet.getString(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(padEnd(stringValue, ((CharType) type).getLength(), ' '));
}
} else if (DATE.equals(type)) {
Date dateValue = resultSet.getDate(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(dateValue);
}
} else if (TIME.equals(type) || TIME_WITH_TIME_ZONE.equals(type)) {
Time timeValue = resultSet.getTime(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(timeValue);
}
} else if (TIMESTAMP.equals(type) || TIMESTAMP_WITH_TIME_ZONE.equals(type)) {
Timestamp timestampValue = resultSet.getTimestamp(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(timestampValue);
}
} else if (UNKNOWN.equals(type)) {
Object objectValue = resultSet.getObject(i);
checkState(resultSet.wasNull(), "Expected a null value, but got %s", objectValue);
row.add(null);
} else if (type instanceof DecimalType) {
BigDecimal decimalValue = resultSet.getBigDecimal(i);
if (resultSet.wasNull()) {
row.add(null);
} else {
row.add(decimalValue);
}
} else {
throw new AssertionError("unhandled type: " + type);
}
}
return new MaterializedRow(MaterializedResult.DEFAULT_PRECISION, row);
}
};
}
use of java.sql.Timestamp in project dropwizard by dropwizard.
the class JodaDateTimeArgument method apply.
@Override
public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
if (value != null) {
if (calendar.isPresent()) {
// We need to make a clone, because Calendar is not thread-safe
// and some JDBC drivers mutate it during time calculations
final Calendar calendarClone = (Calendar) calendar.get().clone();
statement.setTimestamp(position, new Timestamp(value.getMillis()), calendarClone);
} else {
statement.setTimestamp(position, new Timestamp(value.getMillis()));
}
} else {
statement.setNull(position, Types.TIMESTAMP);
}
}
Aggregations