use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method checkCurrentSlotTableExists.
private synchronized void checkCurrentSlotTableExists() throws PersistenceException {
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);
}
try {
try {
// checking if PENDING_MESSAGES table exists
String sa = "SELECT * FROM \"" + Schema.FAMILY_PENDING_MESSAGES + "\" WHERE \"" + Schema.COLUMN_DAY + "\"='0';";
PreparedStatement ps = session.prepare(sa);
} catch (InvalidQueryException e) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE \"");
sb.append(Schema.FAMILY_PENDING_MESSAGES);
sb.append("\" (");
appendField(sb, Schema.COLUMN_DAY, "ascii");
appendField(sb, Schema.COLUMN_STORED_MESSAGES, "counter");
appendField(sb, Schema.COLUMN_SENT_MESSAGES, "counter");
sb.append("PRIMARY KEY (\"");
sb.append(Schema.COLUMN_DAY);
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_PENDING_MESSAGES + "!";
throw new PersistenceException(msg, e1);
}
try {
try {
// checking of SMPP_SMS_ROUTING_RULE_2 existence
String sa = "SELECT \"" + Schema.COLUMN_ADDRESS + "\" FROM \"" + Schema.FAMILY_SMPP_SMS_ROUTING_RULE + "\" where \"" + Schema.COLUMN_ADDRESS + "\"='' and \"" + Schema.COLUMN_NETWORK_ID + "\"=0;";
PreparedStatement ps = session.prepare(sa);
} catch (InvalidQueryException e) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE \"");
sb.append(Schema.FAMILY_SMPP_SMS_ROUTING_RULE);
sb.append("\" (");
appendField(sb, Schema.COLUMN_ADDRESS, "text");
appendField(sb, Schema.COLUMN_NETWORK_ID, "int");
appendField(sb, Schema.COLUMN_CLUSTER_NAME, "text");
sb.append("PRIMARY KEY (\"");
sb.append(Schema.COLUMN_ADDRESS);
sb.append("\", \"");
sb.append(Schema.COLUMN_NETWORK_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_SMPP_SMS_ROUTING_RULE + "!";
throw new PersistenceException(msg, e1);
}
try {
try {
// checking of SIP_SMS_ROUTING_RULE_2 existence
String sa = "SELECT \"" + Schema.COLUMN_ADDRESS + "\" FROM \"" + Schema.FAMILY_SIP_SMS_ROUTING_RULE + "\" where \"" + Schema.COLUMN_ADDRESS + "\"='' and \"" + Schema.COLUMN_NETWORK_ID + "\"=0;";
PreparedStatement ps = session.prepare(sa);
} catch (InvalidQueryException e) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE \"");
sb.append(Schema.FAMILY_SIP_SMS_ROUTING_RULE);
sb.append("\" (");
appendField(sb, Schema.COLUMN_ADDRESS, "text");
appendField(sb, Schema.COLUMN_NETWORK_ID, "int");
appendField(sb, Schema.COLUMN_CLUSTER_NAME, "text");
sb.append("PRIMARY KEY (\"");
sb.append(Schema.COLUMN_ADDRESS);
sb.append("\", \"");
sb.append(Schema.COLUMN_NETWORK_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_SIP_SMS_ROUTING_RULE + "!";
throw new PersistenceException(msg, e1);
}
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method c2_getSipSmsRoutingRulesRange.
/**
* Returns 100 rows of SIP_SMS_ROUTING_RULE starting from passed lastAdress. If lastAdress, first 100 rows are returned
*
* @param lastAdress
* @return
* @throws PersistenceException
*/
public List<DbSmsRoutingRule> c2_getSipSmsRoutingRulesRange(String lastAdress) throws PersistenceException {
List<DbSmsRoutingRule> ress = new FastList<DbSmsRoutingRule>();
try {
PreparedStatement ps = lastAdress != null ? getSipSmsRoutingRulesRange : getSipSmsRoutingRulesRange2;
BoundStatement boundStatement = new BoundStatement(ps);
if (lastAdress != null) {
boundStatement.bind(lastAdress);
}
ResultSet result = session.execute(boundStatement);
int i1 = 0;
for (Row row : result) {
String address = row.getString(Schema.COLUMN_ADDRESS);
String name = row.getString(Schema.COLUMN_CLUSTER_NAME);
int networkId = row.getInt(Schema.COLUMN_NETWORK_ID);
DbSmsRoutingRule res = new DbSmsRoutingRule(SmsRoutingRuleType.SIP, address, networkId, name);
if (i1 == 0) {
i1 = 1;
if (lastAdress == null)
ress.add(res);
} else {
ress.add(res);
}
}
return ress;
} catch (Exception e) {
String msg = "Failed to getSmsRoutingRule DbSmsRoutingRule for all records: " + e;
throw new PersistenceException(msg, e);
}
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method c2_clearDueSlotForTargetId.
private void c2_clearDueSlotForTargetId(String targetId, long newDueSlot) throws PersistenceException {
PreparedStatementCollection psc = this.getStatementCollection(newDueSlot);
try {
PreparedStatement ps = psc.createDueSlotForTargetId;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(targetId, 0L);
ResultSet res = session.execute(boundStatement);
} catch (Exception e1) {
String msg = "Failed to execute clearDueSlotForTargetId() !";
throw new PersistenceException(msg, e1);
}
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method c2_getRecordList.
public ArrayList<SmsSet> c2_getRecordList(long dueSlot) throws PersistenceException {
PreparedStatementCollection psc = getStatementCollection(dueSlot);
ArrayList<SmsSet> result = new ArrayList<SmsSet>();
try {
PreparedStatement ps = psc.getRecordData;
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(dueSlot);
ResultSet res = session.execute(boundStatement);
if (res != null)
for (Row row : res) {
SmsSet smsSet = this.createSms(row, null, psc.getShortMessageNewStringFormat(), psc.getAddedCorrId(), psc.getAddedNetworkId(), psc.getAddedOrigNetworkId(), psc.getAddedPacket1(), false);
if (smsSet != null)
result.add(smsSet);
}
} catch (Exception e1) {
String msg = "Failed getRecordList()";
throw new PersistenceException(msg, e1);
}
return result;
}
use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.
the class DBOperations method appendIndex.
private void appendIndex(String tName, String fieldName) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE INDEX ON \"");
sb.append(tName);
sb.append("\" (\"");
sb.append(fieldName);
sb.append("\");");
String s2 = sb.toString();
PreparedStatement ps = session.prepare(s2);
BoundStatement boundStatement = new BoundStatement(ps);
ResultSet res = session.execute(boundStatement);
}
Aggregations