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


Java SQLUpdateStatement类代码示例

本文整理汇总了Java中com.alibaba.druid.sql.ast.statement.SQLUpdateStatement的典型用法代码示例。如果您正苦于以下问题:Java SQLUpdateStatement类的具体用法?Java SQLUpdateStatement怎么用?Java SQLUpdateStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createSQLUpdateStatement

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLUpdateStatement createSQLUpdateStatement() {
    if (JdbcConstants.MYSQL.equals(dbType)) {
        return new MySqlUpdateStatement();    
    }
    
    if (JdbcConstants.ORACLE.equals(dbType)) {
        return new OracleUpdateStatement();    
    }
    
    if (JdbcConstants.POSTGRESQL.equals(dbType)) {
        return new PGUpdateStatement();    
    }
    
    if (JdbcConstants.SQL_SERVER.equals(dbType)) {
        return new SQLServerUpdateStatement();    
    }
    
    return new SQLUpdateStatement();
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:20,代码来源:SQLUpdateBuilderImpl.java

示例2: visit

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public boolean visit(SQLUpdateStatement x) {
    setAliasMap();

    setMode(x, Mode.Update);

    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        String alias = x.getTableSource().getAlias();
        setCurrentTable(ident);

        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();

        Map<String, String> aliasMap = getAliasMap();
        
        aliasMap.put(ident, ident);
        if(alias != null) {
        	aliasMap.put(alias, ident);
        }
    } else {
        x.getTableSource().accept(this);
    }

    accept(x.getItems());
    accept(x.getWhere());

    return false;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:30,代码来源:MycatSchemaStatVisitor.java

示例3: throwExceptionParse

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public void throwExceptionParse(String sql, boolean throwException) throws NoSuchMethodException {
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement sqlStatement = statementList.get(0);
    MySqlUpdateStatement update = (MySqlUpdateStatement) sqlStatement;
    SchemaConfig schemaConfig = mock(SchemaConfig.class);
    Map<String, TableConfig> tables = mock(Map.class);
    TableConfig tableConfig = mock(TableConfig.class);
    String tableName = "hotnews";
    when((schemaConfig).getTables()).thenReturn(tables);
    when(tables.get(tableName)).thenReturn(tableConfig);
    when(tableConfig.getParentTC()).thenReturn(null);
    RouteResultset routeResultset = new RouteResultset(sql, 11);
    Class c = DruidUpdateParser.class;
    Method method = c.getDeclaredMethod("confirmShardColumnNotUpdated", new Class[]{SQLUpdateStatement.class, SchemaConfig.class, String.class, String.class, String.class, RouteResultset.class});
    method.setAccessible(true);
    try {
        method.invoke(c.newInstance(), update, schemaConfig, tableName, "ID", "", routeResultset);
        if (throwException) {
            System.out.println("未抛异常,解析通过则不对!");
            Assert.assertTrue(false);
        } else {
            System.out.println("未抛异常,解析通过,此情况分片字段可能在update语句中但是实际不会被更新");
            Assert.assertTrue(true);
        }
    } catch (Exception e) {
        if (throwException) {
            System.out.println(e.getCause().getClass());
            Assert.assertTrue(e.getCause() instanceof SQLNonTransientException);
            System.out.println("抛异常原因为SQLNonTransientException则正确");
        } else {
            System.out.println("抛异常,需要检查");
            Assert.assertTrue(false);
        }
    }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:37,代码来源:DruidUpdateParserTest.java

示例4: SQLUpdateBuilderImpl

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLUpdateBuilderImpl(String sql, String dbType){
    List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);

    if (stmtList.size() == 0) {
        throw new IllegalArgumentException("not support empty-statement :" + sql);
    }

    if (stmtList.size() > 1) {
        throw new IllegalArgumentException("not support multi-statement :" + sql);
    }

    SQLUpdateStatement stmt = (SQLUpdateStatement) stmtList.get(0);
    this.stmt = stmt;
    this.dbType = dbType;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:16,代码来源:SQLUpdateBuilderImpl.java

示例5: where

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
@Override
public SQLUpdateBuilderImpl where(String expr) {
    SQLUpdateStatement update = getSQLUpdateStatement();

    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    update.setWhere(exprObj);

    return this;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:10,代码来源:SQLUpdateBuilderImpl.java

示例6: whereAnd

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
@Override
public SQLUpdateBuilderImpl whereAnd(String expr) {
    SQLUpdateStatement update = getSQLUpdateStatement();

    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanAnd, exprObj, false, update.getWhere());
    update.setWhere(newCondition);

    return this;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:11,代码来源:SQLUpdateBuilderImpl.java

示例7: whereOr

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
@Override
public SQLUpdateBuilderImpl whereOr(String expr) {
    SQLUpdateStatement update = getSQLUpdateStatement();

    SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
    SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanOr, exprObj, false, update.getWhere());
    update.setWhere(newCondition);

    return this;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:11,代码来源:SQLUpdateBuilderImpl.java

示例8: set

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLUpdateBuilderImpl set(String... items) {
    SQLUpdateStatement update = getSQLUpdateStatement();
    for (String item : items) {
        SQLUpdateSetItem updateSetItem = SQLUtils.toUpdateSetItem(item, dbType);
        update.addItem(updateSetItem);
    }
    
    return this;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:10,代码来源:SQLUpdateBuilderImpl.java

示例9: setValue

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLUpdateBuilderImpl setValue(String column, Object value) {
    SQLUpdateStatement update = getSQLUpdateStatement();
    
    SQLExpr columnExpr = SQLUtils.toSQLExpr(column, dbType);
    SQLExpr valueExpr = toSQLExpr(value, dbType);
    
    SQLUpdateSetItem item = new SQLUpdateSetItem();
    item.setColumn(columnExpr);
    item.setValue(valueExpr);
    update.addItem(item);
    
    return this;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:14,代码来源:SQLUpdateBuilderImpl.java

示例10: updateRecordLog

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
private void updateRecordLog(LogOperate operate,String sql,Object ...args){
    MySqlStatementParser mySqlStatementParser = new MySqlStatementParser(sql);
    SQLUpdateStatement sqlUpdateStatement = mySqlStatementParser.parseUpdateStatement();
    SQLTableSource tableSource = sqlUpdateStatement.getTableSource();
    Assert.notNull(tableSource,"不匹配的操作类型,日志记录失败!");

    List<SQLUpdateSetItem> items = sqlUpdateStatement.getItems();
    JSONObject log = new JSONObject();
    for (int i = 0; i < items.size(); i++) {
        SQLUpdateSetItem sqlUpdateSetItem = items.get(i);
        log.put(sqlUpdateSetItem.getColumn().toString(),args[i]);
    }

    logHandler.handle(operate,sqlUpdateStatement.getTableName().getSimpleName(),sqlUpdateStatement.getTableName().getSimpleName(),log);
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:16,代码来源:LogJdbcTemplate.java

示例11: throwExceptionParse

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public void throwExceptionParse(String sql, boolean throwException) throws NoSuchMethodException {
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement sqlStatement = statementList.get(0);
    MySqlUpdateStatement update = (MySqlUpdateStatement) sqlStatement;
    SchemaConfig schemaConfig = mock(SchemaConfig.class);
    Map<String, TableConfig> tables = mock(Map.class);
    TableConfig tableConfig = mock(TableConfig.class);
    String tableName = "hotnews";
    when((schemaConfig).getTables()).thenReturn(tables);
    when(tables.get(tableName)).thenReturn(tableConfig);
    when(tableConfig.getParentTC()).thenReturn(null);
    RouteResultset routeResultset = new RouteResultset(sql, 11);
    Class c = DruidUpdateParser.class;
    Method method = c.getDeclaredMethod("confirmShardColumnNotUpdated", new Class[]{SQLUpdateStatement.class, SchemaConfig.class, String.class, String.class, String.class, RouteResultset.class});
    method.setAccessible(true);
    try {
        method.invoke(c.newInstance(), update, schemaConfig, tableName, "ID", "", routeResultset);
        if (throwException) {
            System.out.println("Not passed without exception is not correct");
            Assert.assertTrue(false);
        } else {
            System.out.println("Passed without exception. Maybe the partition key exists in update statement,but not update in fact");
            Assert.assertTrue(true);
        }
    } catch (Exception e) {
        if (throwException) {
            System.out.println(e.getCause().getClass());
            Assert.assertTrue(e.getCause() instanceof SQLNonTransientException);
            System.out.println("SQLNonTransientException is expected");
        } else {
            System.out.println("need checked");
            Assert.assertTrue(false);
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:37,代码来源:DruidUpdateParserTest.java

示例12: visit

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
@Override
public boolean visit(SQLUpdateStatement x) {
    setAliasMap();

    setMode(x, Mode.Update);

    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        //
        String alias = x.getTableSource().getAlias();
        setCurrentTable(ident);

        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();

        Map<String, String> aliasMap = getAliasMap();
        
        aliasMap.put(ident, ident);
        //
        if(alias != null) {
        	aliasMap.put(alias, ident);
        }
    } else {
        x.getTableSource().accept(this);
    }

    accept(x.getItems());
    accept(x.getWhere());

    return false;
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:33,代码来源:SqlVisitor.java

示例13: getType

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
@Override
public SqlType getType() {
    if (sqlStatement instanceof SQLSelectStatement)
        return SqlType.SELECT;
    if (sqlStatement instanceof SQLUpdateStatement) return SqlType.UPDATE;

    if (sqlStatement instanceof SQLInsertStatement)

        return SqlType.INSERT;
    if (sqlStatement instanceof SQLDeleteStatement)
        return SqlType.DELETE;
    return null;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:14,代码来源:DruidSqlParser.java

示例14: getStatementType

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLStatementType getStatementType() {
    if (sqlStatement instanceof SQLSelectStatement) {
        return SQLStatementType.SELECT;
    }
    if (sqlStatement instanceof SQLInsertStatement) {
        return SQLStatementType.INSERT;
    }
    if (sqlStatement instanceof SQLUpdateStatement) {
        return SQLStatementType.UPDATE;
    }
    if (sqlStatement instanceof SQLDeleteStatement) {
        return SQLStatementType.DELETE;
    }
    throw new SQLParserException("Unsupported SQL statement: [%s]", sqlStatement);
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:16,代码来源:SQLParseEngine.java

示例15: getSQLVisitor

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
private static SQLASTOutputVisitor getSQLVisitor(DatabaseType databaseType,SQLStatement sqlStatement) {
    if (sqlStatement instanceof SQLSelectStatement) {
        return ClassUtil.newInstance(SQLVisitorRegistry.getSelectVistor(databaseType));
    }
    if (sqlStatement instanceof SQLInsertStatement) {
        return ClassUtil.newInstance(SQLVisitorRegistry.getInsertVistor(databaseType));
    }
    if (sqlStatement instanceof SQLUpdateStatement) {
        return ClassUtil.newInstance(SQLVisitorRegistry.getUpdateVistor(databaseType));
    }
    if (sqlStatement instanceof SQLDeleteStatement) {
        return ClassUtil.newInstance(SQLVisitorRegistry.getDeleteVistor(databaseType));
    }
    throw new SQLParserException("Unsupported SQL statement: [%s]", sqlStatement);
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:16,代码来源:SQLParserFactory.java


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