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


Java Code类代码示例

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


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

示例1: preparedTransactionAction

import com.google.rpc.Code; //导入依赖的package包/类
private void preparedTransactionAction(String xid, TransactionAction action) throws SQLException
{
	try
	{
		if (connection.isReadOnly())
		{
			throw new CloudSpannerSQLException(
					"Connection is in read-only mode and cannot be used for prepared transactions",
					Code.FAILED_PRECONDITION);
		}
		else
		{
			action.apply(xid);
		}
	}
	finally
	{
		transactionThread = null;
		readOnlyTransaction = null;
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:22,代码来源:CloudSpannerTransaction.java

示例2: CloudSpannerArray

import com.google.rpc.Code; //导入依赖的package包/类
private CloudSpannerArray(CloudSpannerDataType type, Object[] elements) throws SQLException
{
	this.type = type;
	this.data = java.lang.reflect.Array.newInstance(type.getJavaClass(), elements.length);
	try
	{
		System.arraycopy(elements, 0, this.data, 0, elements.length);
	}
	catch (Exception e)
	{
		throw new CloudSpannerSQLException(
				"Could not copy array elements. Make sure the supplied array only contains elements of class "
						+ type.getJavaClass().getName(),
				Code.UNKNOWN, e);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:17,代码来源:CloudSpannerArray.java

示例3: commit

import com.google.rpc.Code; //导入依赖的package包/类
@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,代码行数:23,代码来源:CloudSpannerXAConnection.java

示例4: executeUpdate

import com.google.rpc.Code; //导入依赖的package包/类
@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,代码行数:21,代码来源:CloudSpannerStatement.java

示例5: createSelect

import com.google.rpc.Code; //导入依赖的package包/类
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,代码行数:23,代码来源:DeleteWorker.java

示例6: getKeyBuilder

import com.google.rpc.Code; //导入依赖的package包/类
public Key.Builder getKeyBuilder() throws SQLException
{
	Key.Builder builder = Key.newBuilder();
	for (String key : table.getKeyColumns())
	{
		Object value = keyValues.get(key);
		if (!generateParameterMetaData && value == null)
		{
			throw new CloudSpannerSQLException(
					"No value supplied for key column " + key
							+ ". All key columns must be specified in the WHERE-clause of a DELETE-statement.",
					Code.INVALID_ARGUMENT);
		}
		builder.appendObject(value);
	}
	return builder;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:18,代码来源:DeleteKeyBuilder.java

示例7: createUpdateMutation

import com.google.rpc.Code; //导入依赖的package包/类
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,代码行数:24,代码来源:CloudSpannerPreparedStatement.java

示例8: visitDeleteWhereClause

import com.google.rpc.Code; //导入依赖的package包/类
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,代码行数:26,代码来源:CloudSpannerPreparedStatement.java

示例9: createInsertWithSelectStatement

import com.google.rpc.Code; //导入依赖的package包/类
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,代码行数:19,代码来源:CloudSpannerPreparedStatement.java

示例10: waitForOperations

import com.google.rpc.Code; //导入依赖的package包/类
void waitForOperations() throws SQLException
{
	boolean finished = false;
	while (!finished)
	{
		finished = true;
		for (DdlOperation op : operations)
		{
			op.operation = op.operation.reload();
			if (!op.operation.isDone())
			{
				finished = false;
				break;
			}
		}
		try
		{
			Thread.sleep(1000l);
		}
		catch (InterruptedException e)
		{
			Thread.currentThread().interrupt();
			throw new CloudSpannerSQLException("Wait for DDL-operations interrupted", Code.CANCELLED, e);
		}
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:27,代码来源:RunningOperationsStore.java

示例11: testCreateTableStatement

import com.google.rpc.Code; //导入依赖的package包/类
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,代码行数:17,代码来源:CloudSpannerPreparedStatementTest.java

示例12: createConnection

import com.google.rpc.Code; //导入依赖的package包/类
private Connection createConnection() throws SQLException
{
	try
	{
		Class.forName(CloudSpannerDriver.class.getName());
	}
	catch (ClassNotFoundException e)
	{
		throw new CloudSpannerSQLException("Could not load JDBC driver", Code.UNKNOWN, e);
	}
	StringBuilder url = new StringBuilder("jdbc:cloudspanner://localhost");
	url.append(";Project=").append(projectId);
	url.append(";Instance=").append(instanceId);
	url.append(";Database=").append(DATABASE_ID);
	url.append(";PvtKeyPath=").append(credentialsPath);
	return DriverManager.getConnection(url.toString());
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:18,代码来源:CloudSpannerIT.java

示例13: testXA

import com.google.rpc.Code; //导入依赖的package包/类
public void testXA(String projectId, String instanceId, String database, String pvtKeyPath) throws SQLException
{
	log.info("Starting XA tests");
	CloudSpannerXADataSource ds = new CloudSpannerXADataSource();
	ds.setProjectId(projectId);
	ds.setInstanceId(instanceId);
	ds.setDatabase(database);
	ds.setPvtKeyPath(pvtKeyPath);
	ds.setAllowExtendedMode(true);

	try (CloudSpannerXAConnection xaConnection = ds.getXAConnection())
	{
		testXATransaction(xaConnection, CommitMode.TwoPhase);
		testXARollback(xaConnection);
		deleteTestRow(xaConnection);
		testXARecover(xaConnection);
		deleteTestRow(xaConnection);
	}
	catch (Exception e)
	{
		throw new CloudSpannerSQLException("Exception occurred during XA tests", Code.INTERNAL, e);
	}
	log.info("Finished XA tests");
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:25,代码来源:XATester.java

示例14: put

import com.google.rpc.Code; //导入依赖的package包/类
@Override
public void put(
    Operation operation,
    StreamObserver<com.google.rpc.Status> responseObserver) {
  Instance instance;
  try {
    instance = instances.getFromOperationName(operation.getName());
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  boolean ok = instance.putOperation(operation);
  Code code = ok ? Code.OK : Code.UNAVAILABLE;
  responseObserver.onNext(com.google.rpc.Status.newBuilder()
      .setCode(code.getNumber())
      .build());
  responseObserver.onCompleted();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:20,代码来源:OperationQueueService.java

示例15: poll

import com.google.rpc.Code; //导入依赖的package包/类
@Override
public void poll(
    PollOperationRequest request,
    StreamObserver<com.google.rpc.Status> responseObserver) {
  Instance instance;
  try {
    instance = instances.getFromOperationName(
        request.getOperationName());
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  boolean ok = instance.pollOperation(
      request.getOperationName(),
      request.getStage());
  Code code = ok ? Code.OK : Code.UNAVAILABLE;
  responseObserver.onNext(com.google.rpc.Status.newBuilder()
      .setCode(code.getNumber())
      .build());
  responseObserver.onCompleted();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:23,代码来源:OperationQueueService.java


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