• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SQLUpdateStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getOwnerTableName

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
/**
     * 从between语句中获取字段所属的表名。
     * 对于容易出现ambiguous的(字段不知道到底属于哪个表),实际应用中必须使用别名来避免歧义
     * @param betweenExpr
     * @param column
     * @return
     */
    private String getOwnerTableName(SQLBetweenExpr betweenExpr,String column) {
        if(tableStats.size() == 1) {//只有一个表,直接返回这一个表名
            return tableStats.keySet().iterator().next().getName();
        } else if(tableStats.size() == 0) {//一个表都没有,返回空串
            return "";
        } else {//多个表名
            for (Column col : columns.keySet())
            {
                if(col.getName().equals(column)) {
                    return col.getTable();
                }
            }
//            for(Column col : columns) {//从columns中找表名
//                if(col.getName().equals(column)) {
//                    return col.getTable();
//                }
//            }

            //前面没找到表名的,自己从parent中解析

            SQLObject parent = betweenExpr.getParent();
            if(parent instanceof SQLBinaryOpExpr)
            {
                parent=parent.getParent();
            }

            if(parent instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
                if(select.getFrom() instanceof SQLJoinTableSource) {//多表连接
                    SQLJoinTableSource joinTableSource = (SQLJoinTableSource)select.getFrom();
                    return joinTableSource.getLeft().toString();//将left作为主表,此处有不严谨处,但也是实在没有办法,如果要准确,字段前带表名或者表的别名即可
                } else if(select.getFrom() instanceof SQLExprTableSource) {//单表
                    return select.getFrom().toString();
                }
            }
            else if(parent instanceof SQLUpdateStatement) {
                SQLUpdateStatement update = (SQLUpdateStatement) parent;
                return update.getTableName().getSimpleName();
            } else if(parent instanceof SQLDeleteStatement) {
                SQLDeleteStatement delete = (SQLDeleteStatement) parent;
                return delete.getTableName().getSimpleName();
            } else {
                
            }
        }
        return "";
    }
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:55,代码来源:MycatSchemaStatVisitor.java


示例17: getSQLUpdateStatement

import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; //导入依赖的package包/类
public SQLUpdateStatement getSQLUpdateStatement() {
    if (stmt == null) {
        stmt = createSQLUpdateStatement();
    }
    return stmt;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:7,代码来源:SQLUpdateBuilderImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Action类代码示例发布时间:2022-05-22
下一篇:
Java Holder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap