private void primeAndExecuteQueries(String[] primed, String[] queries) throws Exception { SuccessResult result = getSampleSuccessResult(); for (String primeQuery : primed) { server.prime(when(primeQuery).then(result)); } try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { Session session = driverCluster.connect(); server.getCluster().clearLogs(); for (String executeQuery : queries) { SimpleStatement stmt = new SimpleStatement(executeQuery); stmt.setDefaultTimestamp(100); session.execute(stmt); } } }
public void executePut(String query, String consistency){ logger.debug("in data store handle, executing put:"+query); long start = System.currentTimeMillis(); Statement statement = new SimpleStatement(query); if(consistency.equalsIgnoreCase("critical")){ logger.info("Executing critical put query:"+query); statement.setConsistencyLevel(ConsistencyLevel.QUORUM); } else if (consistency.equalsIgnoreCase("eventual")){ logger.info("Executing normal put query:"+query); statement.setConsistencyLevel(ConsistencyLevel.ONE); } session.execute(statement); long end = System.currentTimeMillis(); logger.debug("Time taken for actual put in cassandra:"+(end-start)); }
private ArgumentMatcher<Statement> getHostStatementMatcher(final Host host, final String query) throws Exception { return new ArgumentMatcher<Statement>() { @Override public boolean matches(Object argument) { SelectedHostStatement statement = (SelectedHostStatement) argument; return ((SimpleStatement)statement.getStatement()).getQueryString().equals(query) && Objects.equals(statement.getHostCordinator().getAddress(), host.getAddress()); } @Override public void describeTo(Description description) { description.appendText(format("query:%s host:%s", query, host.getAddress().toString())); } }; }
@Test public void should_generate_simple_statement() throws Exception { //Given String input = "SELECT * FROM users LIMIT 10;"; CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM), Option.<ConsistencyLevel>empty(), Option.empty(), Option.<RetryPolicy>empty(), Option.empty()); //When final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options, intrContext); //Then assertThat(actual).isNotNull(); assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;"); assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM); }
@Test public void should_generate_batch_statement() throws Exception { //Given Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;"); Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);"); Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;"); CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM), Option.<ConsistencyLevel>empty(), Option.empty(), Option.<RetryPolicy>empty(), Option.empty()); //When BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3))); //Then assertThat(actual).isNotNull(); final List<Statement> statements = new ArrayList<>(actual.getStatements()); assertThat(statements).hasSize(3); assertThat(statements.get(0)).isSameAs(st1); assertThat(statements.get(1)).isSameAs(st2); assertThat(statements.get(2)).isSameAs(st3); assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM); }
/** * Build schema programmatically * <p> * DDL equivalent: * * <pre> * CREATE TABLE messages ( * sessionId uuid, * seqNo bigint, * message blob, * PRIMARY KEY (sessionId, seqNo ) ); * </pre> * * @throws StoreException if the store is not open * */ public void buildSchema() throws StoreException { if (session != null) { // Appropriate for a local test only session.execute(new SimpleStatement("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE_NAME + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }")); System.out.format("Keyspace %s available\n", KEYSPACE_NAME); Create create = SchemaBuilder.createTable(KEYSPACE_NAME, TABLE_NAME).ifNotExists() .addPartitionKey(SESSION_ID_COLNAME, DataType.uuid()) .addClusteringColumn(SEQ_NO_COLNAME, DataType.bigint()) .addColumn(MESSAGE_COLNAME, DataType.blob()); ResultSet resultSet = session.execute(create); System.out.format("Table %s available\n", TABLE_NAME); } else { throw new StoreException("Schema not created; store not open"); } }
@Test public void should_generate_simple_statement() throws Exception { //Given String input = "SELECT * FROM users LIMIT 10;"; CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM), Option.<ConsistencyLevel>empty(), Option.empty(), Option.<RetryPolicy>empty(), Option.empty(), Option.empty()); //When final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options, intrContext); //Then assertThat(actual).isNotNull(); assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;"); assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM); }
@Test public void should_generate_batch_statement() throws Exception { //Given Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;"); Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);"); Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;"); CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM), Option.<ConsistencyLevel>empty(), Option.empty(), Option.<RetryPolicy>empty(), Option.empty(), Option.empty()); //When BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3))); //Then assertThat(actual).isNotNull(); final List<Statement> statements = new ArrayList<>(actual.getStatements()); assertThat(statements).hasSize(3); assertThat(statements.get(0)).isSameAs(st1); assertThat(statements.get(1)).isSameAs(st2); assertThat(statements.get(2)).isSameAs(st3); assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM); }
@Override public DBResult queryForLastWriteTimes() { if (cluster == null) return null; try (Session session = cluster.newSession()) { Statement statement = new SimpleStatement(String.format("SELECT WRITETIME (%s) FROM %s.%s;", columnName, keyspace, tableName)); statement.setConsistencyLevel(ConsistencyLevel.ALL); ResultSet results = session.execute(statement); List<Row> allRows = results.all(); // sort all of the rows accordingly allRows.sort(new RowComparator()); // gather the information we need long startTime = allRows.get(0).getLong(0) / 1000; long endTime = allRows.get(allRows.size() - 1).getLong(0) / 1000; int totalCount = allRows.size(); return new DBResult(startTime, endTime, totalCount); } }
static void load(SessionContext sessionContext, List<String> cqlStatements) { if (!cqlStatements.isEmpty()) { sessionContext.checkClusterHealth(); } try { cqlStatements.stream() .map(stringStatement -> new SimpleStatement(stringStatement).setConsistencyLevel(sessionContext.getWriteConsistencyLevel())) .forEach(statement -> { LOGGER.debug("Executing cql statement {}", statement); sessionContext.getSession().execute(statement); }); } catch (DriverException e) { LOGGER.error("Failed to execute cql statements {}: {}", cqlStatements, e.getMessage()); throw e; } }
public int[] executeBatch() throws SQLException { int[] returnCounts= new int[batchQueries.size()]; List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>(); if (logger.isTraceEnabled() || this.connection.debugMode) logger.debug("CQL statements: "+ batchQueries.size()); for(String q:batchQueries){ if (logger.isTraceEnabled() || this.connection.debugMode) logger.debug("CQL: "+ q); SimpleStatement stmt = new SimpleStatement(q); stmt.setConsistencyLevel(this.connection.defaultConsistencyLevel); ResultSetFuture resultSetFuture = this.connection.getSession().executeAsync(stmt); futures.add(resultSetFuture); } int i=0; for (ResultSetFuture future : futures){ future.getUninterruptibly(); returnCounts[i]=1; i++; } return returnCounts; }
public ResultSet getRows(String keyspace, String table, int limit, String startKey, ConsistencyLevel level) { StringBuilder command = new StringBuilder(); command.append("SELECT * from ").append(keyspace).append(".") .append(table); if (startKey != null) { command.append(" WHERE token(key)>token('").append(startKey) .append("')"); } if (limit > 0) { command.append(" LIMIT ").append(Integer.toString(limit)); } command.append(";"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); ResultSet result = executeQuery(ss); return result; }
public ResultSet getColumnFromRow(String keyspace, String tableName, String key, String column, ConsistencyLevel level) { StringBuilder command = new StringBuilder(); // Build SELECT query command.append("SELECT ").append(column).append(" FROM ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" WHERE ").append(KEY) .append(" = '").append(key).append("';"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); ResultSet result = executeQuery(ss); return result; }
public ResultSet getColumnsFromRow(String keyspace, String tableName, String key, ArrayList<String> columns, ConsistencyLevel level) { StringBuilder command = new StringBuilder(); StringBuilder cols = new StringBuilder(); // Build column list cols.append(columns.get(0)); for (int i = 1; i < columns.size(); i++) { cols.append(",").append(columns.get(i)); } // Build SELECT query command.append("SELECT ").append(cols.toString()).append(" FROM ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" WHERE ").append(KEY) .append(" = '").append(key).append("';"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); ResultSet result = executeQuery(ss); return result; }
public ResultSet getRowByVersion(String keyspace, String tableName, int version, ConsistencyLevel level) { Long start = System.nanoTime(); StringBuilder command = new StringBuilder(); command.append("SELECT * FROM ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" WHERE ") .append(VERSION).append(" = ").append(version).append(";"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); ResultSet result = executeQuery(ss); IOStats.getRowByVersion(((double) System.nanoTime() - (double) start) / 1000000); return result; }
public void markDeleted(String keyspace, String tableName, String key, int version, ConsistencyLevel level) { Long start = System.nanoTime(); StringBuilder command = new StringBuilder(); command.append("UPDATE ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" USING TIMESTAMP ") .append(++this.counter).append(" SET ").append(DELETED) .append(" = true,").append(VERSION).append(" = ") .append(version).append(" WHERE ").append(KEY).append(" = '") .append(key).append("';"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); executeQuery(ss); IOStats.markDelRow(((double) System.nanoTime() - (double) start) / 1000000); }
public void deleteColumnsFromRow(String keyspace, String tableName, String key, List<String> columns, ConsistencyLevel level) { StringBuilder command = new StringBuilder(); command.append("DELETE "); String col = columns.get(0); command.append(col); for (int i = 1; i < columns.size(); i++) { col = columns.get(i); command.append(",").append(col); } command.append(" FROM ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" WHERE ").append(KEY) .append(" = '").append(key).append("';"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); executeQuery(ss); }
public void deleteRow(String keyspace, String tableName, String key, ConsistencyLevel level) { Long start = System.nanoTime(); StringBuilder command = new StringBuilder(); command.append("DELETE FROM ") .append((keyspace == null) ? keyspaceName : keyspace) .append(".").append(tableName).append(" WHERE ").append(KEY) .append(" = '").append(key).append("';"); SimpleStatement ss = new SimpleStatement(command.toString()); ss.setConsistencyLevel(level); executeQuery(ss); IOStats.delRow(((double) System.nanoTime() - (double) start) / 1000000); }
public ResultSet execute() { if (session == null) init(); // Select selectQuery = QueryBuilder.select().all().from(HiveCassandraUtils.getKeyspace(conf), HiveCassandraUtils.getColumnFamily(this.conf)); StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM "); sb.append(HiveCassandraUtils.getKeyspace(conf)); sb.append("."); sb.append(HiveCassandraUtils.getColumnFamily(conf)); String whereClause = HiveCassandraUtils.getWhereClause(conf); if (!Strings.isNullOrEmpty(whereClause)) { sb.append(" WHERE "); sb.append(getWhereClause(conf)); } SimpleStatement selectQuery = new SimpleStatement(sb.toString()); selectQuery.setConsistencyLevel(ConsistencyLevel.valueOf(HiveCassandraUtils.getInputConsistencyLevel(conf))); return session.execute(selectQuery); }
@Override public void transactionMarker() throws Exception { BatchStatement batchStatement = new BatchStatement(); batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (100, 'f100', 'l100')")); batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (101, 'f101', 'l101')")); PreparedStatement preparedStatement = session.prepare("INSERT INTO test.users (id, fname, lname) VALUES (?, ?, ?)"); for (int i = 200; i < 210; i++) { BoundStatement boundStatement = new BoundStatement(preparedStatement); boundStatement.bind(i, "f" + i, "l" + i); batchStatement.add(boundStatement); } batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (300, 'f300', 'l300')")); session.executeAsync(batchStatement).get(); }
@Override public void transactionMarker() throws Exception { BatchStatement batchStatement = new BatchStatement(); batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (100, 'f100', 'l100')")); batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (101, 'f101', 'l101')")); PreparedStatement preparedStatement = session.prepare("INSERT INTO test.users (id, fname, lname) VALUES (?, ?, ?)"); for (int i = 200; i < 210; i++) { BoundStatement boundStatement = new BoundStatement(preparedStatement); boundStatement.bind(i, "f" + i, "l" + i); batchStatement.add(boundStatement); } batchStatement.add(new SimpleStatement( "INSERT INTO test.users (id, fname, lname) VALUES (300, 'f300', 'l300')")); session.execute(batchStatement); }
void returnStatement(Statement stmnt) { if (stmnt != null) { if (stmnt instanceof BoundStatement) { synchronized (boundStack) { if (boundStack.size() < getStackSize()) { boundStack.push((BoundStatement) stmnt); } } } else { synchronized (simpleStack) { if (simpleStack.size() < getStackSize()) { simpleStack.push((SimpleStatement) stmnt); } } } } }
/** * {@inheritDoc} * * @param key * @param fields * @return */ @Override public Persistent get(Object key, String[] fields) { if (fields == null) { fields = getFields(); } String cqlQuery = CassandraQueryFactory.getSelectObjectWithFieldsQuery(mapping, fields); SimpleStatement statement = new SimpleStatement(cqlQuery, key); if (readConsistencyLevel != null) { statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel)); } ResultSet results = client.getSession().execute(statement); Result<T> objects = mapper.map(results); List<T> objectList = objects.all(); if (objectList != null) { LOG.debug("Object is found for key : {}", key); return objectList.get(0); } LOG.debug("Object is not found for key : {}", key); return null; }
/** * {@inheritDoc} * * @param key * @param fields * @return */ @Override public Persistent get(Object key, String[] fields) { if (fields == null) { fields = getFields(); } ArrayList<String> cassandraKeys = new ArrayList<>(); ArrayList<Object> cassandraValues = new ArrayList<>(); AvroCassandraUtils.processKeys(mapping, key, cassandraKeys, cassandraValues); String cqlQuery = CassandraQueryFactory.getSelectObjectWithFieldsQuery(mapping, fields, cassandraKeys); SimpleStatement statement = new SimpleStatement(cqlQuery, cassandraValues.toArray()); if (readConsistencyLevel != null) { statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel)); } ResultSet resultSet = this.client.getSession().execute(statement); Iterator<Row> iterator = resultSet.iterator(); ColumnDefinitions definitions = resultSet.getColumnDefinitions(); T obj = null; if (iterator.hasNext()) { obj = cassandraDataStore.newPersistent(); AbstractGettableData row = (AbstractGettableData) iterator.next(); populateValuesToPersistent(row, definitions, obj, fields); } return obj; }
/** * {@inheritDoc} * * @param key * @return */ @Override public Persistent get(Object key) { ArrayList<String> cassandraKeys = new ArrayList<>(); ArrayList<Object> cassandraValues = new ArrayList<>(); AvroCassandraUtils.processKeys(mapping, key, cassandraKeys, cassandraValues); String cqlQuery = CassandraQueryFactory.getSelectObjectQuery(mapping, cassandraKeys); SimpleStatement statement = new SimpleStatement(cqlQuery, cassandraValues.toArray()); if (readConsistencyLevel != null) { statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel)); } ResultSet resultSet = client.getSession().execute(statement); Iterator<Row> iterator = resultSet.iterator(); ColumnDefinitions definitions = resultSet.getColumnDefinitions(); T obj = null; if (iterator.hasNext()) { obj = cassandraDataStore.newPersistent(); AbstractGettableData row = (AbstractGettableData) iterator.next(); populateValuesToPersistent(row, definitions, obj, mapping.getFieldNames()); } return obj; }
public static BatchStatement makeNativeBatchStatement(List<String> queries, List<List> values) { BatchStatement statement = new BatchStatement(); Iterator<List> valuesIterator = values.iterator(); for (String query : queries) { List value = valuesIterator.next(); statement.add(new SimpleStatement(query, value.toArray(new Object[value.size()]))); } return statement; }
@Test public void testShouldReturnClientTimeout() throws Exception { server.prime(when(query)); thrown.expect(OperationTimedOutException.class); query(new SimpleStatement(query).setReadTimeoutMillis(1000)); }
public static void main(String[] args) { Session session = Connection.connect(); SimpleStatement statement1 = new SimpleStatement("insert into user (id, name, age) values (?, ?, ?)", UUIDs.timeBased(), "user01", 30); statement1.setConsistencyLevel(ConsistencyLevel.ONE); try { ResultSet rs = session.execute(statement1); System.out.println(rs); } catch (Exception ex) { ex.printStackTrace(); } SimpleStatement statement2 = new SimpleStatement("select id, name, age from user"); ResultSet rs2 = session.execute(statement2); System.out.println(rs2); for (Row row : rs2) { System.out.printf("id: %s, name: %s, age: %d\n", row.get(0, UUID.class), row.getString(1), row.getInt(2)); } Connection.close(); }
/** * This method executes a write query in Music * @param cql the CQL to be sent to Cassandra */ protected void executeMusicWriteQuery(String cql) { logger.debug("Executing MUSIC write:"+ cql); Session sess = getMusicSession(); SimpleStatement s = new SimpleStatement(cql); s.setReadTimeoutMillis(60000); synchronized (sess) { sess.execute(s); } }
public ResultSet executeEventualGet(String query){ logger.info("Executing normal get query:"+query); long start = System.currentTimeMillis(); Statement statement = new SimpleStatement(query); statement.setConsistencyLevel(ConsistencyLevel.ONE); ResultSet results = session.execute(statement); long end = System.currentTimeMillis(); logger.debug("Time taken for actual get in cassandra:"+(end-start)); return results; }
public ResultSet executeCriticalGet(String query){ Statement statement = new SimpleStatement(query); logger.info("Executing critical get query:"+query); statement.setConsistencyLevel(ConsistencyLevel.QUORUM); ResultSet results = session.execute(statement); return results; }
private void executeCreateQuery(String query, String consistency) throws Exception { Statement statement = new SimpleStatement(query); if (consistency.equalsIgnoreCase("atomic")) statement.setConsistencyLevel(ConsistencyLevel.ALL); else if (consistency.equalsIgnoreCase("eventual")) statement.setConsistencyLevel(ConsistencyLevel.ONE); else throw new Exception("Consistency level "+consistency+ " unknown!!"); session.execute(statement); }
private static void load(Trans trans, Session session, String query) { // trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Perms", Env.REMOTE); ResultSet results; try { Statement stmt = new SimpleStatement( query ); results = session.execute(stmt); } finally { tt.done(); } try { Iterator<Row> iter = results.iterator(); Row row; tt = trans.start("Load Perms", Env.SUB); try { while(iter.hasNext()) { row = iter.next(); Perm pk = new Perm(row.getString(0),row.getString(1),row.getString(2),row.getString(3), row.getString(4), row.getSet(5,String.class)); keys.put(pk.encode(), pk); data.put(pk,pk.roles); } } finally { tt.done(); } } finally { trans.info().log("Found",data.size(),"perms"); } }
private static void load(Trans trans, Session session, String query, Creator<NS> creator) { trans.info().log( "query: " + query ); ResultSet results; TimeTaken tt; tt = trans.start("Read Namespaces", Env.REMOTE); try { Statement stmt = new SimpleStatement( query ); results = session.execute(stmt); } finally { tt.done(); } try { Iterator<Row> iter = results.iterator(); Row row; tt = trans.start("Load Namespaces", Env.SUB); try { while(iter.hasNext()) { row = iter.next(); NS ns = creator.create(row); data.put(ns.name,ns); } } finally { tt.done(); } } finally { trans.info().log("Found",data.size(),"Namespaces"); } }
private static void load(Trans trans, Session session, String query) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Creds", Env.REMOTE); ResultSet results; try { Statement stmt = new SimpleStatement( query ); results = session.execute(stmt); } finally { tt.done(); } int count = 0; try { Iterator<Row> iter = results.iterator(); Row row; tt = trans.start("Load Roles", Env.SUB); try { while(iter.hasNext()) { ++count; row = iter.next(); String id = row.getString(0); Cred cred = data.get(id); if(cred==null) { cred = new Cred(id); data.put(id, cred); } cred.instances.add(new Instance(row.getInt(1), row.getDate(2), row.getInt(3))); } } finally { tt.done(); } } finally { trans.info().log("Found",count,"creds"); } }
public static void load(Trans trans, Session session, String query, Map<String,MiscID> map) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read MiscID", Env.REMOTE); ResultSet results; try { Statement stmt = new SimpleStatement( query ); results = session.execute(stmt); } finally { tt.done(); } int count = 0; try { tt = trans.start("Load Map", Env.SUB); try { for( Row row : results.all()) { MiscID miscID = new MiscID(); miscID.set(row); data.put(miscID.id,miscID); ++count; } } finally { tt.done(); } } finally { trans.info().log("Found",count,"miscID records"); } }
public static void load(Trans trans, Session session, Creator<Future> creator) { trans.info().log( "query: " + creator.select() ); ResultSet results; TimeTaken tt = trans.start("Load Futures", Env.REMOTE); try { Statement stmt = new SimpleStatement(creator.select()); results = session.execute(stmt); } finally { tt.done(); } int count = 0; tt = trans.start("Process Futures", Env.SUB); try { for(Row row : results.all()) { ++count; Future f = creator.create(row); data.add(f); List<Future> lf = byMemo.get(f.memo); if(lf == null) { lf = new ArrayList<Future>(); byMemo.put(f.memo, lf); } lf.add(f); } } finally { trans.info().log("Found",count,"Futures"); } }
public static void load(Trans trans, Session session, Creator<NsAttrib> creator ) { trans.info().log( "query: " + creator.select() ); ResultSet results; TimeTaken tt = trans.start("Load NsAttributes", Env.REMOTE); try { Statement stmt = new SimpleStatement(creator.select()); results = session.execute(stmt); } finally { tt.done(); } int count = 0; tt = trans.start("Process NsAttributes", Env.SUB); try { for(Row row : results.all()) { ++count; NsAttrib ur = creator.create(row); data.add(ur); List<NsAttrib> lna = byKey.get(ur.key); if(lna==null) { lna = new ArrayList<NsAttrib>(); byKey.put(ur.key, lna); } lna.add(ur); lna = byNS.get(ur.ns); if(lna==null) { lna = new ArrayList<NsAttrib>(); byNS.put(ur.ns, lna); } lna.add(ur); } } finally { tt.done(); trans.info().log("Found",count,"NS Attributes"); } }
private static void load(Trans trans, Session session, String query) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Roles", Env.REMOTE); ResultSet results; try { Statement stmt = new SimpleStatement( query ); results = session.execute(stmt); } finally { tt.done(); } try { Iterator<Row> iter = results.iterator(); Row row; tt = trans.start("Load Roles", Env.SUB); try { while(iter.hasNext()) { row = iter.next(); Role rk =new Role(row.getString(0),row.getString(1), row.getString(2),row.getSet(3,String.class)); keys.put(rk.encode(), rk); data.put(rk,rk.perms); } } finally { tt.done(); } } finally { trans.info().log("Found",data.size(),"roles"); } }
public static void load(Trans trans, Session session, Creator<Notification> creator ) { trans.info().log( "query: " + creator.select() ); TimeTaken tt = trans.start("Load Notify", Env.REMOTE); ResultSet results; try { Statement stmt = new SimpleStatement(creator.select()); results = session.execute(stmt); } finally { tt.done(); } int count = 0; tt = trans.start("Process Notify", Env.SUB); try { for(Row row : results.all()) { ++count; try { Notification not = creator.create(row); List<Notification> ln = data.get(not.user); if(ln==null) { ln = new ArrayList<Notification>(); data.put(not.user, ln); } ln.add(not); } finally { tt.done(); } } } finally { tt.done(); trans.info().log("Found",count,"Notify Records"); } }