use of java.sql.Timestamp in project musiccabinet by hakko.
the class JdbcWebserviceHistoryDao method isWebserviceInvocationAllowed.
protected boolean isWebserviceInvocationAllowed(Calltype callType, short page) {
String sql = "select max(invocation_time) from library.webservice_history" + " where calltype_id = " + callType.getDatabaseId() + " and page = " + page;
Timestamp lastInvocation = jdbcTemplate.queryForObject(sql, Timestamp.class);
return isWebserviceInvocationAllowed(callType, lastInvocation);
}
use of java.sql.Timestamp in project h2o-3 by h2oai.
the class ExternalFrameWriterClientTest method testWriting.
@Test
public void testWriting() throws IOException {
final String[] nodes = new String[H2O.CLOUD._memary.length];
// get ip and ports of h2o nodes
for (int i = 0; i < nodes.length; i++) {
nodes[i] = H2O.CLOUD._memary[i].getIpPortString();
}
// we will open 2 connection per h2o node
final String[] connStrings = ArrayUtils.join(nodes, nodes);
// The api expects that empty frame has to be in the DKV before we start working with it
final String frameName = "fr";
String[] colNames = { "NUM", "BOOL", "STR", "TIMESTAMP" };
// vector types are inferred from expected types
final byte[] expectedTypes = ExternalFrameUtils.prepareExpectedTypes(new Class[] { Integer.class, Boolean.class, String.class, Timestamp.class });
ChunkUtils.initFrame(frameName, colNames);
// number of chunks will be number of h2o nodes
final long[] rowsPerChunk = new long[connStrings.length];
Thread[] threads = new Thread[connStrings.length];
// open all connections in connStrings array
for (int idx = 0; idx < connStrings.length; idx++) {
final int currentIndex = idx;
threads[idx] = new Thread() {
@Override
public void run() {
try {
ByteChannel sock = ExternalFrameUtils.getConnection(connStrings[currentIndex]);
ExternalFrameWriterClient writer = new ExternalFrameWriterClient(sock);
writer.createChunks(frameName, expectedTypes, currentIndex, 1000);
Timestamp time = new Timestamp(Calendar.getInstance().getTime().getTime());
for (int i = 0; i < 997; i++) {
writer.sendInt(i);
writer.sendBoolean(true);
writer.sendString("str_" + i);
writer.sendTimestamp(time);
}
writer.sendInt(0);
writer.sendBoolean(true);
writer.sendString(null);
writer.sendTimestamp(time);
writer.sendInt(1);
writer.sendBoolean(true);
writer.sendString("");
writer.sendTimestamp(time);
// send NA for all columns
writer.sendNA();
writer.sendNA();
writer.sendNA();
writer.sendNA();
writer.waitUntilAllWritten();
sock.close();
rowsPerChunk[currentIndex] = 1000;
} catch (IOException ignore) {
}
}
};
threads[idx].start();
}
// wait for all writer thread to finish
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ChunkUtils.finalizeFrame(frameName, rowsPerChunk, ExternalFrameUtils.vecTypesFromExpectedTypes(expectedTypes), null);
Frame frame = null;
try {
frame = DKV.getGet(frameName);
assertEquals(frame.anyVec().nChunks(), connStrings.length);
assertEquals(frame._names.length, 4);
assertEquals(frame.numCols(), 4);
assertEquals(frame._names[0], "NUM");
assertEquals(frame._names[1], "BOOL");
assertEquals(frame._names[2], "STR");
assertEquals(frame._names[3], "TIMESTAMP");
assertEquals(frame.vec(0).get_type(), Vec.T_NUM);
assertEquals(frame.vec(1).get_type(), Vec.T_NUM);
assertEquals(frame.vec(2).get_type(), Vec.T_STR);
assertEquals(frame.vec(3).get_type(), Vec.T_TIME);
assertEquals(frame.numRows(), 1000 * connStrings.length);
// last row should be NA
assertEquals(frame.vec(0).at8(0), 0);
BufferedString buff = new BufferedString();
assertEquals(frame.vec(2).atStr(buff, 996).toString(), "str_996");
assertEquals(frame.vec(2).atStr(buff, 997), null);
assertEquals(frame.vec(2).atStr(buff, 998).toString(), "");
assertTrue(frame.vec(0).isNA(999));
assertTrue(frame.vec(1).isNA(999));
assertTrue(frame.vec(2).isNA(999));
assertTrue(frame.vec(3).isNA(999));
} finally {
if (frame != null) {
frame.remove();
}
}
}
use of java.sql.Timestamp in project spring-security-oauth by spring-projects.
the class JdbcApprovalStore method updateApproval.
private boolean updateApproval(final String sql, final Approval approval) {
logger.debug(String.format("refreshing approval: [%s]", approval));
int refreshed = jdbcTemplate.update(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setTimestamp(1, new Timestamp(approval.getExpiresAt().getTime()));
ps.setString(2, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString());
ps.setTimestamp(3, new Timestamp(approval.getLastUpdatedAt().getTime()));
ps.setString(4, approval.getUserId());
ps.setString(5, approval.getClientId());
ps.setString(6, approval.getScope());
}
});
if (refreshed != 1) {
return false;
}
return true;
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLAddressSpaceLoader method loadAddressSpaces.
/**
* Loads the address spaces of a project.
*
* The project, the debugger manager, and all modules in the module list must be stored in the
* database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param project The parent project of the address spaces to load.
* @param debuggerManager Debugger manager of the database.
* @param list A list of all modules that belong to the database.
*
* @return A list that contains the address spaces of the project.
*
* @throws CouldntLoadDataException Thrown if the address spaces could not be loaded.
*/
public static List<CAddressSpace> loadAddressSpaces(final AbstractSQLProvider provider, final INaviProject project, final DebuggerTemplateManager debuggerManager, final List<INaviModule> list) throws CouldntLoadDataException {
checkArguments(provider, project);
Preconditions.checkNotNull(debuggerManager, "IE01543: Debugger provider argument can not be null");
Preconditions.checkNotNull(list, "IE01545: Modules argument can not be null");
NaviLogger.info("Loading address spaces of project %s", project.getConfiguration().getName());
final CConnection connection = provider.getConnection();
final List<CAddressSpace> addressSpaces = new ArrayList<CAddressSpace>();
final String query = "SELECT id, name, description, creation_date, modification_date, debugger_id " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + project.getConfiguration().getId();
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final int addressSpaceId = resultSet.getInt("id");
final Map<INaviModule, IAddress> imageBases = loadImageBases(connection, addressSpaceId, list);
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final DebuggerTemplate debuggerDescription = debuggerManager.findDebugger(resultSet.getInt("debugger_id"));
addressSpaces.add(new CAddressSpace(addressSpaceId, name, description, creationDate, modificationDate, imageBases, debuggerDescription, provider, project));
}
return addressSpaces;
} finally {
resultSet.close();
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLModuleFunctions method readModule.
public static CModule readModule(final CConnection connection, final int moduleId, final INaviRawModule rawModule, final SQLProvider provider) throws CouldntLoadDataException {
Preconditions.checkNotNull(rawModule, "IE01797: Raw module argument can not be null");
Preconditions.checkNotNull(provider, "IE01798: Provider argument can not be null");
final String query = "SELECT id, " + CTableNames.MODULES_TABLE + ".name, md5, sha1, " + " description, import_time, modification_date, image_base, file_base, stared, " + " initialization_state " + " FROM " + CTableNames.MODULES_TABLE + " WHERE id = " + moduleId + " ORDER by id";
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String md5 = PostgreSQLHelpers.readString(resultSet, "md5");
final String sha1 = PostgreSQLHelpers.readString(resultSet, "sha1");
final String comment = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp importTime = resultSet.getTimestamp("import_time");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final int functionCount = rawModule.getFunctionCount();
final int viewCount = 0;
final IAddress imageBase = PostgreSQLHelpers.loadAddress(resultSet, "image_base");
final IAddress fileBase = PostgreSQLHelpers.loadAddress(resultSet, "file_base");
final boolean isStared = resultSet.getBoolean("stared");
final int initializationState = resultSet.getInt("initialization_state");
return new CModule(moduleId, name, comment, importTime, modificationDate, md5, sha1, functionCount, viewCount, fileBase, imageBase, null, rawModule, initializationState, isStared, provider);
}
} finally {
resultSet.close();
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
throw new CouldntLoadDataException("Error: No module with the given ID exists");
}
Aggregations