Create update parser instance.

@param dbType database type
@param shardingRule databases and tables sharding rule
@param lexerEngine lexical analysis engine.
@return Update parser instance
335081
public static AbstractUpdateParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
        switch (dbType) {
            case H2:
            case MySQL:
                return new MySQLUpdateParser(shardingRule, lexerEngine);
            case Oracle:
                return new OracleUpdateParser(shardingRule, lexerEngine);
            case SQLServer:
                return new SQLServerUpdateParser(shardingRule, lexerEngine);
            case PostgreSQL:
                return new PostgreSQLUpdateParser(shardingRule, lexerEngine);
            default:
                throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
        }
    }
874433
public static AbstractUseParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
        switch (dbType) {
            case H2:
            case MySQL:
                return new MySQLUseParser(lexerEngine);
            default:
                throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
        }
    }
1024640
private <S extends Model> String buildUpdateSQL(S model, Map<String, Object> updateColumns) {
        SQLParams sqlParams = SQLParams.builder()
                .model(model)
                .modelClass(this.modelClass)
                .tableName(this.tableName)
                .pkName(this.primaryKeyColumn)
                .updateColumns(updateColumns)
                .conditionSQL(this.conditionSQL)
                .build();

        return Anima.of().dialect().update(sqlParams);
    }
115902
public SQLStatement parse(final boolean useCache, final String sql) {
        Optional<SQLStatement> cachedSQLStatement = getSQLStatementFromCache(useCache, sql);
        if (cachedSQLStatement.isPresent()) {
            return cachedSQLStatement.get();
        }
        SQLStatement result = SQLParserFactory.newInstance(dbType, encryptRule, shardingTableMetaData, sql).parse();
        if (useCache) {
            parsingResultCache.put(sql, result);
        }
        return result;
    }
1240692
public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) throws SQLException {
        List<TableMetaData> actualTableMetaDataList = load(getDataNodeGroups(logicTableName, shardingRule), shardingRule.getShardingDataSourceNames());
        checkUniformed(logicTableName, actualTableMetaDataList);
        return actualTableMetaDataList.iterator().next();
    }
1012443
public SQLAST parse() {
        ParseTree parseTree = SQLParserFactory.newInstance(databaseType, sql).execute().getChild(0);
        if (parseTree instanceof ErrorNode) {
            throw new SQLParsingUnsupportedException(String.format("Unsupported SQL of `%s`", sql));
        }
        Optional<SQLStatementRule> sqlStatementRule = parsingRuleRegistry.findSQLStatementRule(databaseType, parseTree.getClass().getSimpleName());
        if (sqlStatementRule.isPresent()) {
            return new SQLAST((ParserRuleContext) parseTree, sqlStatementRule.get());
        }
        if (parsingRuleRegistry instanceof EncryptParsingRuleRegistry) {
            return new SQLAST((ParserRuleContext) parseTree);
        }
        throw new SQLParsingUnsupportedException(String.format("Unsupported SQL of `%s`", sql));
    }
1113282
def create_parser():
    
    select = create_select()
    scan = create_scan()
    delete = create_delete()
    update = create_update()
    insert = create_insert()
    create = create_create()
    drop = create_drop()
    alter = create_alter()
    dump = create_dump()
    load = create_load()
    base = (
        select | scan | delete | update | insert | create | drop | alter | dump | load
    )
    explain = upkey("explain").setResultsName("action") + Group(
        select | scan | delete | update | insert | create | drop | alter
    )
    analyze = upkey("analyze").setResultsName("action") + Group(
        select | scan | delete | update | insert
    )
    dql = explain | analyze | base
    dql.ignore("--" + restOfLine)
    return dql
