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


Java Code.FAILED_PRECONDITION属性代码示例

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


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

示例1: preparedTransactionAction

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,代码行数:21,代码来源:CloudSpannerTransaction.java

示例2: checkFree

private void checkFree() throws SQLException
{
	if (data == null)
	{
		throw new CloudSpannerSQLException(FREE_EXCEPTION, Code.FAILED_PRECONDITION);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:7,代码来源:CloudSpannerArray.java

示例3: executeQuery

@Override
public ResultSet executeQuery(String sql) throws SQLException
{
	throw new CloudSpannerSQLException(
			"The executeQuery(String sql)-method may not be called on a PreparedStatement",
			Code.FAILED_PRECONDITION);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:7,代码来源:CloudSpannerPreparedStatement.java

示例4: setReadOnly

@Override
public void setReadOnly(boolean readOnly) throws SQLException
{
	checkClosed();
	if (transaction.isRunning())
		throw new CloudSpannerSQLException(
				"There is currently a transaction running. Commit or rollback the running transaction before changing read-only mode.",
				Code.FAILED_PRECONDITION);
	this.readOnly = readOnly;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:10,代码来源:CloudSpannerConnection.java

示例5: checkClosed

protected void checkClosed() throws SQLException
{
	if (isClosed())
	{
		throw new CloudSpannerSQLException(CONNECTION_CLOSED, Code.FAILED_PRECONDITION);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:7,代码来源:AbstractCloudSpannerConnection.java

示例6: invoke

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
	final String methodName = method.getName();
	// From Object
	if (method.getDeclaringClass().equals(Object.class))
	{
		if (methodName.equals("toString"))
		{
			return "Pooled statement wrapping physical statement " + st;
		}
		if (methodName.equals("hashCode"))
		{
			return System.identityHashCode(proxy);
		}
		if (methodName.equals("equals"))
		{
			return proxy == args[0];
		}
		return method.invoke(st, args);
	}

	// All the rest is from the Statement interface
	if (methodName.equals("isClosed"))
	{
		return st == null || st.isClosed();
	}
	if (methodName.equals("close"))
	{
		if (st == null || st.isClosed())
		{
			return null;
		}
		con = null;
		final Statement oldSt = st;
		st = null;
		oldSt.close();
		return null;
	}
	if (st == null || st.isClosed())
	{
		throw new CloudSpannerSQLException("Statement has been closed.", Code.FAILED_PRECONDITION);
	}
	if (methodName.equals("getConnection"))
	{
		return con.getProxy(); // the proxied connection, not a physical
								// connection
	}

	// Delegate the call to the proxied Statement.
	try
	{
		return method.invoke(st, args);
	}
	catch (final InvocationTargetException ite)
	{
		final Throwable te = ite.getTargetException();
		if (te instanceof SQLException)
		{
			fireConnectionError((SQLException) te); // Tell listeners
													// about exception
													// if it's fatal
		}
		throw te;
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:66,代码来源:CloudSpannerPooledConnection.java

示例7: invoke

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
	if (state != STATE_IDLE)
	{
		String methodName = method.getName();
		if (methodName.equals("commit") || methodName.equals("rollback") || methodName.equals("setSavePoint")
				|| (methodName.equals("setAutoCommit") && (Boolean) args[0]))
		{
			throw new CloudSpannerSQLException(
					"Transaction control methods setAutoCommit(true), commit, rollback and setSavePoint not allowed while an XA transaction is active.",
					Code.FAILED_PRECONDITION);
		}
	}
	try
	{
		/*
		 * If the argument to equals-method is also a wrapper, present
		 * the original unwrapped connection to the underlying equals
		 * method.
		 */
		if (method.getName().equals("equals"))
		{
			Object arg = args[0];
			if (Proxy.isProxyClass(arg.getClass()))
			{
				InvocationHandler h = Proxy.getInvocationHandler(arg);
				if (h instanceof ConnectionHandler)
				{
					// unwrap argument
					args = new Object[] { ((ConnectionHandler) h).con };
				}
			}
		}

		return method.invoke(con, args);
	}
	catch (InvocationTargetException ex)
	{
		throw ex.getTargetException();
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:42,代码来源:CloudSpannerXAConnection.java

示例8: end

/**
 * Preconditions: 1. Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND 2. xid !=
 * null 3. Connection is associated with transaction xid
 *
 * Implementation deficiency preconditions: 1. Flags is not TMSUSPEND
 *
 * Postconditions: 1. connection is disassociated from the transaction.
 * 
 * @see XAResource#end(Xid, int)
 */
@Override
public void end(Xid xid, int flags) throws XAException
{
	if (logger.logDebug())
	{
		debug("ending transaction xid = " + xid);
	}

	// Check preconditions

	if (flags != XAResource.TMSUSPEND && flags != XAResource.TMFAIL && flags != XAResource.TMSUCCESS)
	{
		throw new CloudSpannerXAException("Invalid flags", Code.INVALID_ARGUMENT, XAException.XAER_INVAL);
	}

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

	if (state != STATE_ACTIVE || !currentXid.equals(xid))
	{
		throw new CloudSpannerXAException("tried to call end without corresponding start call",
				Code.FAILED_PRECONDITION, XAException.XAER_PROTO);
	}

	// Check implementation deficiency preconditions
	if (flags == XAResource.TMSUSPEND)
	{
		throw new CloudSpannerXAException("suspend/resume not implemented", Code.UNIMPLEMENTED,
				XAException.XAER_RMERR);
	}

	// We ignore TMFAIL. It's just a hint to the RM. We could roll back
	// immediately
	// if TMFAIL was given.

	// All clear. We don't have any real work to do.
	state = STATE_ENDED;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:50,代码来源:CloudSpannerXAConnection.java

示例9: writeMutations

protected long writeMutations(Mutations mutations) throws SQLException
{
	if (connection.isReadOnly())
	{
		throw new CloudSpannerSQLException("Connection is in read-only mode. Mutations are not allowed",
				Code.FAILED_PRECONDITION);
	}
	if (mutations.isWorker())
	{
		ConversionResult result = mutations.getWorker().call();
		if (result.getException() != null)
		{
			if (result.getException() instanceof SQLException)
				throw (SQLException) result.getException();
			if (result.getException() instanceof SpannerException)
				throw new CloudSpannerSQLException((SpannerException) result.getException());
			throw new CloudSpannerSQLException(result.getException().getMessage(), Code.UNKNOWN,
					result.getException());
		}
	}
	else
	{

		if (connection.getAutoCommit())
		{
			dbClient.readWriteTransaction().run(new TransactionCallable<Void>()
			{

				@Override
				public Void run(TransactionContext transaction) throws Exception
				{
					transaction.buffer(mutations.getMutations());
					return null;
				}
			});
		}
		else
		{
			connection.getTransaction().buffer(mutations.getMutations());
		}
	}
	return mutations.getNumberOfResults();
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:43,代码来源:AbstractCloudSpannerStatement.java

示例10: checkClosed

protected void checkClosed() throws SQLException
{
	if (isClosed())
		throw new CloudSpannerSQLException("Statement is closed", Code.FAILED_PRECONDITION);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:5,代码来源:AbstractCloudSpannerStatement.java

示例11: createMutations

private Mutations createMutations(String sql, boolean forceUpdate, boolean generateParameterMetaData)
		throws SQLException
{
	try
	{
		if (getConnection().isReadOnly())
		{
			throw new CloudSpannerSQLException("The connection is in read-only mode. Mutations are not allowed.",
					Code.FAILED_PRECONDITION);
		}
		if (isDDLStatement())
		{
			throw new CloudSpannerSQLException(
					"Cannot create mutation for DDL statement. Expected INSERT, UPDATE or DELETE",
					Code.INVALID_ARGUMENT);
		}
		Statement statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
		if (statement instanceof Insert)
		{
			Insert insertStatement = (Insert) statement;
			if (generateParameterMetaData || insertStatement.getSelect() == null)
				return new Mutations(createInsertMutation(insertStatement, generateParameterMetaData));
			return new Mutations(createInsertWithSelectStatement(insertStatement, forceUpdate));
		}
		else if (statement instanceof Update)
		{
			Update updateStatement = (Update) statement;
			if (updateStatement.getSelect() != null)
				throw new CloudSpannerSQLException(
						"UPDATE statement using SELECT is not supported. Try to re-write the statement as an INSERT INTO ... SELECT A, B, C FROM TABLE WHERE ... ON DUPLICATE KEY UPDATE",
						Code.INVALID_ARGUMENT);
			if (updateStatement.getTables().size() > 1)
				throw new CloudSpannerSQLException(
						"UPDATE statement using multiple tables is not supported. Try to re-write the statement as an INSERT INTO ... SELECT A, B, C FROM TABLE WHERE ... ON DUPLICATE KEY UPDATE",
						Code.INVALID_ARGUMENT);

			if (generateParameterMetaData || isSingleRowWhereClause(
					getConnection().getTable(unquoteIdentifier(updateStatement.getTables().get(0).getName())),
					updateStatement.getWhere()))
				return new Mutations(createUpdateMutation(updateStatement, generateParameterMetaData));
			// Translate into an 'INSERT ... SELECT ... ON DUPLICATE KEY
			// UPDATE'-statement
			String insertSQL = createInsertSelectOnDuplicateKeyUpdateStatement(updateStatement);
			return createMutations(insertSQL, true, false);
		}
		else if (statement instanceof Delete)
		{
			Delete deleteStatement = (Delete) statement;
			if (generateParameterMetaData || deleteStatement.getWhere() == null
					|| isSingleRowWhereClause(
							getConnection().getTable(unquoteIdentifier(deleteStatement.getTable().getName())),
							deleteStatement.getWhere()))
				return new Mutations(createDeleteMutation(deleteStatement, generateParameterMetaData));
			return new Mutations(createDeleteWorker(deleteStatement));
		}
		else
		{
			throw new CloudSpannerSQLException(
					"Unrecognized or unsupported SQL-statment: Expected one of INSERT, UPDATE or DELETE. Please note that batching of prepared statements is not supported for SELECT-statements.",
					Code.INVALID_ARGUMENT);
		}
	}
	catch (JSQLParserException | IllegalArgumentException | TokenMgrError e)
	{
		throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(),
				Code.INVALID_ARGUMENT, e);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:68,代码来源:CloudSpannerPreparedStatement.java


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