use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLViewCreator method createView.
/**
* Inserts a new view in the database by copying an existing view.
*
* @param provider The connection to the database.
* @param containerId The ID of the container where the view is created.
* @param view The view to be copied.
* @param name The name of the new view.
* @param description The description of the new view.
* @param containerTable Name of the view container table.
* @param viewContainerTable Name of the view container views table.
* @param generator Generates the view.
* @return The created view.
* @throws CouldntSaveDataException Thrown if the view could not be created.
*/
private static CView createView(final AbstractSQLProvider provider, final int containerId, final INaviView view, final String name, final String description, final String containerTable, final String viewContainerTable, final ViewGenerator generator) throws CouldntSaveDataException {
final CConnection connection = provider.getConnection();
try {
PostgreSQLHelpers.beginTransaction(connection);
final int viewId = insertView(connection, name, description);
// Mark the view as a module view
connection.executeUpdate("INSERT INTO " + viewContainerTable + " VALUES(" + containerId + ", " + viewId + ")", true);
final List<INaviViewNode> nodes = view.getGraph().getNodes();
final List<INaviEdge> edges = view.getGraph().getEdges();
// Store all nodes
PostgreSQLNodeSaver.writeNodes(provider, viewId, nodes);
// Store all edges
PostgreSQLEdgeSaver.writeEdges(provider, edges);
PostgreSQLHelpers.endTransaction(connection);
final String query = "SELECT creation_date, modification_date FROM " + CTableNames.VIEWS_TABLE + " WHERE id = " + viewId;
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
PostgreSQLHelpers.updateModificationDate(connection, containerTable, containerId);
return generator.generate(viewId, name, description, ViewType.NonNative, view.getGraphType(), creationDate, modificationDate, view.getNodeCount(), view.getEdgeCount(), new HashSet<CTag>(), new HashSet<CTag>(), false);
}
throw new CouldntSaveDataException("Error: Couldnt't load the created view");
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
CUtilityFunctions.logException(exception);
try {
PostgreSQLHelpers.rollback(connection);
} catch (final SQLException e) {
CUtilityFunctions.logException(e);
}
throw new CouldntSaveDataException(exception);
}
}
use of java.sql.Timestamp in project jdbc-shards by wplatform.
the class PreparedStatementTestCase method testDate.
private void testDate(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("SELECT ?");
Timestamp ts = Timestamp.valueOf("2001-02-03 04:05:06");
prep.setObject(1, new java.util.Date(ts.getTime()));
ResultSet rs = prep.executeQuery();
rs.next();
Timestamp ts2 = rs.getTimestamp(1);
assertEquals(ts.toString(), ts2.toString());
}
use of java.sql.Timestamp in project jdbc-shards by wplatform.
the class PreparedStatementTestCase method testCoalesce.
private static void testCoalesce(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.executeUpdate("create table test(tm timestamp)");
stat.executeUpdate("insert into test values(current_timestamp)");
PreparedStatement prep = conn.prepareStatement("update test set tm = coalesce(?,tm)");
prep.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
prep.executeUpdate();
stat.executeUpdate("drop table test");
}
use of java.sql.Timestamp in project hibernate-orm by hibernate.
the class DefaultGeneratedValueTest method testUpdateTimestampGeneration.
@Test
@TestForIssue(jiraKey = "HHH-2907")
public void testUpdateTimestampGeneration() {
Session s = openSession();
s.beginTransaction();
TheEntity theEntity = new TheEntity(1);
assertNull(theEntity.updated);
s.save(theEntity);
//TODO: Actually the value should be non-null afterQuery save
assertNull(theEntity.updated);
s.getTransaction().commit();
s.close();
Timestamp created = theEntity.vmCreatedSqlTimestamp;
Timestamp updated = theEntity.updated;
assertNotNull(updated);
assertNotNull(created);
s = openSession();
s.beginTransaction();
theEntity = (TheEntity) s.get(TheEntity.class, 1);
theEntity.lastName = "Smith";
try {
Thread.sleep(1);
} catch (InterruptedException ignore) {
}
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
theEntity = (TheEntity) s.get(TheEntity.class, 1);
assertEquals("Creation timestamp should not change on update", created, theEntity.vmCreatedSqlTimestamp);
assertTrue("Update timestamp should have changed due to update", theEntity.updated.after(updated));
s.delete(theEntity);
s.getTransaction().commit();
s.close();
}
use of java.sql.Timestamp in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testStandardFunctions.
@Test
public void testStandardFunctions() throws Exception {
Session session = openSession();
Transaction t = session.beginTransaction();
Product p = new Product();
p.setDescription("a product");
p.setPrice(new BigDecimal(1.0));
p.setProductId("abc123");
session.persist(p);
Object[] result = (Object[]) session.createQuery("select current_time(), current_date(), current_timestamp() from Product").uniqueResult();
assertTrue(result[0] instanceof Time);
assertTrue(result[1] instanceof Date);
assertTrue(result[2] instanceof Timestamp);
assertNotNull(result[0]);
assertNotNull(result[1]);
assertNotNull(result[2]);
session.delete(p);
t.commit();
session.close();
}
Aggregations