Search in sources :

Example 66 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.

the class DBOperations method c2_updateAlertingSupport.

public void c2_updateAlertingSupport(long dueSlot, String targetId, UUID dbId) throws PersistenceException {
    PreparedStatementCollection psc = this.getStatementCollection(dueSlot);
    try {
        PreparedStatement ps = psc.updateAlertingSupport;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(true, dueSlot, targetId, dbId);
        ResultSet res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed to execute c2_updateAlertingSupport() !";
        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 67 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.

the class DBOperations method c2_createRecordArchive.

public void c2_createRecordArchive(Sms sms, String dlvMessageId, String dlvDestId, boolean deliveryReceipts, boolean incomingDeliveryReceipts) throws PersistenceException {
    if (!this.databaseAvailable)
        return;
    Date deliveryDate = sms.getDeliverDate();
    if (deliveryDate == null)
        deliveryDate = new Date();
    long dueSlot = this.c2_getDueSlotForTime(deliveryDate);
    PreparedStatementCollection psc = getStatementCollection(deliveryDate);
    try {
        // we are storing data into MESSAGES_YYYY_MM_DD table
        PreparedStatement ps = psc.createRecordArchive;
        BoundStatement boundStatement = new BoundStatement(ps);
        setSmsFields(sms, dueSlot, boundStatement, true, psc.getShortMessageNewStringFormat(), psc.getAddedCorrId(), psc.getAddedNetworkId(), psc.getAddedOrigNetworkId(), psc.getAddedPacket1());
        ResultSet res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed createRecordArchive - 1 !" + e1.getMessage();
        throw new PersistenceException(msg, e1);
    }
    if ((deliveryReceipts || incomingDeliveryReceipts) && !MessageUtil.isDeliveryReceipt(sms)) {
        try {
            // and created a record in MES_ID_YYYY_MM_DD table
            SmsSetCache.getInstance().putDeliveredMsgValue(sms, 30);
            PreparedStatement ps = psc.createRecordArchiveMesId;
            BoundStatement boundStatement = new BoundStatement(ps);
            boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
            boundStatement.setString(Schema.COLUMN_ADDR_DST_DIGITS, sms.getSmsSet().getDestAddr());
            boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
            ResultSet res = session.execute(boundStatement);
        } catch (Exception e1) {
            String msg = "Failed createRecordArchive - 2 !" + e1.getMessage();
            throw new PersistenceException(msg, e1);
        }
    }
    if (incomingDeliveryReceipts && !MessageUtil.isDeliveryReceipt(sms) && dlvMessageId != null && dlvMessageId.length() > 0 && dlvDestId != null) {
        try {
            // and created a record in DLV_MES_ID_YYYY_MM_DD table
            SmsSetCache.getInstance().putDeliveredRemoteMsgIdValue(dlvMessageId, dlvDestId, sms.getMessageId(), 30);
            PreparedStatement ps = psc.createRecordArchiveDlvMesId;
            BoundStatement boundStatement = new BoundStatement(ps);
            boundStatement.setString(Schema.COLUMN_REMOTE_MESSAGE_ID, dlvMessageId);
            boundStatement.setString(Schema.COLUMN_DEST_ID, dlvDestId);
            boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
            ResultSet res = session.execute(boundStatement);
        } catch (Exception e1) {
            String msg = "Failed createRecordArchive - 3 !, dlvMessageId=" + dlvMessageId + ", dlvDestId=" + dlvDestId + ", messageId=" + sms.getMessageId() + " - " + e1.getMessage();
            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) Date(java.util.Date) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 68 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.

the class DBOperations method c2_getSmppSmsRoutingRulesRange.

/**
 * Returns 100 rows of SMPP_SMS_ROUTING_RULE starting from passed lastAdress. If lastAdress, first 100 rows are returned
 *
 * @param lastAdress
 * @return
 * @throws PersistenceException
 */
public List<DbSmsRoutingRule> c2_getSmppSmsRoutingRulesRange(String lastAdress) throws PersistenceException {
    List<DbSmsRoutingRule> ress = new FastList<DbSmsRoutingRule>();
    try {
        PreparedStatement ps = lastAdress != null ? getSmppSmsRoutingRulesRange : getSmppSmsRoutingRulesRange2;
        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.SMPP, 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 69 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.

the class DBOperations method c2_updateDueSlotForTargetId.

public void c2_updateDueSlotForTargetId(String targetId, long newDueSlot) throws PersistenceException {
    PreparedStatementCollection psc = this.getStatementCollection(newDueSlot);
    try {
        PreparedStatement ps = psc.createDueSlotForTargetId;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(targetId, newDueSlot);
        ResultSet res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed to execute createDueSlotForTargetId() !";
        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 70 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project smscgateway by RestComm.

the class DBOperations method c2_setCurrentSlotTable.

private void c2_setCurrentSlotTable(int key, long newVal) throws PersistenceException {
    try {
        PreparedStatement ps = updateCurrentSlotTable;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(key, newVal);
        ResultSet res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed writing a c2_setCurrenrSlotTable !";
        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)

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