Java Code Examples for org.apache.cassandra.cql3.QueryProcessor#process()
The following examples show how to use
org.apache.cassandra.cql3.QueryProcessor#process() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientOnlyExample.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private static void testWriting() throws Exception { // do some writing. for (int i = 0; i < 100; i++) { QueryProcessor.process(String.format("INSERT INTO %s.%s (id, name, value) VALUES ( 'key%d', 'colb', 'value%d')", KEYSPACE, COLUMN_FAMILY, i, i), ConsistencyLevel.QUORUM); System.out.println("wrote key" + i); } System.out.println("Done writing."); }
Example 2
Source File: Auth.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private static void setupDefaultSuperuser() { try { // insert a default superuser if AUTH_KS.USERS_CF is empty. if (!hasExistingUsers()) { QueryProcessor.process(String.format("INSERT INTO %s.%s (name, super) VALUES ('%s', %s) USING TIMESTAMP 0", AUTH_KS, USERS_CF, DEFAULT_SUPERUSER_NAME, true), ConsistencyLevel.ONE); logger.info("Created default superuser '{}'", DEFAULT_SUPERUSER_NAME); } } catch (RequestExecutionException e) { logger.warn("Skipped default superuser setup: some nodes were not ready"); } }
Example 3
Source File: ScrubTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * For CASSANDRA-6892 too, check that for a compact table with one cluster column, we can insert whatever * we want as value for the clustering column, including something that would conflict with a CQL column definition. */ @Test public void testValidationCompactStorage() throws Exception { QueryProcessor.process("CREATE TABLE \"Keyspace1\".test_compact_dynamic_columns (a int, b text, c text, PRIMARY KEY (a, b)) WITH COMPACT STORAGE", ConsistencyLevel.ONE); Keyspace keyspace = Keyspace.open("Keyspace1"); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_dynamic_columns"); QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'a', 'foo')"); QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'b', 'bar')"); QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'c', 'boo')"); cfs.forceBlockingFlush(); CompactionManager.instance.performScrub(cfs, true); // Scrub is silent, but it will remove broken records. So reading everything back to make sure nothing to "scrubbed away" UntypedResultSet rs = QueryProcessor.executeInternal("SELECT * FROM \"Keyspace1\".test_compact_dynamic_columns"); assertEquals(3, rs.size()); Iterator<UntypedResultSet.Row> iter = rs.iterator(); assertEquals("foo", iter.next().getString("c")); assertEquals("bar", iter.next().getString("c")); assertEquals("boo", iter.next().getString("c")); }
Example 4
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private void setupTableWithTrigger(String cf, Class<? extends ITrigger> triggerImpl) throws RequestExecutionException { String cql = String.format("CREATE TABLE IF NOT EXISTS %s.%s (k int, v1 int, v2 int, PRIMARY KEY (k))", ksName, cf); QueryProcessor.process(cql, ConsistencyLevel.ONE); // no conditional execution of create trigger stmt yet cql = String.format("CREATE TRIGGER trigger_1 ON %s.%s USING '%s'", ksName, cf, triggerImpl.getName()); QueryProcessor.process(cql, ConsistencyLevel.ONE); }
Example 5
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test(expected=RuntimeException.class) public void onCqlUpdateWithConditionsRejectGeneratedUpdatesForDifferentTable() throws Exception { String cf = "cf" + System.nanoTime(); try { setupTableWithTrigger(cf, CrossTableTrigger.class); String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (8, 8) IF NOT EXISTS", ksName, cf); QueryProcessor.process(cql, ConsistencyLevel.ONE); } finally { assertUpdateNotExecuted(cf, 7); } }
Example 6
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test(expected=RuntimeException.class) public void onCqlUpdateWithConditionsRejectGeneratedUpdatesForDifferentPartition() throws Exception { String cf = "cf" + System.nanoTime(); try { setupTableWithTrigger(cf, CrossPartitionTrigger.class); String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (7, 7) IF NOT EXISTS", ksName, cf); QueryProcessor.process(cql, ConsistencyLevel.ONE); } finally { assertUpdateNotExecuted(cf, 7); } }
Example 7
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void executeTriggerOnCqlBatchWithConditions() throws Exception { String cql = String.format("BEGIN BATCH " + " INSERT INTO %1$s.%2$s (k, v1) VALUES (5, 5) IF NOT EXISTS; " + " INSERT INTO %1$s.%2$s (k, v1) VALUES (5, 5); " + "APPLY BATCH", ksName, cfName); QueryProcessor.process(cql, ConsistencyLevel.ONE); assertUpdateIsAugmented(5); }
Example 8
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void executeTriggerOnCqlInsertWithConditions() throws Exception { String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (4, 4) IF NOT EXISTS", ksName, cfName); QueryProcessor.process(cql, ConsistencyLevel.ONE); assertUpdateIsAugmented(4); }
Example 9
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void executeTriggerOnCqlBatchInsert() throws Exception { String cql = String.format("BEGIN BATCH " + " INSERT INTO %s.%s (k, v1) VALUES (1, 1); " + "APPLY BATCH", ksName, cfName); QueryProcessor.process(cql, ConsistencyLevel.ONE); assertUpdateIsAugmented(1); }
Example 10
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void executeTriggerOnCqlInsert() throws Exception { String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (0, 0)", ksName, cfName); QueryProcessor.process(cql, ConsistencyLevel.ONE); assertUpdateIsAugmented(0); }
Example 11
Source File: TriggersTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { StorageService.instance.initServer(0); if (thriftServer == null || ! thriftServer.isRunning()) { thriftServer = new ThriftServer(InetAddress.getLocalHost(), 9170, 50); thriftServer.start(); } String cql = String.format("CREATE KEYSPACE IF NOT EXISTS %s " + "WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}", ksName); QueryProcessor.process(cql, ConsistencyLevel.ONE); cql = String.format("CREATE TABLE IF NOT EXISTS %s.%s (k int, v1 int, v2 int, PRIMARY KEY (k))", ksName, cfName); QueryProcessor.process(cql, ConsistencyLevel.ONE); cql = String.format("CREATE TABLE IF NOT EXISTS %s.%s (k int, v1 int, v2 int, PRIMARY KEY (k))", ksName, otherCf); QueryProcessor.process(cql, ConsistencyLevel.ONE); // no conditional execution of create trigger stmt yet if (! triggerCreated) { cql = String.format("CREATE TRIGGER trigger_1 ON %s.%s USING '%s'", ksName, cfName, TestTrigger.class.getName()); QueryProcessor.process(cql, ConsistencyLevel.ONE); triggerCreated = true; } }
Example 12
Source File: ScrubTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testScrubColumnValidation() throws InterruptedException, RequestExecutionException, ExecutionException { QueryProcessor.process("CREATE TABLE \"Keyspace1\".test_compact_static_columns (a bigint, b timeuuid, c boolean static, d text, PRIMARY KEY (a, b))", ConsistencyLevel.ONE); Keyspace keyspace = Keyspace.open("Keyspace1"); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_static_columns"); QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_static_columns (a, b, c, d) VALUES (123, c3db07e8-b602-11e3-bc6b-e0b9a54a6d93, true, 'foobar')"); cfs.forceBlockingFlush(); CompactionManager.instance.performScrub(cfs, false); }
Example 13
Source File: Auth.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Deletes the user from AUTH_KS.USERS_CF. * * @param username Username to delete. * @throws RequestExecutionException */ public static void deleteUser(String username) throws RequestExecutionException { QueryProcessor.process(String.format("DELETE FROM %s.%s WHERE name = '%s'", AUTH_KS, USERS_CF, escape(username)), consistencyForUser(username)); }
Example 14
Source File: Auth.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Inserts the user into AUTH_KS.USERS_CF (or overwrites their superuser status as a result of an ALTER USER query). * * @param username Username to insert. * @param isSuper User's new status. * @throws RequestExecutionException */ public static void insertUser(String username, boolean isSuper) throws RequestExecutionException { QueryProcessor.process(String.format("INSERT INTO %s.%s (name, super) VALUES ('%s', %s)", AUTH_KS, USERS_CF, escape(username), isSuper), consistencyForUser(username)); }
Example 15
Source File: ClientOnlyExample.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static void setupKeyspace() throws RequestExecutionException, RequestValidationException, InterruptedException { QueryProcessor.process("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}", ConsistencyLevel.ANY); QueryProcessor.process("CREATE TABLE IF NOT EXISTS " + KEYSPACE + "." + COLUMN_FAMILY + " (id ascii PRIMARY KEY, name ascii, value ascii )", ConsistencyLevel.ANY); TimeUnit.MILLISECONDS.sleep(1000); }
Example 16
Source File: CassandraAuthorizer.java From stratio-cassandra with Apache License 2.0 | 4 votes |
private static UntypedResultSet process(String query) throws RequestExecutionException { return QueryProcessor.process(query, ConsistencyLevel.ONE); }
Example 17
Source File: PasswordAuthenticator.java From stratio-cassandra with Apache License 2.0 | 4 votes |
private static UntypedResultSet process(String query, ConsistencyLevel cl) throws RequestExecutionException { return QueryProcessor.process(query, cl); }
Example 18
Source File: ListUsersStatement.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public ResultMessage execute(ClientState state) throws RequestValidationException, RequestExecutionException { return QueryProcessor.process(String.format("SELECT * FROM %s.%s", Auth.AUTH_KS, Auth.USERS_CF), ConsistencyLevel.QUORUM, QueryState.forInternalCalls()); }