本文整理汇总了Java中com.datastax.driver.core.exceptions.InvalidQueryException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidQueryException类的具体用法?Java InvalidQueryException怎么用?Java InvalidQueryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidQueryException类属于com.datastax.driver.core.exceptions包,在下文中一共展示了InvalidQueryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeQuery
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
public ResultSet executeQuery(String cql, String extra) {
if(isDryRun() && !cql.startsWith("SELECT")) {
if(extra!=null)env.info().log("Would query" + extra + ": " + cql);
} else {
if(extra!=null)env.info().log("query" + extra + ": " + cql);
try {
return session.execute(cql);
} catch (InvalidQueryException e) {
if(extra==null) {
env.info().log("query: " + cql);
}
throw e;
}
}
return null;
}
示例2: createKeySpace
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
protected void createKeySpace() {
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Checking for key-space: " + this.keySpace);
}
getSession().execute("USE " + this.keySpace);
} catch (final InvalidQueryException e) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating key-space: " + this.keySpace, e);
} else if (LOGGER.isInfoEnabled()) {
LOGGER.info("Creating key-space: " + this.keySpace);
}
getSession().execute("CREATE KEYSPACE " + this.keySpace + " with replication = " + this.replicator);
getSession().execute("USE " + this.keySpace);
}
}
示例3: checkCassandraException
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
protected void checkCassandraException(Exception e) {
_mexceptions.incr();
if (e instanceof AlreadyExistsException ||
e instanceof AuthenticationException ||
e instanceof DriverException ||
e instanceof DriverInternalError ||
e instanceof InvalidConfigurationInQueryException ||
e instanceof InvalidQueryException ||
e instanceof InvalidTypeException ||
e instanceof QueryExecutionException ||
e instanceof QueryTimeoutException ||
e instanceof QueryValidationException ||
e instanceof ReadTimeoutException ||
e instanceof SyntaxError ||
e instanceof TraceRetrievalException ||
e instanceof TruncateException ||
e instanceof UnauthorizedException ||
e instanceof UnavailableException ||
e instanceof ReadTimeoutException ||
e instanceof WriteTimeoutException) {
throw new ReportedFailedException(e);
} else {
throw new RuntimeException(e);
}
}
示例4: runMigration_shouldStopOnFailure
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Test
public void runMigration_shouldStopOnFailure() throws Exception {
String invalidMigrationStatement = "invalid migration";
when(session.execute(invalidMigrationStatement)).thenThrow(new InvalidQueryException("unit test"));
try {
client.runMigration(new Migration("001_initial_migration.cql", invalidMigrationStatement));
fail("Excepted exception");
} catch (InvalidQueryException ignored) {
}
verify(session, times(1)).execute(invalidMigrationStatement);
ArgumentCaptor<BuiltStatement> captor = ArgumentCaptor.forClass(BuiltStatement.class);
verify(session, times(2)).execute(captor.capture());
assertThat(captor.getAllValues())
.hasSize(2)
.extracting(BuiltStatement::toString)
.has(containsSubstr("UPDATE test.migrations SET status='FAILED'"), atIndex(1))
.has(containsSubstr("reason='unit test'"), atIndex(1))
.has(containsSubstr("IF status IN ('APPLYING','FAILED')"), atIndex(1));
}
示例5: testCountersTable
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Test
public void testCountersTable() throws Throwable
{
createTable("CREATE TABLE %s (" +
"k int PRIMARY KEY, " +
"count counter)");
execute("USE " + keyspace());
executeNet(protocolVersion, "USE " + keyspace());
try
{
createView("mv_counter", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE count IS NOT NULL AND k IS NOT NULL PRIMARY KEY (count,k)");
Assert.fail("MV on counter should fail");
}
catch (InvalidQueryException e)
{
}
}
示例6: testDropTableWithMV
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Test
public void testDropTableWithMV() throws Throwable
{
createTable("CREATE TABLE %s (" +
"a int," +
"b int," +
"c int," +
"d int," +
"PRIMARY KEY (a, b, c))");
executeNet(protocolVersion, "USE " + keyspace());
createView(keyspace() + ".mv1",
"CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, b, c)");
try
{
executeNet(protocolVersion, "DROP TABLE " + keyspace() + ".mv1");
Assert.fail();
}
catch (InvalidQueryException e)
{
Assert.assertEquals("Cannot use DROP TABLE on Materialized View", e.getMessage());
}
}
示例7: onWrite
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Override
public CompletableFuture<ImmutableSet<? extends Batchable<?>>> onWrite(WriteQueryData queryData) {
// this interceptor does not support where condition based queries
if (!queryData.getWhereConditions().isEmpty()) {
throw new InvalidQueryException("where condition based queries are not supported");
}
if (queryData.hasKey(ACCOUNT_ID) && queryData.hasValueToMutate(KEY) && queryData.hasSetValuesToAddOrSet(EMAIL_IDX)) {
List<Write> writes = Lists.newArrayList();
for (TupleValue tupleValue : queryData.getSetValuesToAddOrSet(EMAIL_IDX)) {
writes.add(keyByEmailDao.writeWithKey(KeyByEmailColumns.EMAIL, tupleValue.getString(0), KeyByEmailColumns.CREATED, tupleValue.getLong(1))
.value(KeyByEmailColumns.KEY, queryData.getValueToMutate(KEY))
.value(KeyByEmailColumns.ACCOUNT_ID, queryData.getKey(ACCOUNT_ID))
.withConsistency(ConsistencyLevel.QUORUM));
}
return CompletableFuture.completedFuture(ImmutableSet.copyOf(writes));
} else {
return CompletableFuture.completedFuture(ImmutableSet.of());
}
}
示例8: getTenants
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
private Set<String> getTenants() {
Set<String> tenants = new HashSet<>();
ResultSet resultset = session.execute("SELECT * FROM system_schema.keyspaces WHERE keyspace_name = 'hawkular_metrics';");
if (!resultset.iterator().hasNext()) {
return tenants;
}
try {
// An invalid query exception will occur if the table does not exists.
// If the table does not exist, then no tenants have been stored yet so we just return the empty tenant set.
ResultSet resultSet = session.execute("SELECT DISTINCT tenant_id,type from hawkular_metrics.metrics_idx;");
Iterator<Row> ri = resultSet.iterator();
while (ri.hasNext()) {
Row row = ri.next();
String tenant = row.getString("tenant_id");
if (!tenant.startsWith("_") && !tenant.contains(":")) {
tenants.add(tenant);
}
}
} catch (InvalidQueryException iqe) {
log.warn(iqe);
}
return tenants;
}
示例9: testDropKeyspace
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Test
public void testDropKeyspace() throws Exception {
// Set up a connection manager and build the cluster and keyspace
ConnectionManager cm = getConnectionManager();
CKeyspaceDefinition definition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class
, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
assertNotNull(definition);
cm.buildKeyspace(definition, false);
// Drop the keyspace
cm.dropKeyspace(definition.getName());
// Make sure it is really dropped
Session session = cm.getEmptySession();
boolean caught = false;
try {
session.execute("USE " + definition.getName() + ";");
} catch(InvalidQueryException e) {
caught = true;
}
session.close();
assertTrue(caught);
cm.teardown();
}
示例10: testShouldReturnInvalidResult
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Test
public void testShouldReturnInvalidResult() throws Exception {
String message = "This is an invalid result";
server.prime(when(query).then(invalid(message)));
thrown.expect(InvalidQueryException.class);
thrown.expectMessage(message);
query();
}
示例11: isKeyspaceAbsenceError
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
/**
* Checks if Cassandra keyspace absence error occurred.
*
* @param e Exception to check.
* @return {@code true} in case of keyspace absence error.
*/
public static boolean isKeyspaceAbsenceError(Throwable e) {
if (CassandraHelper.isKeyspaceAbsenceError(e)) {
return true;
}
while (e != null) {
if (e instanceof InvalidQueryException && KEYSPACE_EXIST_ERROR3.matcher(e.getMessage()).matches()) {
return true;
}
e = e.getCause();
}
return false;
}
示例12: onError
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
@Override
public void onError(Throwable e) {
logger.warn(e.getMessage(), e);
if (e instanceof InvalidQueryException) {
response.resume(Response.status(Response.Status.BAD_REQUEST).build());
}
response.resume(e);
}
示例13: deleteKeySpace
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
private void deleteKeySpace(String keySpace) throws CassandraServiceException {
LOGGER.info("Deleting KeySpace " + keySpace);
try {
session.execute("DROP KEYSPACE " + keySpace);
} catch (InvalidQueryException e) {
throw new CassandraServiceException("keyspace " + keySpace + " doesn't exists", e);
}
}
示例14: isKeyspaceAbsenceError
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
/**
* Checks if Cassandra keyspace absence error occur.
*
* @param e Exception to check.
* @return {@code true} in case of keyspace absence error.
*/
public static boolean isKeyspaceAbsenceError(Throwable e) {
while (e != null) {
if (e instanceof InvalidQueryException &&
(KEYSPACE_EXIST_ERROR1.matcher(e.getMessage()).matches() ||
KEYSPACE_EXIST_ERROR2.matcher(e.getMessage()).matches()))
return true;
e = e.getCause();
}
return false;
}
示例15: isTableAbsenceError
import com.datastax.driver.core.exceptions.InvalidQueryException; //导入依赖的package包/类
/**
* Checks if Cassandra table absence error occur.
*
* @param e Exception to check.
* @return {@code true} in case of table absence error.
*/
public static boolean isTableAbsenceError(Throwable e) {
while (e != null) {
if (e instanceof InvalidQueryException &&
(TABLE_EXIST_ERROR1.matcher(e.getMessage()).matches() ||
KEYSPACE_EXIST_ERROR1.matcher(e.getMessage()).matches() ||
KEYSPACE_EXIST_ERROR2.matcher(e.getMessage()).matches()))
return true;
if (e instanceof NoHostAvailableException && ((NoHostAvailableException) e).getErrors() != null) {
NoHostAvailableException ex = (NoHostAvailableException)e;
for (Map.Entry<InetSocketAddress, Throwable> entry : ex.getErrors().entrySet()) {
//noinspection ThrowableResultOfMethodCallIgnored
Throwable error = entry.getValue();
if (error instanceof DriverException &&
(error.getMessage().contains(TABLE_EXIST_ERROR2) ||
KEYSPACE_EXIST_ERROR3.matcher(error.getMessage()).matches()))
return true;
}
}
e = e.getCause();
}
return false;
}