use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class NN_DBOper method doGetStatementCollection4.
private synchronized PreparedStatementCollection4 doGetStatementCollection4(String tName) throws PersistenceException {
PreparedStatementCollection4 psc = dataTableRead4.get(tName);
if (psc != null)
return psc;
try {
try {
// checking if a datatable exists
String s1 = "SELECT * FROM \"" + Schema.FAMILY_DST_SLOT_TABLE + tName + "\";";
PreparedStatement ps = session.prepare(s1);
} catch (InvalidQueryException e) {
// datatable does not exist
// DST_SLOT_TABLE
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE \"" + Schema.FAMILY_DST_SLOT_TABLE);
sb.append(tName);
sb.append("\" (");
appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
sb.append("PRIMARY KEY (\"");
sb.append(Schema.COLUMN_TARGET_ID);
sb.append("\"");
sb.append("));");
String s2 = sb.toString();
PreparedStatement ps = session.prepare(s2);
BoundStatement boundStatement = new BoundStatement(ps);
ResultSet res = session.execute(boundStatement);
// // MESSAGES
// sb = new StringBuilder();
// sb.append("CREATE TABLE \"" + Schema.FAMILY_SLOTS);
// sb.append(tName);
// sb.append("\" (");
//
// appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
// appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
//
// // !!!!- temproary - delete it
// appendField(sb, "PROCESSED", "boolean");
// // !!!!- temproary - delete it
//
// sb.append("PRIMARY KEY (\"");
// sb.append(Schema.COLUMN_DUE_SLOT);
// sb.append("\", \"");
// sb.append(Schema.COLUMN_TARGET_ID);
// sb.append("\"");
// sb.append("));");
//
// s2 = sb.toString();
// ps = session.prepare(s2);
// boundStatement = new BoundStatement(ps);
// res = session.execute(boundStatement);
}
} catch (Exception e1) {
String msg = "Failed to access or create table " + tName + "!";
throw new PersistenceException(msg, e1);
}
psc = new PreparedStatementCollection4(tName);
dataTableRead4.putEntry(tName, psc);
return psc;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class NN_DBOper method doGetCurDueSlot.
private synchronized long doGetCurDueSlot() throws PersistenceException {
if (currentDueSlot != 0)
return currentDueSlot;
try {
try {
// checking of CURRENT_SLOT_TABLE existence
String sa = "SELECT \"" + Schema.COLUMN_NEXT_SLOT + "\" FROM \"" + Schema.FAMILY_CURRENT_SLOT_TABLE + "\" where \"" + Schema.COLUMN_ID + "\"=0;";
PreparedStatement ps = session.prepare(sa);
} catch (InvalidQueryException e) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE \"");
sb.append(Schema.FAMILY_CURRENT_SLOT_TABLE);
sb.append("\" (");
appendField(sb, Schema.COLUMN_ID, "int");
appendField(sb, Schema.COLUMN_NEXT_SLOT, "bigint");
sb.append("PRIMARY KEY (\"");
sb.append(Schema.COLUMN_ID);
sb.append("\"");
sb.append("));");
String s2 = sb.toString();
PreparedStatement ps = session.prepare(s2);
BoundStatement boundStatement = new BoundStatement(ps);
ResultSet res = session.execute(boundStatement);
}
} catch (Exception e1) {
String msg = "Failed to access or create table " + Schema.FAMILY_CURRENT_SLOT_TABLE + "!";
throw new PersistenceException(msg, e1);
}
nextDueSlotTime = (new Date()).getTime() + millisecInDueSlot;
return currentDueSlot;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method doGetArchiveMsg.
private SmsSet doGetArchiveMsg(long messageId, PreparedStatementCollection psc) throws PersistenceException {
PreparedStatement ps = psc.getRecordArchiveMesId;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(messageId);
ResultSet res = session.execute(boundStatement);
String addr = null;
UUID id = null;
for (Row row : res) {
addr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
id = row.getUUID(Schema.COLUMN_ID);
break;
}
SmsSet result = null;
if (addr != null && id != null) {
ps = psc.getRecordArchive;
boundStatement = new BoundStatement(ps);
boundStatement.bind(addr, id);
res = session.execute(boundStatement);
for (Row row : res) {
result = this.createSms(row, null, psc.getShortMessageNewStringFormat(), psc.getAddedCorrId(), psc.getAddedNetworkId(), psc.getAddedOrigNetworkId(), psc.getAddedPacket1(), true);
break;
}
}
return result;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method doGetMessageIdByRemoteMessageId.
private Long doGetMessageIdByRemoteMessageId(String remoteMessageId, String destId, PreparedStatementCollection psc) throws PersistenceException {
PreparedStatement ps = psc.getRecordArchiveDlvMesId;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(remoteMessageId, destId);
ResultSet res = session.execute(boundStatement);
Long msgId = null;
for (Row row : res) {
msgId = row.getLong(Schema.COLUMN_MESSAGE_ID);
break;
}
return msgId;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method doDeleteTable.
private void doDeleteTable(String tName) {
try {
String sa = "select * from \"" + tName + "\" limit 1";
PreparedStatement ps = session.prepare(sa);
BoundStatement boundStatement = new BoundStatement(ps);
session.execute(boundStatement);
} catch (Exception e) {
logger.info("Can not drop cassandra table because it is absent: " + tName);
return;
}
try {
String sb = "DROP TABLE \"" + tName + "\"";
PreparedStatement ps = session.prepare(sb);
BoundStatement boundStatement = new BoundStatement(ps);
session.execute(boundStatement);
logger.warn("Successfully dropped cassandra table: " + tName);
} catch (Exception e) {
logger.warn("Exception when dropping cassandra table: " + tName, e);
}
}
Aggregations