use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method c2_getCurrentSlotTable.
/**
* Initial reading CURRENT_DUE_SLOT and NEXT_MESSAGE_ID when cassandra database access starting
*
* @param CURRENT_DUE_SLOT or NEXT_MESSAGE_ID
* @return dead value
* @throws PersistenceException
*/
protected long c2_getCurrentSlotTable(int key) throws PersistenceException {
PreparedStatement ps = selectCurrentSlotTable;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(key);
ResultSet res = session.execute(boundStatement);
long res2 = 0;
for (Row row : res) {
res2 = row.getLong(0);
break;
}
return res2;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method c2_getDueSlotForTargetId.
public long c2_getDueSlotForTargetId(PreparedStatementCollection psc, String targetId) throws PersistenceException {
try {
PreparedStatement ps = psc.getDueSlotForTargetId;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(targetId);
ResultSet res = session.execute(boundStatement);
long l = 0;
for (Row row : res) {
l = row.getLong(0);
break;
}
return l;
} catch (Exception e1) {
// TODO: remove it
e1.printStackTrace();
String msg = "Failed to execute getDueSlotForTargetId() !";
throw new PersistenceException(msg, e1);
}
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperTesting method run.
public void run() {
BasicConfigurator.configure();
Logger logger = Logger.getLogger(DBOperations.class);
try {
logger.info("stating ...");
logger.info("getting DBOperations_C2 ...");
DBOperations_C2_Proxy db = new DBOperations_C2_Proxy();
logger.info("starting DBOperations_C2 ...");
String keySpacename = "RestCommSMSC1";
// String keySpacename = "RestCommSMSC";
db.start("127.0.0.1", 9042, keySpacename, "cassandra", "cassandra", 60, 60, 60 * 10, 1, 10000000000L);
logger.info("DBOperations_C2 is started");
logger.info("Getting of CurrentDueSlot ...");
long processedDueSlot = db.c2_getCurrentDueSlot();
logger.info("CurrentDueSlot = " + processedDueSlot);
// long possibleDueSlot = dbOperations_C2.c2_getIntimeDueSlot();
// if (processedDueSlot >= possibleDueSlot) {
// return new OneWaySmsSetCollection();
// }
logger.info("getting of table list ....");
Session secc = db.getSession();
PreparedStatement ps = secc.prepare("select columnfamily_name from system.schema_columnfamilies where keyspace_name = '" + keySpacename + "';");
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind();
ResultSet result = secc.execute(boundStatement);
for (Row row : result) {
String s = row.getString(0);
logger.info(s);
}
long baseDeuSlot = 493020406;
for (long i1 = 3600 * 6; i1 < 3600 * 12; i1++) {
long dueSlot = baseDeuSlot - i1;
logger.info("Getting of RecordList for deuSlot: " + dueSlot + " " + (new Date()).toString());
// processedDueSlot++;
ArrayList<SmsSet> lstS = db.c2_getRecordList(dueSlot);
logger.info("Size of RecordList=" + lstS.size());
}
System.exit(0);
} catch (Throwable e) {
logger.error("General error: ", e);
System.exit(1);
}
}
use of com.datastax.driver.core.PreparedStatement in project data-transfer-project by google.
the class CosmosStore method update.
private void update(UUID id, Object instance, String query) {
PreparedStatement statement = session.prepare(query);
BoundStatement boundStatement = new BoundStatement(statement);
try {
boundStatement.setString(0, mapper.writeValueAsString(instance));
boundStatement.setUUID(1, id);
session.execute(boundStatement);
} catch (JsonProcessingException e) {
throw new MicrosoftStorageException("Error deleting data: " + id, e);
}
}
use of com.datastax.driver.core.PreparedStatement in project data-transfer-project by google.
the class CosmosStore method findData.
private <T> T findData(Class<T> type, UUID id, String query, String column) {
PreparedStatement statement = session.prepare(query);
BoundStatement boundStatement = new BoundStatement(statement);
boundStatement.bind(id);
Row row = session.execute(boundStatement).one();
String serialized = row.getString(column);
try {
return mapper.readValue(serialized, type);
} catch (IOException e) {
throw new MicrosoftStorageException("Error deserializing data: " + id, e);
}
}
Aggregations