use of nl.topicus.jdbc.exception.CloudSpannerSQLException in project spanner-jdbc by olavloite.
the class CloudSpannerPooledConnection method fireConnectionError.
/**
* Fires a connection error event, but only if we think the exception is
* fatal.
*
* @param e
* the SQLException to consider
*/
private void fireConnectionError(SQLException e) {
Code code = Code.UNKNOWN;
if (e instanceof CloudSpannerSQLException) {
code = ((CloudSpannerSQLException) e).getCode();
}
if (!isFatalState(code)) {
return;
}
fireConnectionFatalError(e);
}
use of nl.topicus.jdbc.exception.CloudSpannerSQLException in project spanner-jdbc by olavloite.
the class CloudSpannerPooledConnection method getConnection.
/**
* Gets a handle for a client to use. This is a wrapper around the physical
* connection, so the client can call close and it will just return the
* connection to the pool without really closing the physical connection.
*
* <p>
* According to the JDBC 2.0 Optional Package spec (6.2.3), only one client
* may have an active handle to the connection at a time, so if there is a
* previous handle active when this is called, the previous one is forcibly
* closed and its work rolled back.
* </p>
*/
@Override
public ICloudSpannerConnection getConnection() throws SQLException {
if (con == null) {
// Before throwing the exception, let's notify the registered
// listeners about the error
SQLException sqlException = new CloudSpannerSQLException("This PooledConnection has already been closed.", Code.FAILED_PRECONDITION);
fireConnectionFatalError(sqlException);
throw sqlException;
}
// eliminate bad pooled connections.
try {
// Package spec section 6.2.3
if (last != null) {
last.close();
if (!con.getAutoCommit()) {
rollbackAndIgnoreException();
}
con.clearWarnings();
}
/*
* In XA-mode, autocommit is handled in PGXAConnection, because it
* depends on whether an XA-transaction is open or not
*/
if (!isXA) {
con.setAutoCommit(autoCommit);
}
} catch (SQLException sqlException) {
fireConnectionFatalError(sqlException);
throw (SQLException) sqlException.fillInStackTrace();
}
ConnectionHandler handler = new ConnectionHandler(con);
last = handler;
ICloudSpannerConnection proxyCon = (ICloudSpannerConnection) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Connection.class, ICloudSpannerConnection.class }, handler);
last.setProxy(proxyCon);
return proxyCon;
}
use of nl.topicus.jdbc.exception.CloudSpannerSQLException in project spanner-jdbc by olavloite.
the class CloudSpannerResultSet method getArray.
@Override
public Array getArray(int columnIndex) throws SQLException {
if (isNull(columnIndex))
return null;
Type type = resultSet.getColumnType(columnIndex - 1);
if (type.getCode() != Code.ARRAY)
throw new CloudSpannerSQLException("Column with index " + columnIndex + " does not contain an array", com.google.rpc.Code.INVALID_ARGUMENT);
CloudSpannerDataType dataType = CloudSpannerDataType.getType(type.getArrayElementType().getCode());
List<? extends Object> elements = dataType.getArrayElements(resultSet, columnIndex - 1);
return CloudSpannerArray.createArray(dataType, elements);
}
use of nl.topicus.jdbc.exception.CloudSpannerSQLException in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method execute.
@Override
public boolean execute() throws SQLException {
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null)
return custom.execute(sqlTokens);
Statement statement = null;
boolean ddl = isDDLStatement();
if (!ddl) {
try {
statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
} catch (JSQLParserException | TokenMgrError e) {
throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e);
}
}
if (!ddl && statement instanceof Select) {
lastResultSet = executeQuery();
lastUpdateCount = -1;
return true;
} else {
lastUpdateCount = executeUpdate();
lastResultSet = null;
return false;
}
}
use of nl.topicus.jdbc.exception.CloudSpannerSQLException in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method 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, getParameterStore(), getConnection().isAllowExtendedMode(), mode);
}
Aggregations