1260250
public static TextProtocolBackendHandler newInstance(final String sql, final BackendConnection backendConnection) {
        if (sql.toUpperCase().startsWith(ShardingCTLBackendHandlerFactory.SCTL)) {
            return ShardingCTLBackendHandlerFactory.newInstance(sql, backendConnection);
        }
        // TODO use sql parser engine instead of string compare
        Optional<TransactionOperationType> transactionOperationType = TransactionOperationType.getOperationType(sql.toUpperCase());
        if (transactionOperationType.isPresent()) {
            return new TransactionBackendHandler(transactionOperationType.get(), backendConnection);
        }
        if (sql.toUpperCase().contains(SET_AUTOCOMMIT_1)) {
            return backendConnection.getStateHandler().isInTransaction() ? new TransactionBackendHandler(TransactionOperationType.COMMIT, backendConnection) : new SkipBackendHandler();
        }
        SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
        return SQLType.DAL == sqlStatement.getType() ? createDALBackendHandler(sqlStatement, sql, backendConnection) : new QueryBackendHandler(sql, backendConnection);
    }
782183
@SuppressWarnings("unchecked")
	@Override
	public int update(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createUpdateContext(this, metadata, type, true);
			context.setSqlKind(SqlKind.UPDATE);
			handler.setUpdateParams(context, entity);
			int count = handler.doUpdate(this, context, entity);

			if (count == 0 && MappingUtils.getVersionMappingColumn(type).isPresent()) {
				throw new OptimisticLockException(context);
			}
			return count;
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.UPDATE, e);
		}
	}
925625
public static RoutingEngine newInstance(final ShardingRule shardingRule,
                                            final ShardingDataSourceMetaData shardingDataSourceMetaData, final SQLStatement sqlStatement, final OptimizeResult optimizeResult) {
        Collection<String> tableNames = sqlStatement.getTables().getTableNames();
        if (SQLType.TCL == sqlStatement.getType()) {
            return new DatabaseBroadcastRoutingEngine(shardingRule);
        }
        if (SQLType.DDL == sqlStatement.getType()) {
            return new TableBroadcastRoutingEngine(shardingRule, sqlStatement);
        }
        if (SQLType.DAL == sqlStatement.getType()) {
            return getDALRoutingEngine(shardingRule, sqlStatement, tableNames);
        }
        if (SQLType.DCL == sqlStatement.getType()) {
            return getDCLRoutingEngine(shardingRule, sqlStatement, shardingDataSourceMetaData);
        }
        if (shardingRule.isAllInDefaultDataSource(tableNames)) {
            return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
        }
        if (shardingRule.isAllBroadcastTables(tableNames)) {
            return SQLType.DQL == sqlStatement.getType() ? new UnicastRoutingEngine(shardingRule, tableNames) : new DatabaseBroadcastRoutingEngine(shardingRule);
        }
        if (optimizeResult.getShardingConditions().isAlwaysFalse() || tableNames.isEmpty()) {
            return new UnicastRoutingEngine(shardingRule, tableNames);
        }
        Collection<String> shardingTableNames = shardingRule.getShardingLogicTableNames(tableNames);
        if (1 == shardingTableNames.size() || shardingRule.isAllBindingTables(shardingTableNames)) {
            return new StandardRoutingEngine(sqlStatement, shardingRule, shardingTableNames.iterator().next(), optimizeResult);
        }
        // TODO config for cartesian set
        return new ComplexRoutingEngine(sqlStatement, shardingRule, tableNames, optimizeResult);
    }
