use of io.seata.sqlparser.SQLParsingException in project seata by seata.
the class AntlrDelegatingSQLRecognizerFactory method setClassLoader.
/**
* Only for unit test
*/
void setClassLoader() {
try {
Class<?> recognizerFactoryImplClass = ClassLoader.getSystemClassLoader().loadClass("io.seata.sqlparser.antlr.mysql.AntlrMySQLRecognizerFactory");
Constructor<?> implConstructor = recognizerFactoryImplClass.getDeclaredConstructor();
implConstructor.setAccessible(true);
try {
recognizerFactoryImpl = (SQLRecognizerFactory) implConstructor.newInstance();
} finally {
implConstructor.setAccessible(false);
}
} catch (Exception e) {
throw new SQLParsingException(e);
}
}
use of io.seata.sqlparser.SQLParsingException in project seata by seata.
the class MySQLSelectForUpdateRecognizer method getSelect.
private SQLSelectQueryBlock getSelect() {
SQLSelect select = ast.getSelect();
if (select == null) {
throw new SQLParsingException("should never happen!");
}
SQLSelectQueryBlock selectQueryBlock = select.getQueryBlock();
if (selectQueryBlock == null) {
throw new SQLParsingException("should never happen!");
}
return selectQueryBlock;
}
use of io.seata.sqlparser.SQLParsingException in project seata by seata.
the class OracleInsertRecognizer method getInsertColumns.
@Override
public List<String> getInsertColumns() {
List<SQLExpr> columnSQLExprs = ast.getColumns();
if (columnSQLExprs.isEmpty()) {
// INSERT INTO ta VALUES (...), without fields clarified
return null;
}
List<String> list = new ArrayList<>(columnSQLExprs.size());
for (SQLExpr expr : columnSQLExprs) {
if (expr instanceof SQLIdentifierExpr) {
list.add(((SQLIdentifierExpr) expr).getName());
} else {
throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
}
}
return list;
}
use of io.seata.sqlparser.SQLParsingException in project seata by seata.
the class PostgresqlInsertRecognizer method getInsertRows.
@Override
public List<List<Object>> getInsertRows(Collection<Integer> primaryKeyIndex) {
List<SQLInsertStatement.ValuesClause> valuesClauses = ast.getValuesList();
List<List<Object>> rows = new ArrayList<>(valuesClauses.size());
for (SQLInsertStatement.ValuesClause valuesClause : valuesClauses) {
List<SQLExpr> exprs = valuesClause.getValues();
List<Object> row = new ArrayList<>(exprs.size());
rows.add(row);
for (int i = 0, len = exprs.size(); i < len; i++) {
SQLExpr expr = exprs.get(i);
if (expr instanceof SQLNullExpr) {
row.add(Null.get());
} else if (expr instanceof SQLValuableExpr) {
row.add(((SQLValuableExpr) expr).getValue());
} else if (expr instanceof SQLVariantRefExpr) {
row.add(((SQLVariantRefExpr) expr).getName());
} else if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr sqlMethodInvokeExpr = (SQLMethodInvokeExpr) expr;
String function = sqlMethodInvokeExpr.getMethodName();
if (StringUtils.equalsIgnoreCase(function, "nextval")) {
String sequence = sqlMethodInvokeExpr.getParameters().get(0).toString();
row.add(new SqlSequenceExpr(sequence, function));
} else {
row.add(SqlMethodExpr.get());
}
} else if (expr instanceof SQLSequenceExpr) {
SQLSequenceExpr sequenceExpr = (SQLSequenceExpr) expr;
String sequence = sequenceExpr.getSequence().getSimpleName();
String function = sequenceExpr.getFunction().name;
row.add(new SqlSequenceExpr(sequence, function));
} else if (expr instanceof SQLDefaultExpr) {
row.add(SqlDefaultExpr.get());
} else {
if (primaryKeyIndex.contains(i)) {
throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
}
row.add(NotPlaceholderExpr.get());
}
}
}
return rows;
}
use of io.seata.sqlparser.SQLParsingException in project seata by seata.
the class PostgresqlSelectForUpdateRecognizer method getSelect.
private SQLSelectQueryBlock getSelect() {
SQLSelect select = ast.getSelect();
if (select == null) {
throw new SQLParsingException("should never happen!");
}
SQLSelectQueryBlock selectQueryBlock = select.getQueryBlock();
if (selectQueryBlock == null) {
throw new SQLParsingException("should never happen!");
}
return selectQueryBlock;
}
Aggregations