Search in sources :

Example 6 with PreparedStatement

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);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 7 with PreparedStatement

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);
    }
}
Also used : FastList(javolution.util.FastList) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) DbSmsRoutingRule(org.mobicents.smsc.library.DbSmsRoutingRule) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 8 with PreparedStatement

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);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 9 with PreparedStatement

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;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement) SmsSet(org.mobicents.smsc.library.SmsSet) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 10 with PreparedStatement

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);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

PreparedStatement (com.datastax.driver.core.PreparedStatement)113 ResultSet (com.datastax.driver.core.ResultSet)60 BoundStatement (com.datastax.driver.core.BoundStatement)59 Session (com.datastax.driver.core.Session)39 Test (org.junit.Test)30 Row (com.datastax.driver.core.Row)27 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)27 XMLStreamException (javolution.xml.stream.XMLStreamException)25 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)15 Cluster (com.datastax.driver.core.Cluster)9 Date (java.util.Date)9 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)7 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)7 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)7 ICluster (org.apache.cassandra.distributed.api.ICluster)7