Search in sources :

Example 6 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method doGetStatementCollection3.

private synchronized PreparedStatementCollection3 doGetStatementCollection3(String tName) throws PersistenceException {
    PreparedStatementCollection3 psc = dataTableRead3.get(tName);
    if (psc != null)
        return psc;
    try {
        try {
            // checking if a datatable exists
            String s1 = "SELECT * FROM \"" + Schema.FAMILY_SLOT_MESSAGES_TABLE + tName + "\";";
            PreparedStatement ps = session.prepare(s1);
        } catch (InvalidQueryException e) {
            // datatable does not exist
            // SLOT_MESSAGES_TABLE
            StringBuilder sb = new StringBuilder();
            sb.append("CREATE TABLE \"" + Schema.FAMILY_SLOT_MESSAGES_TABLE);
            sb.append(tName);
            sb.append("\" (");
            appendField(sb, Schema.COLUMN_ID, "uuid");
            appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
            appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
            appendField(sb, Schema.COLUMN_IN_SYSTEM, "bigint");
            appendField(sb, Schema.COLUMN_ADDR_DST_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_ADDR_DST_TON, "int");
            appendField(sb, Schema.COLUMN_ADDR_DST_NPI, "int");
            appendField(sb, Schema.COLUMN_ADDR_SRC_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_ADDR_SRC_TON, "int");
            appendField(sb, Schema.COLUMN_ADDR_SRC_NPI, "int");
            appendField(sb, Schema.COLUMN_DUE_DELAY, "int");
            appendField(sb, Schema.COLUMN_ALERTING_SUPPORTED, "boolean");
            appendField(sb, Schema.COLUMN_MESSAGE_ID, "bigint");
            appendField(sb, Schema.COLUMN_MO_MESSAGE_REF, "int");
            appendField(sb, Schema.COLUMN_ORIG_ESME_NAME, "text");
            appendField(sb, Schema.COLUMN_ORIG_SYSTEM_ID, "text");
            appendField(sb, Schema.COLUMN_DEST_CLUSTER_NAME, "text");
            appendField(sb, Schema.COLUMN_DEST_ESME_NAME, "text");
            appendField(sb, Schema.COLUMN_DEST_SYSTEM_ID, "text");
            appendField(sb, Schema.COLUMN_SUBMIT_DATE, "timestamp");
            appendField(sb, Schema.COLUMN_DELIVERY_DATE, "timestamp");
            appendField(sb, Schema.COLUMN_SERVICE_TYPE, "text");
            appendField(sb, Schema.COLUMN_ESM_CLASS, "int");
            appendField(sb, Schema.COLUMN_PROTOCOL_ID, "int");
            appendField(sb, Schema.COLUMN_PRIORITY, "int");
            appendField(sb, Schema.COLUMN_REGISTERED_DELIVERY, "int");
            appendField(sb, Schema.COLUMN_REPLACE, "int");
            appendField(sb, Schema.COLUMN_DATA_CODING, "int");
            appendField(sb, Schema.COLUMN_DEFAULT_MSG_ID, "int");
            appendField(sb, Schema.COLUMN_MESSAGE, "blob");
            appendField(sb, Schema.COLUMN_OPTIONAL_PARAMETERS, "text");
            appendField(sb, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, "timestamp");
            appendField(sb, Schema.COLUMN_VALIDITY_PERIOD, "timestamp");
            appendField(sb, Schema.COLUMN_IMSI, "ascii");
            appendField(sb, Schema.COLUMN_NNN_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_NNN_AN, "int");
            appendField(sb, Schema.COLUMN_NNN_NP, "int");
            appendField(sb, Schema.COLUMN_SM_STATUS, "int");
            appendField(sb, Schema.COLUMN_SM_TYPE, "int");
            appendField(sb, Schema.COLUMN_DELIVERY_COUNT, "int");
            sb.append("PRIMARY KEY ((\"");
            sb.append(Schema.COLUMN_DUE_SLOT);
            sb.append("\"), \"");
            sb.append(Schema.COLUMN_TARGET_ID);
            sb.append("\", \"");
            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 " + tName + "!";
        throw new PersistenceException(msg, e1);
    }
    psc = new PreparedStatementCollection3(tName);
    dataTableRead3.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 7 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method createDueSlotForTargetId.

private void createDueSlotForTargetId(PreparedStatementCollection3 psc, String targetId, long newDueSlot) throws PersistenceException {
    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) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 8 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method doGetStatementCollection.

private synchronized PreparedStatementCollection2 doGetStatementCollection(Date dt, String tName) throws PersistenceException {
    PreparedStatementCollection2 psc = dataTableRead.get(tName);
    if (psc != null)
        return psc;
    try {
        try {
            // checking if a datatable exists
            String s1 = "SELECT * FROM \"" + Schema.FAMILY_DATA + tName + "\";";
            PreparedStatement ps = session.prepare(s1);
        } catch (InvalidQueryException e) {
            // datatable does not exist
            // DATA
            StringBuilder sb = new StringBuilder();
            sb.append("CREATE TABLE \"" + Schema.FAMILY_DATA);
            sb.append(tName);
            sb.append("\" (");
            appendField(sb, Schema.COLUMN_ADDR_DST_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_ADDR_DST_TON, "int");
            appendField(sb, Schema.COLUMN_ADDR_DST_NPI, "int");
            appendField(sb, Schema.COLUMN_ID, "uuid");
            appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
            appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
            appendField(sb, Schema.COLUMN_IN_SYSTEM_SLOT, "bigint");
            appendField(sb, Schema.COLUMN_ADDR_SRC_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_ADDR_SRC_TON, "int");
            appendField(sb, Schema.COLUMN_ADDR_SRC_NPI, "int");
            appendField(sb, Schema.COLUMN_DUE_DELAY, "int");
            appendField(sb, Schema.COLUMN_ALERTING_SUPPORTED, "boolean");
            appendField(sb, Schema.COLUMN_MESSAGE_ID, "bigint");
            appendField(sb, Schema.COLUMN_MO_MESSAGE_REF, "int");
            appendField(sb, Schema.COLUMN_ORIG_ESME_NAME, "text");
            appendField(sb, Schema.COLUMN_ORIG_SYSTEM_ID, "text");
            appendField(sb, Schema.COLUMN_DEST_CLUSTER_NAME, "text");
            appendField(sb, Schema.COLUMN_DEST_ESME_NAME, "text");
            appendField(sb, Schema.COLUMN_DEST_SYSTEM_ID, "text");
            appendField(sb, Schema.COLUMN_SUBMIT_DATE, "timestamp");
            appendField(sb, Schema.COLUMN_DELIVERY_DATE, "timestamp");
            appendField(sb, Schema.COLUMN_SERVICE_TYPE, "text");
            appendField(sb, Schema.COLUMN_ESM_CLASS, "int");
            appendField(sb, Schema.COLUMN_PROTOCOL_ID, "int");
            appendField(sb, Schema.COLUMN_PRIORITY, "int");
            appendField(sb, Schema.COLUMN_REGISTERED_DELIVERY, "int");
            appendField(sb, Schema.COLUMN_REPLACE, "int");
            appendField(sb, Schema.COLUMN_DATA_CODING, "int");
            appendField(sb, Schema.COLUMN_DEFAULT_MSG_ID, "int");
            appendField(sb, Schema.COLUMN_MESSAGE, "blob");
            appendField(sb, Schema.COLUMN_OPTIONAL_PARAMETERS, "text");
            appendField(sb, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, "timestamp");
            appendField(sb, Schema.COLUMN_VALIDITY_PERIOD, "timestamp");
            appendField(sb, Schema.COLUMN_IMSI, "ascii");
            appendField(sb, Schema.COLUMN_NNN_DIGITS, "ascii");
            appendField(sb, Schema.COLUMN_NNN_AN, "int");
            appendField(sb, Schema.COLUMN_NNN_NP, "int");
            appendField(sb, Schema.COLUMN_SM_STATUS, "int");
            appendField(sb, Schema.COLUMN_SM_TYPE, "int");
            appendField(sb, Schema.COLUMN_DELIVERY_COUNT, "int");
            sb.append("PRIMARY KEY (\"");
            sb.append(Schema.COLUMN_TARGET_ID);
            sb.append("\", \"");
            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);
            // appendIndex("DATA" + tName, Schema.COLUMN_TARGET_ID);
            // appendIndex(tName, Schema.COLUMN_DUE_SLOT);
            // appendIndex("DATA" + tName, Schema.COLUMN_IN_SYSTEM_SLOT);
            // SLOTS
            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);
            // DESTS
            sb = new StringBuilder();
            sb.append("CREATE TABLE \"" + Schema.FAMILY_DESTS);
            sb.append(tName);
            sb.append("\" (");
            appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
            appendField(sb, Schema.COLUMN_ID, "uuid");
            appendField(sb, Schema.COLUMN_SENT, "boolean");
            sb.append("PRIMARY KEY (\"");
            sb.append(Schema.COLUMN_TARGET_ID);
            sb.append("\", \"");
            sb.append(Schema.COLUMN_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 PreparedStatementCollection2(tName);
    dataTableRead.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 9 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method createSms.

protected Sms createSms(final Row row, SmsSet smsSet) throws PersistenceException {
    if (row == null)
        return null;
    Sms sms = new Sms();
    sms.setDbId(row.getUUID(Schema.COLUMN_ID));
    String srcAddr = null;
    int srcAddrTon = -1;
    int srcAddrNpi = -1;
    srcAddr = row.getString(Schema.COLUMN_ADDR_SRC_DIGITS);
    srcAddrTon = row.getInt(Schema.COLUMN_ADDR_SRC_TON);
    srcAddrNpi = row.getInt(Schema.COLUMN_ADDR_SRC_NPI);
    sms.setMessageId(row.getLong(Schema.COLUMN_MESSAGE_ID));
    sms.setMoMessageRef(row.getInt(Schema.COLUMN_MO_MESSAGE_REF));
    sms.setOrigEsmeName(row.getString(Schema.COLUMN_ORIG_ESME_NAME));
    sms.setOrigSystemId(row.getString(Schema.COLUMN_ORIG_SYSTEM_ID));
    sms.setSubmitDate(DBOperations.getRowDate(row, Schema.COLUMN_SUBMIT_DATE));
    sms.setSourceAddr(row.getString(Schema.COLUMN_ADDR_SRC_DIGITS));
    sms.setSourceAddrTon(row.getInt(Schema.COLUMN_ADDR_SRC_TON));
    sms.setSourceAddrNpi(row.getInt(Schema.COLUMN_ADDR_SRC_NPI));
    sms.setServiceType(row.getString(Schema.COLUMN_SERVICE_TYPE));
    sms.setEsmClass(row.getInt(Schema.COLUMN_ESM_CLASS));
    sms.setProtocolId(row.getInt(Schema.COLUMN_PROTOCOL_ID));
    sms.setPriority(row.getInt(Schema.COLUMN_PRIORITY));
    sms.setRegisteredDelivery(row.getInt(Schema.COLUMN_REGISTERED_DELIVERY));
    sms.setReplaceIfPresent(row.getInt(Schema.COLUMN_REPLACE));
    sms.setDataCoding(row.getInt(Schema.COLUMN_DATA_CODING));
    sms.setDefaultMsgId(row.getInt(Schema.COLUMN_DEFAULT_MSG_ID));
    ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE);
    byte[] buf = new byte[bb.limit() - bb.position()];
    bb.get(buf);
    sms.setShortMessage(buf);
    sms.setScheduleDeliveryTime(DBOperations.getRowDate(row, Schema.COLUMN_SCHEDULE_DELIVERY_TIME));
    sms.setValidityPeriod(DBOperations.getRowDate(row, Schema.COLUMN_VALIDITY_PERIOD));
    sms.setDeliveryCount(row.getInt(Schema.COLUMN_DELIVERY_COUNT));
    String s = row.getString(Schema.COLUMN_OPTIONAL_PARAMETERS);
    if (s != null) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
            XMLObjectReader reader = XMLObjectReader.newInstance(bais);
            TlvSet copy = reader.read(TLV_SET, TlvSet.class);
            sms.getTlvSet().clearAllOptionalParameter();
            sms.getTlvSet().addAllOptionalParameter(copy.getOptionalParameters());
        } catch (XMLStreamException e) {
            String msg = "XMLStreamException when deserializing optional parameters for '" + sms.getDbId() + "'!";
            throw new PersistenceException(msg, e);
        }
    }
    if (smsSet == null) {
        smsSet = new SmsSet();
        String destAddr = null;
        int destAddrTon = -1;
        int destAddrNpi = -1;
        destAddr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
        destAddrTon = row.getInt(Schema.COLUMN_ADDR_DST_TON);
        destAddrNpi = row.getInt(Schema.COLUMN_ADDR_DST_NPI);
        if (destAddr == null || destAddrTon == -1 || destAddrNpi == -1) {
            throw new PersistenceException("destAddr or destAddrTon or destAddrNpi is absent for ID='" + sms.getDbId() + "'");
        }
        smsSet.setDestAddr(destAddr);
        smsSet.setDestAddrTon(destAddrTon);
        smsSet.setDestAddrNpi(destAddrNpi);
        smsSet.updateDueDelay(row.getInt(Schema.COLUMN_DUE_DELAY));
    }
    smsSet.addSms(sms);
    return sms;
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) XMLObjectReader(javolution.xml.XMLObjectReader) TlvSet(org.restcomm.smpp.parameter.TlvSet) ByteBuffer(java.nio.ByteBuffer) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 10 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method getSmsSetForTargetId.

public SmsSet getSmsSetForTargetId(Date[] dtt, NN_LoadedTargetId ti) throws PersistenceException {
    SmsSet smsSet = null;
    for (Date dt : dtt) {
        PreparedStatementCollection2 psc = getStatementCollection(dt);
        ArrayList<UUID> lst2 = new ArrayList<UUID>();
        try {
            PreparedStatement ps = psc.getIdListDests;
            BoundStatement boundStatement = new BoundStatement(ps);
            boundStatement.bind(ti.getTargetId());
            ResultSet res = session.execute(boundStatement);
            for (Row row : res) {
                UUID id = row.getUUID(0);
                boolean sent = row.getBool(1);
                if (!sent)
                    lst2.add(id);
            }
        } catch (Exception e1) {
            String msg = "Failed reading a set of ID from DESTS for targetId " + ti.getTargetId() + " !";
            throw new PersistenceException(msg, e1);
        }
        try {
            for (UUID id : lst2) {
                PreparedStatement ps = psc.getSms;
                BoundStatement boundStatement = new BoundStatement(ps);
                boundStatement.bind(ti.getTargetId(), id);
                ResultSet res = session.execute(boundStatement);
                for (Row row : res) {
                    Sms sms = createSms(row, smsSet);
                    smsSet = sms.getSmsSet();
                }
            }
        } catch (Exception e1) {
            String msg = "Failed reading SmsSet for " + ti.getTargetId() + " !";
            throw new PersistenceException(msg, e1);
        }
    }
    if (smsSet != null)
        smsSet.resortSms();
    else {
        // no message records - removing TARGET_ID from SLOTS
        PreparedStatementCollection2 psc = getStatementCollection(ti.getDtx());
        PreparedStatement ps = psc.deleteRecordSlots;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(ti.getDueSlot(), ti.getTargetId());
        ResultSet res = session.execute(boundStatement);
    }
    return smsSet;
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Date(java.util.Date) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) ResultSet(com.datastax.driver.core.ResultSet) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) Sms(org.mobicents.smsc.library.Sms) Row(com.datastax.driver.core.Row) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) SmsSet(org.mobicents.smsc.library.SmsSet)

Aggregations

PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)28 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)12 ResultSet (com.datastax.driver.core.ResultSet)12 XMLStreamException (javolution.xml.stream.XMLStreamException)11 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)10 Sms (org.mobicents.smsc.library.Sms)9 Date (java.util.Date)6 SmsSet (org.mobicents.smsc.library.SmsSet)5 Row (com.datastax.driver.core.Row)4 CreateException (javax.slee.CreateException)4 EventType (org.mobicents.smsc.library.EventType)4 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)4 TargetAddress (org.mobicents.smsc.library.TargetAddress)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DbSmsRoutingRule (org.mobicents.smsc.library.DbSmsRoutingRule)3 MessageDeliveryResultResponseInterface (org.mobicents.smsc.library.MessageDeliveryResultResponseInterface)3 Esme (org.restcomm.smpp.Esme)3 EsmeManagement (org.restcomm.smpp.EsmeManagement)3