public MasterSlavePreparedStatement(final MasterSlaveConnection connection, final String sql, final int[] columnIndexes) throws SQLException { this.connection = connection; masterSlaveRouter = new MasterSlaveRouter(connection.getMasterSlaveDataSource().getMasterSlaveRule(), connection.getMasterSlaveDataSource().getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)); for (String each : masterSlaveRouter.route(sql)) { PreparedStatement preparedStatement = connection.getConnection(each).prepareStatement(sql, columnIndexes); routedStatements.add(preparedStatement); } }
public MasterSlavePreparedStatement(final MasterSlaveConnection connection, final String sql, final int autoGeneratedKeys) throws SQLException { this.connection = connection; masterSlaveRouter = new MasterSlaveRouter(connection.getMasterSlaveDataSource().getMasterSlaveRule(), connection.getMasterSlaveDataSource().getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)); for (String each : masterSlaveRouter.route(sql)) { PreparedStatement preparedStatement = connection.getConnection(each).prepareStatement(sql, autoGeneratedKeys); routedStatements.add(preparedStatement); } }
public MasterSlavePreparedStatement(final MasterSlaveConnection connection, final String sql, final String[] columnNames) throws SQLException { this.connection = connection; masterSlaveRouter = new MasterSlaveRouter(connection.getMasterSlaveDataSource().getMasterSlaveRule(), connection.getMasterSlaveDataSource().getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)); for (String each : masterSlaveRouter.route(sql)) { PreparedStatement preparedStatement = connection.getConnection(each).prepareStatement(sql, columnNames); routedStatements.add(preparedStatement); } }
public MasterSlavePreparedStatement( final MasterSlaveConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException { this.connection = connection; masterSlaveRouter = new MasterSlaveRouter(connection.getMasterSlaveDataSource().getMasterSlaveRule(), connection.getMasterSlaveDataSource().getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)); for (String each : masterSlaveRouter.route(sql)) { PreparedStatement preparedStatement = connection.getConnection(each).prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); routedStatements.add(preparedStatement); } }
private SQLRouteResult doMasterSlaveRoute(final String sql) { SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge(); String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite(); SQLRouteResult result = new SQLRouteResult(sqlStatement); for (String each : new MasterSlaveRouter( ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) { result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, new ArrayList<>(Collections.singleton(parameters))))); } return result; }
private SQLRouteResult doMasterSlaveRoute(final String sql) { SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge(); String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite(); SQLRouteResult result = new SQLRouteResult(sqlStatement); for (String each : new MasterSlaveRouter( ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) { result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, new ArrayList<>(Collections.singleton(parameters))))); } return result; }
public MasterSlaveStatement(final MasterSlaveConnection connection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { super(Statement.class); this.connection = connection; masterSlaveRouter = new MasterSlaveRouter(connection.getMasterSlaveDataSource().getMasterSlaveRule(), connection.getMasterSlaveDataSource().getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)); this.resultSetType = resultSetType; this.resultSetConcurrency = resultSetConcurrency; this.resultSetHoldability = resultSetHoldability; }
private CommandResponsePackets executeForMasterSlave() throws InterruptedException, ExecutionException, TimeoutException { String dataSourceName = new MasterSlaveRouter(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(sql).iterator().next(); synchronizedFuture = new SynchronizedFuture(1); FutureRegistry.getInstance().put(connectionId, synchronizedFuture); executeSQL(dataSourceName, sql); List<QueryResult> queryResults = synchronizedFuture.get( GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS); FutureRegistry.getInstance().delete(connectionId); List<CommandResponsePackets> packets = new LinkedList<>(); for (QueryResult each : queryResults) { packets.add(((MySQLQueryResult) each).getCommandResponsePackets()); } return merge(new SQLJudgeEngine(sql).judge(), packets, queryResults); }
private PostgreSQLCommandResponsePackets executeForMasterSlave() throws InterruptedException, ExecutionException, TimeoutException { String dataSourceName = new MasterSlaveRouter(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(sql).iterator().next(); synchronizedFuture = new SynchronizedFuture(1); FutureRegistry.getInstance().put(connectionId, synchronizedFuture); executeSQL(dataSourceName, sql); List<QueryResult> queryResults = synchronizedFuture.get( GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS); FutureRegistry.getInstance().delete(connectionId); List<PostgreSQLCommandResponsePackets> packets = new LinkedList<>(); for (QueryResult each : queryResults) { packets.add(((MySQLQueryResult) each).getCommandResponsePackets()); } return merge(new SQLJudgeEngine(sql).judge(), packets, queryResults); }
private SQLRouteResult doMasterSlaveRoute(final String sql) { SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge(); String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite(); SQLRouteResult result = new SQLRouteResult(sqlStatement); for (String each : new MasterSlaveRouter( ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) { result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, Collections.<List<Object>>emptyList()))); } return result; }
private SQLRouteResult doMasterSlaveRoute(final String sql) { SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge(); String rewriteSQL = new MasterSlaveSQLRewriteEngine(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), sql, sqlStatement, logicSchema.getMetaData()).rewrite(); SQLRouteResult result = new SQLRouteResult(sqlStatement); for (String each : new MasterSlaveRouter( ((MasterSlaveSchema) logicSchema).getMasterSlaveRule(), GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(rewriteSQL)) { result.getRouteUnits().add(new RouteUnit(each, new SQLUnit(rewriteSQL, Collections.<List<Object>>emptyList()))); } return result; }