Loading sharding-core/src/main/java/io/shardingjdbc/core/merger/MergeEngine.java +1 −1 Original line number Diff line number Diff line Loading @@ -32,5 +32,5 @@ public interface MergeEngine { * @return merged result set. * @throws SQLException SQL exception */ ResultSetMerger merge() throws SQLException; MergedResult merge() throws SQLException; } sharding-core/src/main/java/io/shardingjdbc/core/merger/ResultSetMerger.java→sharding-core/src/main/java/io/shardingjdbc/core/merger/MergedResult.java +2 −2 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import java.sql.SQLException; import java.util.Calendar; /** * ResultSet merger interface. * Merged result after merge engine. * * @author zhangliang */ public interface ResultSetMerger { public interface MergedResult { /** * iterate next data. Loading sharding-core/src/main/java/io/shardingjdbc/core/merger/QueryResult.java +83 −3 Original line number Diff line number Diff line Loading @@ -17,14 +17,24 @@ package io.shardingjdbc.core.merger; import java.io.InputStream; import java.sql.SQLException; import java.util.Calendar; /** * Query result form database. * * @author zhangliang */ public interface QueryResult extends ResultSetMerger { public interface QueryResult { /** * iterate next data. * * @return has next data * @throws SQLException SQL Exception */ boolean next() throws SQLException; /** * Get column count. Loading @@ -42,4 +52,74 @@ public interface QueryResult extends ResultSetMerger { * @throws SQLException SQL Exception */ String getColumnLabel(int columnIndex) throws SQLException; /** * Get data value. * * @param columnIndex column index * @param type class type of data value * @return data value * @throws SQLException SQL Exception */ Object getValue(int columnIndex, Class<?> type) throws SQLException; /** * Get data value. * * @param columnLabel column label * @param type class type of data value * @return data value * @throws SQLException SQL Exception */ Object getValue(String columnLabel, Class<?> type) throws SQLException; /** * Get calendar value. * * @param columnIndex column index * @param type class type of data value * @param calendar calendar * @return calendar value * @throws SQLException SQL Exception */ Object getCalendarValue(int columnIndex, Class<?> type, Calendar calendar) throws SQLException; /** * Get calendar value. * * @param columnLabel column label * @param type class type of data value * @param calendar calendar * @return calendar value * @throws SQLException SQL Exception */ Object getCalendarValue(String columnLabel, Class<?> type, Calendar calendar) throws SQLException; /** * Get InputStream. * * @param columnIndex column index * @param type class type of data value * @return InputStream * @throws SQLException SQL Exception */ InputStream getInputStream(int columnIndex, String type) throws SQLException; /** * Get InputStream. * * @param columnLabel column label * @param type class type of data value * @return InputStream * @throws SQLException SQL Exception */ InputStream getInputStream(String columnLabel, String type) throws SQLException; /** * Adjust ResultSet is null or not. * * @return ResultSet is null or not * @throws SQLException SQL Exception */ boolean wasNull() throws SQLException; } sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/DALMergeEngine.java +10 −10 Original line number Diff line number Diff line Loading @@ -19,11 +19,11 @@ package io.shardingjdbc.core.merger.dal; import io.shardingjdbc.core.merger.MergeEngine; import io.shardingjdbc.core.merger.QueryResult; import io.shardingjdbc.core.merger.ResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowCreateTableResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowDatabasesResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowOtherResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowTablesResultSetMerger; import io.shardingjdbc.core.merger.MergedResult; import io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResult; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement; Loading @@ -49,16 +49,16 @@ public final class DALMergeEngine implements MergeEngine { private final DALStatement dalStatement; @Override public ResultSetMerger merge() throws SQLException { public MergedResult merge() throws SQLException { if (dalStatement instanceof ShowDatabasesStatement) { return new ShowDatabasesResultSetMerger(); return new ShowDatabasesMergedResult(); } if (dalStatement instanceof ShowTablesStatement) { return new ShowTablesResultSetMerger(shardingRule, queryResults); return new ShowTablesMergedResult(shardingRule, queryResults); } if (dalStatement instanceof ShowCreateTableStatement) { return new ShowCreateTableResultSetMerger(shardingRule, queryResults); return new ShowCreateTableMergedResult(shardingRule, queryResults); } return new ShowOtherResultSetMerger(queryResults.get(0)); return new ShowOtherMergedResult(queryResults.get(0)); } } sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableResultSetMerger.java→sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java +9 −9 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ package io.shardingjdbc.core.merger.dal.show; import com.google.common.base.Optional; import io.shardingjdbc.core.constant.DatabaseType; import io.shardingjdbc.core.merger.QueryResult; import io.shardingjdbc.core.merger.dql.common.AbstractMemoryResultSetMerger; import io.shardingjdbc.core.merger.dql.common.MemoryResultSetRow; import io.shardingjdbc.core.merger.dql.common.MemoryMergedResult; import io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow; import io.shardingjdbc.core.parsing.SQLParsingEngine; import io.shardingjdbc.core.rule.ShardingRule; import io.shardingjdbc.core.rule.TableRule; Loading @@ -34,34 +34,34 @@ import java.util.List; import java.util.Map; /** * Show create table result set merger. * Merged result for show create table. * * @author zhangliang */ public final class ShowCreateTableResultSetMerger extends AbstractMemoryResultSetMerger { public final class ShowCreateTableMergedResult extends MemoryMergedResult { private static final Map<String, Integer> LABEL_AND_INDEX_MAP = new HashMap<>(2, 1); private final ShardingRule shardingRule; private final Iterator<MemoryResultSetRow> memoryResultSetRows; private final Iterator<MemoryQueryResultRow> memoryResultSetRows; static { LABEL_AND_INDEX_MAP.put("Table", 1); LABEL_AND_INDEX_MAP.put("Create Table", 2); } public ShowCreateTableResultSetMerger(final ShardingRule shardingRule, final List<QueryResult> queryResults) throws SQLException { public ShowCreateTableMergedResult(final ShardingRule shardingRule, final List<QueryResult> queryResults) throws SQLException { super(LABEL_AND_INDEX_MAP); this.shardingRule = shardingRule; memoryResultSetRows = init(queryResults); } private Iterator<MemoryResultSetRow> init(final List<QueryResult> queryResults) throws SQLException { List<MemoryResultSetRow> result = new LinkedList<>(); private Iterator<MemoryQueryResultRow> init(final List<QueryResult> queryResults) throws SQLException { List<MemoryQueryResultRow> result = new LinkedList<>(); for (QueryResult each : queryResults) { while (each.next()) { MemoryResultSetRow memoryResultSetRow = new MemoryResultSetRow(each); MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); String tableName = memoryResultSetRow.getCell(1).toString(); Optional<TableRule> tableRule = shardingRule.tryFindTableRuleByActualTable(tableName); if (tableRule.isPresent()) { Loading Loading
sharding-core/src/main/java/io/shardingjdbc/core/merger/MergeEngine.java +1 −1 Original line number Diff line number Diff line Loading @@ -32,5 +32,5 @@ public interface MergeEngine { * @return merged result set. * @throws SQLException SQL exception */ ResultSetMerger merge() throws SQLException; MergedResult merge() throws SQLException; }
sharding-core/src/main/java/io/shardingjdbc/core/merger/ResultSetMerger.java→sharding-core/src/main/java/io/shardingjdbc/core/merger/MergedResult.java +2 −2 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import java.sql.SQLException; import java.util.Calendar; /** * ResultSet merger interface. * Merged result after merge engine. * * @author zhangliang */ public interface ResultSetMerger { public interface MergedResult { /** * iterate next data. Loading
sharding-core/src/main/java/io/shardingjdbc/core/merger/QueryResult.java +83 −3 Original line number Diff line number Diff line Loading @@ -17,14 +17,24 @@ package io.shardingjdbc.core.merger; import java.io.InputStream; import java.sql.SQLException; import java.util.Calendar; /** * Query result form database. * * @author zhangliang */ public interface QueryResult extends ResultSetMerger { public interface QueryResult { /** * iterate next data. * * @return has next data * @throws SQLException SQL Exception */ boolean next() throws SQLException; /** * Get column count. Loading @@ -42,4 +52,74 @@ public interface QueryResult extends ResultSetMerger { * @throws SQLException SQL Exception */ String getColumnLabel(int columnIndex) throws SQLException; /** * Get data value. * * @param columnIndex column index * @param type class type of data value * @return data value * @throws SQLException SQL Exception */ Object getValue(int columnIndex, Class<?> type) throws SQLException; /** * Get data value. * * @param columnLabel column label * @param type class type of data value * @return data value * @throws SQLException SQL Exception */ Object getValue(String columnLabel, Class<?> type) throws SQLException; /** * Get calendar value. * * @param columnIndex column index * @param type class type of data value * @param calendar calendar * @return calendar value * @throws SQLException SQL Exception */ Object getCalendarValue(int columnIndex, Class<?> type, Calendar calendar) throws SQLException; /** * Get calendar value. * * @param columnLabel column label * @param type class type of data value * @param calendar calendar * @return calendar value * @throws SQLException SQL Exception */ Object getCalendarValue(String columnLabel, Class<?> type, Calendar calendar) throws SQLException; /** * Get InputStream. * * @param columnIndex column index * @param type class type of data value * @return InputStream * @throws SQLException SQL Exception */ InputStream getInputStream(int columnIndex, String type) throws SQLException; /** * Get InputStream. * * @param columnLabel column label * @param type class type of data value * @return InputStream * @throws SQLException SQL Exception */ InputStream getInputStream(String columnLabel, String type) throws SQLException; /** * Adjust ResultSet is null or not. * * @return ResultSet is null or not * @throws SQLException SQL Exception */ boolean wasNull() throws SQLException; }
sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/DALMergeEngine.java +10 −10 Original line number Diff line number Diff line Loading @@ -19,11 +19,11 @@ package io.shardingjdbc.core.merger.dal; import io.shardingjdbc.core.merger.MergeEngine; import io.shardingjdbc.core.merger.QueryResult; import io.shardingjdbc.core.merger.ResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowCreateTableResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowDatabasesResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowOtherResultSetMerger; import io.shardingjdbc.core.merger.dal.show.ShowTablesResultSetMerger; import io.shardingjdbc.core.merger.MergedResult; import io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResult; import io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResult; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement; import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement; Loading @@ -49,16 +49,16 @@ public final class DALMergeEngine implements MergeEngine { private final DALStatement dalStatement; @Override public ResultSetMerger merge() throws SQLException { public MergedResult merge() throws SQLException { if (dalStatement instanceof ShowDatabasesStatement) { return new ShowDatabasesResultSetMerger(); return new ShowDatabasesMergedResult(); } if (dalStatement instanceof ShowTablesStatement) { return new ShowTablesResultSetMerger(shardingRule, queryResults); return new ShowTablesMergedResult(shardingRule, queryResults); } if (dalStatement instanceof ShowCreateTableStatement) { return new ShowCreateTableResultSetMerger(shardingRule, queryResults); return new ShowCreateTableMergedResult(shardingRule, queryResults); } return new ShowOtherResultSetMerger(queryResults.get(0)); return new ShowOtherMergedResult(queryResults.get(0)); } }
sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableResultSetMerger.java→sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java +9 −9 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ package io.shardingjdbc.core.merger.dal.show; import com.google.common.base.Optional; import io.shardingjdbc.core.constant.DatabaseType; import io.shardingjdbc.core.merger.QueryResult; import io.shardingjdbc.core.merger.dql.common.AbstractMemoryResultSetMerger; import io.shardingjdbc.core.merger.dql.common.MemoryResultSetRow; import io.shardingjdbc.core.merger.dql.common.MemoryMergedResult; import io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow; import io.shardingjdbc.core.parsing.SQLParsingEngine; import io.shardingjdbc.core.rule.ShardingRule; import io.shardingjdbc.core.rule.TableRule; Loading @@ -34,34 +34,34 @@ import java.util.List; import java.util.Map; /** * Show create table result set merger. * Merged result for show create table. * * @author zhangliang */ public final class ShowCreateTableResultSetMerger extends AbstractMemoryResultSetMerger { public final class ShowCreateTableMergedResult extends MemoryMergedResult { private static final Map<String, Integer> LABEL_AND_INDEX_MAP = new HashMap<>(2, 1); private final ShardingRule shardingRule; private final Iterator<MemoryResultSetRow> memoryResultSetRows; private final Iterator<MemoryQueryResultRow> memoryResultSetRows; static { LABEL_AND_INDEX_MAP.put("Table", 1); LABEL_AND_INDEX_MAP.put("Create Table", 2); } public ShowCreateTableResultSetMerger(final ShardingRule shardingRule, final List<QueryResult> queryResults) throws SQLException { public ShowCreateTableMergedResult(final ShardingRule shardingRule, final List<QueryResult> queryResults) throws SQLException { super(LABEL_AND_INDEX_MAP); this.shardingRule = shardingRule; memoryResultSetRows = init(queryResults); } private Iterator<MemoryResultSetRow> init(final List<QueryResult> queryResults) throws SQLException { List<MemoryResultSetRow> result = new LinkedList<>(); private Iterator<MemoryQueryResultRow> init(final List<QueryResult> queryResults) throws SQLException { List<MemoryQueryResultRow> result = new LinkedList<>(); for (QueryResult each : queryResults) { while (each.next()) { MemoryResultSetRow memoryResultSetRow = new MemoryResultSetRow(each); MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); String tableName = memoryResultSetRow.getCell(1).toString(); Optional<TableRule> tableRule = shardingRule.tryFindTableRuleByActualTable(tableName); if (tableRule.isPresent()) { Loading