Search in sources :

Example 61 with PreparedStatement

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

Example 62 with PreparedStatement

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

Example 63 with PreparedStatement

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 64 with PreparedStatement

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 65 with PreparedStatement

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

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