use of java.sql.SQLNonTransientException in project jaybird by FirebirdSQL.
the class V10Statement method prepare.
@Override
public void prepare(final String statementText) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkTransactionActive(getTransaction());
final StatementState currentState = getState();
if (!isPrepareAllowed(currentState)) {
throw new SQLNonTransientException(String.format("Current statement state (%s) does not allow call to prepare", currentState));
}
resetAll();
final FbWireDatabase db = getDatabase();
if (currentState == StatementState.NEW) {
try {
sendAllocate();
getXdrOut().flush();
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
processAllocateResponse(db.readGenericResponse(getStatementWarningCallback()));
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
}
} else {
checkStatementValid();
}
try {
sendPrepare(statementText);
getXdrOut().flush();
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
processPrepareResponse(db.readGenericResponse(getStatementWarningCallback()));
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
}
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of java.sql.SQLNonTransientException in project cobar by alibaba.
the class ServerConnection method execute.
public void execute(String sql, int type) {
// 状态检查
if (txInterrupted) {
writeErrMessage(ErrorCode.ER_YES, "Transaction error, need to rollback.");
return;
}
// 检查当前使用的DB
String db = this.schema;
if (db == null) {
writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return;
}
// 路由计算
RouteResultset rrs = null;
try {
rrs = ServerRouter.route(schema, sql, this.charset, this);
} catch (SQLNonTransientException e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(sql).toString(), e);
String msg = e.getMessage();
writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return;
}
// session执行
session.execute(rrs, type);
}
use of java.sql.SQLNonTransientException in project cobar by alibaba.
the class ExplainHandler method getRouteResultset.
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
String db = c.getSchema();
if (db == null) {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return null;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return null;
}
try {
return ServerRouter.route(schema, stmt, c.getCharset(), c);
} catch (SQLNonTransientException e) {
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append(stmt).toString(), e);
String msg = e.getMessage();
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
}
use of java.sql.SQLNonTransientException in project Mycat-Server by MyCATApache.
the class DruidInsertParser method parserChildTable.
private RouteResultset parserChildTable(SchemaConfig schema, RouteResultset rrs, String tableName, MySqlInsertStatement insertStmt) throws SQLNonTransientException {
TableConfig tc = schema.getTables().get(tableName);
String joinKey = tc.getJoinKey();
int joinKeyIndex = getJoinKeyIndex(insertStmt.getColumns(), joinKey);
if (joinKeyIndex == -1) {
String inf = "joinKey not provided :" + tc.getJoinKey() + "," + insertStmt;
LOGGER.warn(inf);
throw new SQLNonTransientException(inf);
}
if (isMultiInsert(insertStmt)) {
String msg = "ChildTable multi insert not provided";
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
}
String joinKeyVal = insertStmt.getValues().getValues().get(joinKeyIndex).toString();
String sql = insertStmt.toString();
// try to route by ER parent partion key
RouteResultset theRrs = RouterUtil.routeByERParentKey(null, schema, ServerParse.INSERT, sql, rrs, tc, joinKeyVal);
if (theRrs != null) {
rrs.setFinishedRoute(true);
return theRrs;
}
// route by sql query root parent's datanode
String findRootTBSql = tc.getLocateRTableKeySql().toLowerCase() + joinKeyVal;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("find root parent's node sql " + findRootTBSql);
}
FetchStoreNodeOfChildTableHandler fetchHandler = new FetchStoreNodeOfChildTableHandler();
String dn = fetchHandler.execute(schema.getName(), findRootTBSql, tc.getRootParent().getDataNodes());
if (dn == null) {
throw new SQLNonTransientException("can't find (root) parent sharding node for sql:" + sql);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("found partion node for child table to insert " + dn + " sql :" + sql);
}
return RouterUtil.routeToSingleNode(rrs, dn, sql);
}
use of java.sql.SQLNonTransientException in project Mycat-Server by MyCATApache.
the class DruidInsertParser method statementParse.
/**
* 考虑因素:isChildTable、批量、是否分片
*/
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {
MySqlInsertStatement insert = (MySqlInsertStatement) stmt;
String tableName = StringUtil.removeBackquote(insert.getTableName().getSimpleName()).toUpperCase();
ctx.addTable(tableName);
if (RouterUtil.isNoSharding(schema, tableName)) {
// 整个schema都不分库或者该表不拆分
RouterUtil.routeForTableMeta(rrs, schema, tableName, rrs.getStatement());
rrs.setFinishedRoute(true);
return;
}
TableConfig tc = schema.getTables().get(tableName);
if (tc == null) {
String msg = "can't find table define in schema " + tableName + " schema:" + schema.getName();
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
} else {
// childTable的insert直接在解析过程中完成路由
if (tc.isChildTable()) {
parserChildTable(schema, rrs, tableName, insert);
return;
}
String partitionColumn = tc.getPartitionColumn();
if (partitionColumn != null) {
// 拆分表必须给出column list,否则无法寻找分片字段的值
if (insert.getColumns() == null || insert.getColumns().size() == 0) {
throw new SQLSyntaxErrorException("partition table, insert must provide ColumnList");
}
// 批量insert
if (isMultiInsert(insert)) {
// String msg = "multi insert not provided" ;
// LOGGER.warn(msg);
// throw new SQLNonTransientException(msg);
parserBatchInsert(schema, rrs, partitionColumn, tableName, insert);
} else {
parserSingleInsert(schema, rrs, partitionColumn, tableName, insert);
}
}
}
}
Aggregations