Search in sources :

Example 6 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class PostgresqlUpdateRecognizer method getTableName.

@Override
public String getTableName() {
    StringBuilder sb = new StringBuilder();
    PGOutputVisitor visitor = new PGOutputVisitor(sb) {

        @Override
        public boolean visit(SQLExprTableSource x) {
            printTableSourceExpr(x.getExpr());
            return false;
        }

        @Override
        public boolean visit(SQLJoinTableSource x) {
            throw new NotSupportYetException("not support the syntax of update with join table");
        }
    };
    SQLTableSource tableSource = ast.getTableSource();
    if (tableSource instanceof SQLExprTableSource) {
        visitor.visit((SQLExprTableSource) tableSource);
    } else if (tableSource instanceof SQLJoinTableSource) {
        visitor.visit((SQLJoinTableSource) tableSource);
    } else {
        throw new NotSupportYetException("not support the syntax of update with unknow");
    }
    return sb.toString();
}
Also used : PGOutputVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLJoinTableSource(com.alibaba.druid.sql.ast.statement.SQLJoinTableSource) NotSupportYetException(io.seata.common.exception.NotSupportYetException) SQLTableSource(com.alibaba.druid.sql.ast.statement.SQLTableSource)

Example 7 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class RegistryFactory method buildRegistryService.

private static RegistryService buildRegistryService() {
    RegistryType registryType;
    String registryTypeName = ConfigurationFactory.CURRENT_FILE_INSTANCE.getConfig(ConfigurationKeys.FILE_ROOT_REGISTRY + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR + ConfigurationKeys.FILE_ROOT_TYPE);
    try {
        registryType = RegistryType.getType(registryTypeName);
    } catch (Exception exx) {
        throw new NotSupportYetException("not support registry type: " + registryTypeName);
    }
    if (RegistryType.File == registryType) {
        return FileRegistryServiceImpl.getInstance();
    } else {
        return EnhancedServiceLoader.load(RegistryProvider.class, Objects.requireNonNull(registryType).name()).provide();
    }
}
Also used : NotSupportYetException(io.seata.common.exception.NotSupportYetException) NotSupportYetException(io.seata.common.exception.NotSupportYetException)

Example 8 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class BaseInsertExecutor method getGeneratedKeys.

/**
 * default get generated keys.
 * @return
 * @throws SQLException
 */
public List<Object> getGeneratedKeys() throws SQLException {
    // PK is just auto generated
    ResultSet genKeys = statementProxy.getGeneratedKeys();
    List<Object> pkValues = new ArrayList<>();
    while (genKeys.next()) {
        Object v = genKeys.getObject(1);
        pkValues.add(v);
    }
    if (pkValues.isEmpty()) {
        throw new NotSupportYetException(String.format("not support sql [%s]", sqlRecognizer.getOriginalSQL()));
    }
    try {
        genKeys.beforeFirst();
    } catch (SQLException e) {
        LOGGER.warn("Fail to reset ResultSet cursor. can not get primary key value");
    }
    return pkValues;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) NotSupportYetException(io.seata.common.exception.NotSupportYetException)

Example 9 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class BaseInsertExecutor method getPkValuesBySequence.

/**
 * the modify for test
 *
 * @param expr the expr
 * @return the pk values by sequence
 * @throws SQLException the sql exception
 */
protected List<Object> getPkValuesBySequence(SqlSequenceExpr expr) throws SQLException {
    List<Object> pkValues = null;
    try {
        pkValues = getGeneratedKeys();
    } catch (NotSupportYetException | SQLException ignore) {
    }
    if (!CollectionUtils.isEmpty(pkValues)) {
        return pkValues;
    }
    Sequenceable sequenceable = (Sequenceable) this;
    final String sql = sequenceable.getSequenceSql(expr);
    LOGGER.warn("Fail to get auto-generated keys, use '{}' instead. Be cautious, statement could be polluted. Recommend you set the statement to return generated keys.", sql);
    ResultSet genKeys;
    genKeys = statementProxy.getConnection().createStatement().executeQuery(sql);
    pkValues = new ArrayList<>();
    while (genKeys.next()) {
        Object v = genKeys.getObject(1);
        pkValues.add(v);
    }
    return pkValues;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) NotSupportYetException(io.seata.common.exception.NotSupportYetException) Sequenceable(io.seata.sqlparser.struct.Sequenceable)

Example 10 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class MultiDeleteExecutor method beforeImage.

@Override
protected TableRecords beforeImage() throws SQLException {
    if (sqlRecognizers.size() == 1) {
        DeleteExecutor executor = new DeleteExecutor(statementProxy, statementCallback, sqlRecognizers.get(0));
        return executor.beforeImage();
    }
    final TableMeta tmeta = getTableMeta(sqlRecognizers.get(0).getTableName());
    final ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
    StringBuilder whereCondition = new StringBuilder();
    for (SQLRecognizer recognizer : sqlRecognizers) {
        sqlRecognizer = recognizer;
        SQLDeleteRecognizer visitor = (SQLDeleteRecognizer) recognizer;
        ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder) statementProxy : null;
        if (StringUtils.isNotBlank(visitor.getLimit(parametersHolder, paramAppenderList))) {
            throw new NotSupportYetException("Multi delete SQL with limit condition is not support yet !");
        }
        if (StringUtils.isNotBlank(visitor.getOrderBy())) {
            throw new NotSupportYetException("Multi delete SQL with orderBy condition is not support yet !");
        }
        String whereConditionStr = buildWhereCondition(visitor, paramAppenderList);
        if (StringUtils.isBlank(whereConditionStr)) {
            whereCondition = new StringBuilder();
            paramAppenderList.clear();
            break;
        }
        if (whereCondition.length() > 0) {
            whereCondition.append(" OR ");
        }
        whereCondition.append(whereConditionStr);
    }
    StringBuilder suffix = new StringBuilder(" FROM ").append(getFromTableInSQL());
    if (whereCondition.length() > 0) {
        suffix.append(" WHERE ").append(whereCondition);
    }
    suffix.append(" FOR UPDATE");
    final StringJoiner selectSQLAppender = new StringJoiner(", ", "SELECT ", suffix.toString());
    for (String column : tmeta.getAllColumns().keySet()) {
        selectSQLAppender.add(getColumnNameInSQL(ColumnUtils.addEscape(column, getDbType())));
    }
    return buildTableRecords(tmeta, selectSQLAppender.toString(), paramAppenderList);
}
Also used : ParametersHolder(io.seata.sqlparser.ParametersHolder) SQLRecognizer(io.seata.sqlparser.SQLRecognizer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) SQLDeleteRecognizer(io.seata.sqlparser.SQLDeleteRecognizer) NotSupportYetException(io.seata.common.exception.NotSupportYetException) StringJoiner(java.util.StringJoiner)

Aggregations

NotSupportYetException (io.seata.common.exception.NotSupportYetException)16 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)6 SQLJoinTableSource (com.alibaba.druid.sql.ast.statement.SQLJoinTableSource)6 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)2 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)2 PGOutputVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor)2 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)2 ParametersHolder (io.seata.sqlparser.ParametersHolder)2 SQLRecognizer (io.seata.sqlparser.SQLRecognizer)2 Field (java.lang.reflect.Field)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 StringJoiner (java.util.StringJoiner)2 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)1