Search in sources :

Example 71 with PreparedStatement

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

the class DBOperations method c2_getCurrentSlotTable.

/**
 * Initial reading CURRENT_DUE_SLOT and NEXT_MESSAGE_ID when cassandra database access starting
 *
 * @param CURRENT_DUE_SLOT or NEXT_MESSAGE_ID
 * @return dead value
 * @throws PersistenceException
 */
protected long c2_getCurrentSlotTable(int key) throws PersistenceException {
    PreparedStatement ps = selectCurrentSlotTable;
    BoundStatement boundStatement = new BoundStatement(ps);
    boundStatement.bind(key);
    ResultSet res = session.execute(boundStatement);
    long res2 = 0;
    for (Row row : res) {
        res2 = row.getLong(0);
        break;
    }
    return res2;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 72 with PreparedStatement

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

the class DBOperations method c2_getDueSlotForTargetId.

public long c2_getDueSlotForTargetId(PreparedStatementCollection psc, String targetId) throws PersistenceException {
    try {
        PreparedStatement ps = psc.getDueSlotForTargetId;
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(targetId);
        ResultSet res = session.execute(boundStatement);
        long l = 0;
        for (Row row : res) {
            l = row.getLong(0);
            break;
        }
        return l;
    } catch (Exception e1) {
        // TODO: remove it
        e1.printStackTrace();
        String msg = "Failed to execute getDueSlotForTargetId() !";
        throw new PersistenceException(msg, e1);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 73 with PreparedStatement

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

the class DBOperTesting method run.

public void run() {
    BasicConfigurator.configure();
    Logger logger = Logger.getLogger(DBOperations.class);
    try {
        logger.info("stating ...");
        logger.info("getting DBOperations_C2 ...");
        DBOperations_C2_Proxy db = new DBOperations_C2_Proxy();
        logger.info("starting DBOperations_C2 ...");
        String keySpacename = "RestCommSMSC1";
        // String keySpacename = "RestCommSMSC";
        db.start("127.0.0.1", 9042, keySpacename, "cassandra", "cassandra", 60, 60, 60 * 10, 1, 10000000000L);
        logger.info("DBOperations_C2 is started");
        logger.info("Getting of CurrentDueSlot ...");
        long processedDueSlot = db.c2_getCurrentDueSlot();
        logger.info("CurrentDueSlot = " + processedDueSlot);
        // long possibleDueSlot = dbOperations_C2.c2_getIntimeDueSlot();
        // if (processedDueSlot >= possibleDueSlot) {
        // return new OneWaySmsSetCollection();
        // }
        logger.info("getting of table list ....");
        Session secc = db.getSession();
        PreparedStatement ps = secc.prepare("select columnfamily_name from system.schema_columnfamilies where keyspace_name = '" + keySpacename + "';");
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind();
        ResultSet result = secc.execute(boundStatement);
        for (Row row : result) {
            String s = row.getString(0);
            logger.info(s);
        }
        long baseDeuSlot = 493020406;
        for (long i1 = 3600 * 6; i1 < 3600 * 12; i1++) {
            long dueSlot = baseDeuSlot - i1;
            logger.info("Getting of RecordList for deuSlot: " + dueSlot + "   " + (new Date()).toString());
            // processedDueSlot++;
            ArrayList<SmsSet> lstS = db.c2_getRecordList(dueSlot);
            logger.info("Size of RecordList=" + lstS.size());
        }
        System.exit(0);
    } catch (Throwable e) {
        logger.error("General error: ", e);
        System.exit(1);
    }
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Logger(org.apache.log4j.Logger) Date(java.util.Date) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement) SmsSet(org.mobicents.smsc.library.SmsSet) Session(com.datastax.driver.core.Session)

Example 74 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project data-transfer-project by google.

the class CosmosStore method update.

private void update(UUID id, Object instance, String query) {
    PreparedStatement statement = session.prepare(query);
    BoundStatement boundStatement = new BoundStatement(statement);
    try {
        boundStatement.setString(0, mapper.writeValueAsString(instance));
        boundStatement.setUUID(1, id);
        session.execute(boundStatement);
    } catch (JsonProcessingException e) {
        throw new MicrosoftStorageException("Error deleting data: " + id, e);
    }
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 75 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project data-transfer-project by google.

the class CosmosStore method findData.

private <T> T findData(Class<T> type, UUID id, String query, String column) {
    PreparedStatement statement = session.prepare(query);
    BoundStatement boundStatement = new BoundStatement(statement);
    boundStatement.bind(id);
    Row row = session.execute(boundStatement).one();
    String serialized = row.getString(column);
    try {
        return mapper.readValue(serialized, type);
    } catch (IOException e) {
        throw new MicrosoftStorageException("Error deserializing data: " + id, e);
    }
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) IOException(java.io.IOException) 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