150582
public final hqlParser.updateStatement_return updateStatement() throws RecognitionException {
		hqlParser.updateStatement_return retval = new hqlParser.updateStatement_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token UPDATE6=null;
		Token VERSIONED7=null;
		ParserRuleReturnScope optionalFromTokenFromClause8 =null;
		ParserRuleReturnScope setClause9 =null;
		ParserRuleReturnScope whereClause10 =null;

		CommonTree UPDATE6_tree=null;
		CommonTree VERSIONED7_tree=null;

		try {
			// hql.g:165:2: ( UPDATE ^ ( VERSIONED )? optionalFromTokenFromClause setClause ( whereClause )? )
			// hql.g:165:4: UPDATE ^ ( VERSIONED )? optionalFromTokenFromClause setClause ( whereClause )?
			{
			root_0 = (CommonTree)adaptor.nil();


			UPDATE6=(Token)match(input,UPDATE,FOLLOW_UPDATE_in_updateStatement627);
			UPDATE6_tree = (CommonTree)adaptor.create(UPDATE6);
			root_0 = (CommonTree)adaptor.becomeRoot(UPDATE6_tree, root_0);

			// hql.g:165:12: ( VERSIONED )?
			int alt2=2;
			int LA2_0 = input.LA(1);
			if ( (LA2_0==VERSIONED) ) {
				alt2=1;
			}
			switch (alt2) {
				case 1 :
					// hql.g:165:13: VERSIONED
					{
					VERSIONED7=(Token)match(input,VERSIONED,FOLLOW_VERSIONED_in_updateStatement631);
					VERSIONED7_tree = (CommonTree)adaptor.create(VERSIONED7);
					adaptor.addChild(root_0, VERSIONED7_tree);

					}
					break;

			}

			pushFollow(FOLLOW_optionalFromTokenFromClause_in_updateStatement637);
			optionalFromTokenFromClause8=optionalFromTokenFromClause();
			state._fsp--;

			adaptor.addChild(root_0, optionalFromTokenFromClause8.getTree());

			pushFollow(FOLLOW_setClause_in_updateStatement641);
			setClause9=setClause();
			state._fsp--;

			adaptor.addChild(root_0, setClause9.getTree());

			// hql.g:168:3: ( whereClause )?
			int alt3=2;
			int LA3_0 = input.LA(1);
			if ( (LA3_0==WHERE) ) {
				alt3=1;
			}
			switch (alt3) {
				case 1 :
					// hql.g:168:4: whereClause
					{
					pushFollow(FOLLOW_whereClause_in_updateStatement646);
					whereClause10=whereClause();
					state._fsp--;

					adaptor.addChild(root_0, whereClause10.getTree());

					}
					break;

			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1143583
public DatabaseCommunicationEngine newTextProtocolInstance(final LogicSchema logicSchema, final String sql, final BackendConnection backendConnection) {
        return new JDBCDatabaseCommunicationEngine(logicSchema, sql, new JDBCExecuteEngine(backendConnection, new StatementExecutorWrapper(logicSchema)));
    }
981931
function createParser(args) {
  if (!args || !args.file || !args.databaseType) {
    throw new BuildException(
      exceptions.IllegalArgument,
      'The file and the database type must be passed');
  }
  const types = initDatabaseTypeHolder(args.databaseType);
  if (args.editor) {
    const root = getRootElement(readFileContent(args.file));
    return getFileParserByEditor(args.editor, root, types, args.noUserManagement);
  }
  return getParserForSingleFile(args.file, types, args.noUserManagement);
}
754175
public static SQLExecuteCallback<Integer> getPreparedUpdateSQLExecuteCallback(final DatabaseType databaseType, final boolean isExceptionThrown) {
        return new SQLExecuteCallback<Integer>(databaseType, isExceptionThrown) {
            
            @Override
            protected Integer executeSQL(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) throws SQLException {
                return ((PreparedStatement) statement).executeUpdate();
            }
        };
    }
1068192
public static SQLParser newInstance(final DatabaseType databaseType, final String sql) {
        for (ShardingParseEngine each : NewInstanceServiceLoader.newServiceInstances(ShardingParseEngine.class)) {
            if (DatabaseType.valueOf(each.getDatabaseType()) == databaseType) {
                return each.createSQLParser(sql);
            }
        }
        throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType));
    }
531038
public static DatabaseType createDatabaseType(String databaseUrl) {
		String dbTypePart = extractDbType(databaseUrl);
		for (DatabaseType databaseType : databaseTypes) {
			if (databaseType.isDatabaseUrlThisType(databaseUrl, dbTypePart)) {
				return databaseType;
			}
		}
		throw new IllegalArgumentException("Unknown database-type url part '" + dbTypePart + "' in: " + databaseUrl);
	}
1138064
@Override
    public DaoResult updateOrCreate(T bo) {
        if (bo == null) {
            return new DaoResult(DaoOperationStatus.NOT_FOUND);
        }
        try (Connection conn = getConnection(upsertInTransaction)) {
            return updateOrCreate(conn, bo);
        } catch (SQLException e) {
            throw new DaoException(e);
        }
    }