当前位置: 首页>>代码示例>>Java>>正文


Java Code.INVALID_ARGUMENT属性代码示例

本文整理汇总了Java中com.google.rpc.Code.INVALID_ARGUMENT属性的典型用法代码示例。如果您正苦于以下问题:Java Code.INVALID_ARGUMENT属性的具体用法?Java Code.INVALID_ARGUMENT怎么用?Java Code.INVALID_ARGUMENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.rpc.Code的用法示例。


在下文中一共展示了Code.INVALID_ARGUMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commit

@Override
public void commit(Xid xid, boolean onePhase) throws XAException
{
	if (logger.logDebug())
	{
		debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)"));
	}

	if (xid == null)
	{
		throw new CloudSpannerXAException("xid must not be null", Code.INVALID_ARGUMENT, XAException.XAER_INVAL);
	}

	if (onePhase)
	{
		commitOnePhase(xid);
	}
	else
	{
		commitPrepared(xid);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:22,代码来源:CloudSpannerXAConnection.java

示例2: createInsertWithSelectStatement

private InsertWorker createInsertWithSelectStatement(Insert insert, boolean forceUpdate) throws SQLException
{
	Select select = insert.getSelect();
	if (select == null)
	{
		throw new CloudSpannerSQLException("Insert statement must contain a select statement",
				Code.INVALID_ARGUMENT);
	}
	boolean isDuplicate = insert.isUseDuplicate();
	InsertWorker.DMLOperation mode;
	if (forceUpdate)
		mode = DMLOperation.Update;
	else if (isDuplicate)
		mode = DMLOperation.OnDuplicateKeyUpdate;
	else
		mode = DMLOperation.Insert;
	return new InsertWorker(getConnection(), select, insert, getConnection().isAllowExtendedMode(), mode);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:18,代码来源:CloudSpannerPreparedStatement.java

示例3: executeUpdate

@Override
public int executeUpdate(String[] sqlTokens) throws SQLException
{
	if (sqlTokens.length != 1)
		throw new CloudSpannerSQLException(
				"Invalid argument(s) for EXECUTE_DDL_BATCH. Expected \"EXECUTE_DDL_BATCH\"",
				Code.INVALID_ARGUMENT);
	try (CloudSpannerStatement statement = getConnection().createStatement())
	{
		List<String> operations = getConnection().getAutoBatchedDdlOperations();
		for (String sql : operations)
			statement.addBatch(sql);
		statement.executeBatch();
		return operations.size();
	}
	finally
	{
		getConnection().clearAutoBatchedDdlOperations();
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:20,代码来源:CloudSpannerStatement.java

示例4: testCreateTableStatement

private static void testCreateTableStatement(String sql) throws SQLException
{
	boolean isDDL = isDDLStatement(sql);
	Assert.assertTrue(isDDL);
	Statement statement = null;
	try
	{
		statement = CCJSqlParserUtil.parse(sql);
	}
	catch (JSQLParserException e)
	{
		throw new CloudSpannerSQLException("Could not parse SQL statement", Code.INVALID_ARGUMENT, e);
	}
	Assert.assertNotNull(statement);
	Assert.assertEquals(CreateTable.class, statement.getClass());
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:16,代码来源:CloudSpannerPreparedStatementTest.java

示例5: createSelect

private static Select createSelect(CloudSpannerConnection connection, Delete delete) throws SQLException
{
	TableKeyMetaData table = connection.getTable(CloudSpannerDriver.unquoteIdentifier(delete.getTable().getName()));
	List<String> keyCols = table.getKeyColumns().stream()
			.map(x -> CloudSpannerDriver.quoteIdentifier(delete.getTable().getName()) + "."
					+ CloudSpannerDriver.quoteIdentifier(x))
			.collect(Collectors.toList());
	StringBuilder sql = new StringBuilder();
	sql.append("SELECT ").append(String.join(", ", keyCols));
	sql.append("\nFROM ").append(CloudSpannerDriver.quoteIdentifier(delete.getTable().getName()));
	sql.append("\nWHERE ").append(delete.getWhere().toString());

	try
	{
		return (Select) CCJSqlParserUtil.parse(sql.toString());
	}
	catch (JSQLParserException e)
	{
		throw new CloudSpannerSQLException("Could not parse generated SELECT statement: " + sql,
				Code.INVALID_ARGUMENT);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:22,代码来源:DeleteWorker.java

示例6: createUpdateMutation

private Mutation createUpdateMutation(Update update, boolean generateParameterMetaData) throws SQLException
{
	if (update.getTables().isEmpty())
		throw new CloudSpannerSQLException("No table found in update statement", Code.INVALID_ARGUMENT);
	if (update.getTables().size() > 1)
		throw new CloudSpannerSQLException("Update statements for multiple tables at once are not supported",
				Code.INVALID_ARGUMENT);
	String table = unquoteIdentifier(update.getTables().get(0).getFullyQualifiedName());
	getParameterStore().setTable(table);
	List<Expression> expressions = update.getExpressions();
	WriteBuilder builder = Mutation.newUpdateBuilder(table);
	int index = 0;
	for (Column col : update.getColumns())
	{
		String columnName = unquoteIdentifier(col.getFullyQualifiedName());
		expressions.get(index).accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(),
				builder.set(columnName), columnName));
		index++;
	}
	visitUpdateWhereClause(update.getWhere(), builder, generateParameterMetaData);

	return builder.build();
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:23,代码来源:CloudSpannerPreparedStatement.java

示例7: visitDeleteWhereClause

private void visitDeleteWhereClause(Expression where, DeleteKeyBuilder keyBuilder,
		boolean generateParameterMetaData) throws SQLException
{
	if (where != null)
	{
		DMLWhereClauseVisitor whereClauseVisitor = new DMLWhereClauseVisitor(getParameterStore())
		{

			@Override
			protected void visitExpression(Column col, Expression expression)
			{
				String columnName = unquoteIdentifier(col.getFullyQualifiedName());
				keyBuilder.set(columnName);
				expression.accept(
						new KeyBuilderExpressionVisitorAdapter(getParameterStore(), columnName, keyBuilder));
			}

		};
		where.accept(whereClauseVisitor);
		if (!generateParameterMetaData && !whereClauseVisitor.isValid())
		{
			throw new CloudSpannerSQLException(INVALID_WHERE_CLAUSE_DELETE_MESSAGE, Code.INVALID_ARGUMENT);
		}
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:25,代码来源:CloudSpannerPreparedStatement.java

示例8: translateGqlQueryWithLimitCheck

/**
 * Translates a Cloud Datastore gql query string to {@link Query}.
 *
 * <p>Currently, the only way to translate a gql query string to a Query is to run the query
 * against Cloud Datastore and extract the {@code Query} from the response. To prevent reading
 * any data, we set the {@code LIMIT} to 0 but if the gql query already has a limit set, we
 * catch the exception with {@code INVALID_ARGUMENT} error code and retry the translation
 * without the zero limit.
 *
 * <p>Note: This may result in reading actual data from Cloud Datastore but the service has a
 * cap on the number of entities returned for a single rpc request, so this should not be a
 * problem in practice.
 */
@VisibleForTesting
static Query translateGqlQueryWithLimitCheck(String gql, Datastore datastore,
    String namespace) throws DatastoreException {
  String gqlQueryWithZeroLimit = gql + " LIMIT 0";
  try {
    Query translatedQuery = translateGqlQuery(gqlQueryWithZeroLimit, datastore, namespace);
    // Clear the limit that we set.
    return translatedQuery.toBuilder().clearLimit().build();
  } catch (DatastoreException e) {
    // Note: There is no specific error code or message to detect if the query already has a
    // limit, so we just check for INVALID_ARGUMENT and assume that that the query might have
    // a limit already set.
    if (e.getCode() == Code.INVALID_ARGUMENT) {
      LOG.warn("Failed to translate Gql query '{}': {}", gqlQueryWithZeroLimit, e.getMessage());
      LOG.warn("User query might have a limit already set, so trying without zero limit");
      // Retry without the zero limit.
      return translateGqlQuery(gql, datastore, namespace);
    } else {
      throw e;
    }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:35,代码来源:DatastoreV1.java

示例9: setTransactionIsolation

@Override
public void setTransactionIsolation(int level) throws SQLException
{
	checkClosed();
	if (level != Connection.TRANSACTION_SERIALIZABLE)
	{
		throw new CloudSpannerSQLException(
				"Transaction level " + level
						+ " is not supported. Only Connection.TRANSACTION_SERIALIZABLE is supported",
				Code.INVALID_ARGUMENT);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:12,代码来源:CloudSpannerConnection.java

示例10: createArray

static CloudSpannerArray createArray(String typeName, Object[] elements) throws SQLException
{
	for (CloudSpannerDataType type : CloudSpannerDataType.values())
	{
		if (type.getTypeName().equalsIgnoreCase(typeName))
		{
			return new CloudSpannerArray(type, elements);
		}
	}
	throw new CloudSpannerSQLException("Data type " + typeName + " is unknown", Code.INVALID_ARGUMENT);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:11,代码来源:CloudSpannerArray.java

示例11: visitUpdateWhereClause

private void visitUpdateWhereClause(Expression where, WriteBuilder builder, boolean generateParameterMetaData)
		throws SQLException
{
	if (where != null)
	{
		DMLWhereClauseVisitor whereClauseVisitor = new DMLWhereClauseVisitor(getParameterStore())
		{

			@Override
			protected void visitExpression(Column col, Expression expression)
			{
				String columnName = unquoteIdentifier(col.getFullyQualifiedName());
				expression.accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(),
						builder.set(columnName), columnName));
			}

		};
		where.accept(whereClauseVisitor);
		if (!generateParameterMetaData && !whereClauseVisitor.isValid())
		{
			throw new CloudSpannerSQLException(INVALID_WHERE_CLAUSE_UPDATE_MESSAGE, Code.INVALID_ARGUMENT);
		}
	}
	else
	{
		throw new SQLException(INVALID_WHERE_CLAUSE_UPDATE_MESSAGE);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:28,代码来源:CloudSpannerPreparedStatement.java

示例12: execute

@Override
public boolean execute(String sql) throws SQLException
{
	String[] sqlTokens = getTokens(sql);
	CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
	if (custom != null)
		return custom.execute(sqlTokens);
	Statement statement = null;
	boolean ddl = isDDLStatement(sqlTokens);
	if (!ddl)
	{
		try
		{
			statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
		}
		catch (JSQLParserException | TokenMgrError e)
		{
			throw new CloudSpannerSQLException(
					"Error while parsing sql statement " + sql + ": " + e.getLocalizedMessage(),
					Code.INVALID_ARGUMENT, e);
		}
	}
	if (!ddl && statement instanceof Select)
	{
		lastResultSet = executeQuery(sql);
		lastUpdateCount = -1;
		return true;
	}
	else
	{
		lastUpdateCount = executeUpdate(sql);
		lastResultSet = null;
		return false;
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:35,代码来源:CloudSpannerStatement.java

示例13: executeQuery

@Override
public ResultSet executeQuery(String[] sqlTokens) throws SQLException
{
	if (sqlTokens.length == 1)
		return getConnection().getDynamicConnectionProperties(CloudSpannerStatement.this);
	if (sqlTokens.length == 2)
		return getConnection().getDynamicConnectionProperty(CloudSpannerStatement.this, sqlTokens[1]);
	throw new CloudSpannerSQLException(
			"Invalid argument(s) for GET_CONNECTION_PROPERTY. Expected \"GET_CONNECTION_PROPERTY propertyName\" or \"GET_CONNECTION_PROPERTY\"",
			Code.INVALID_ARGUMENT);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:11,代码来源:CloudSpannerStatement.java

示例14: getParameterMetaData

@Override
public CloudSpannerParameterMetaData getParameterMetaData() throws SQLException
{
	// parse the SQL statement without executing it
	try
	{
		if (isDDLStatement())
		{
			throw new CloudSpannerSQLException("Cannot get parameter meta data for DDL statement",
					Code.INVALID_ARGUMENT);
		}
		Statement statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
		if (statement instanceof Insert || statement instanceof Update || statement instanceof Delete)
		{
			// Create mutation, but don't do anything with it. This
			// initializes column names of the parameter store.
			createMutations(sql, false, true);
		}
		else if (statement instanceof Select)
		{
			// Create select builder, but don't do anything with it. This
			// initializes column names of the parameter store.
			createSelectBuilder(statement, sql);
		}
	}
	catch (JSQLParserException | TokenMgrError e)
	{
		throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(),
				Code.INVALID_ARGUMENT, e);
	}
	return new CloudSpannerParameterMetaData(this);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:32,代码来源:CloudSpannerPreparedStatement.java

示例15: executeQuery

@Override
public ResultSet executeQuery() throws SQLException
{
	CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
	if (custom != null && custom.isQuery())
	{
		return custom.executeQuery(sqlTokens);
	}
	Statement statement;
	try
	{
		statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
	}
	catch (JSQLParserException | TokenMgrError e)
	{
		throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(),
				Code.INVALID_ARGUMENT, e);
	}
	if (statement instanceof Select)
	{
		determineForceSingleUseReadContext((Select) statement);
		com.google.cloud.spanner.Statement.Builder builder = createSelectBuilder(statement, sql);
		try (ReadContext context = getReadContext())
		{
			com.google.cloud.spanner.ResultSet rs = context.executeQuery(builder.build());
			return new CloudSpannerResultSet(this, rs);
		}
	}
	throw new CloudSpannerSQLException("SQL statement not suitable for executeQuery. Expected SELECT-statement.",
			Code.INVALID_ARGUMENT);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:31,代码来源:CloudSpannerPreparedStatement.java


注:本文中的com.google.rpc.Code.INVALID_ARGUMENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。