提交 bef359cb 编写于 作者: T terrymanu

refactor

上级 02f31869
......@@ -226,13 +226,13 @@ public final class StatementExecutor {
postDMLExecutionEvents();
if (1 == statementExecutorWrappers.size()) {
StatementExecutorWrapper StatementExecutorWrapper = statementExecutorWrappers.iterator().next();
boolean result = false;
boolean result;
try {
result = executor.execute(StatementExecutorWrapper.getStatement(), StatementExecutorWrapper.getSqlExecutionUnit().getSql());
} catch (final SQLException ex) {
postDMLExecutionEventsAfterExecution(StatementExecutorWrapper, EventExecutionType.EXECUTE_FAILURE);
ExecutorExceptionHandler.handleException(ex);
return result;
return false;
} finally {
MetricsContext.stop(context);
}
......@@ -243,13 +243,13 @@ public final class StatementExecutor {
@Override
public Boolean execute(final StatementExecutorWrapper input) throws Exception {
boolean result = false;
boolean result;
try {
result = executor.execute(input.getStatement(), input.getSqlExecutionUnit().getSql());
} catch (final SQLException ex) {
postDMLExecutionEventsAfterExecution(input, EventExecutionType.EXECUTE_FAILURE);
ExecutorExceptionHandler.handleException(ex);
return result;
return false;
}
postDMLExecutionEventsAfterExecution(input, EventExecutionType.EXECUTE_SUCCESS);
return result;
......
......@@ -51,7 +51,7 @@ public abstract class AbstractPreparedStatementAdapter extends AbstractUnsupport
@Getter
private final List<Object> parameters = new ArrayList<>();
protected AbstractPreparedStatementAdapter(final ShardingConnection shardingConnection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException {
protected AbstractPreparedStatementAdapter(final ShardingConnection shardingConnection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) {
super(shardingConnection, resultSetType, resultSetConcurrency, resultSetHoldability);
}
......
......@@ -37,36 +37,36 @@ public final class SelectGroupByShardingDataBasesOnlyTest extends AbstractShardi
@Test
public void assertSelectSum() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectCount() throws SQLException, DatabaseUnitException {
String sql = "SELECT COUNT(order_id) AS `orders_count`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMax() throws SQLException, DatabaseUnitException {
String sql = "SELECT MAX(order_id) AS `max_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMin() throws SQLException, DatabaseUnitException {
String sql = "SELECT MIN(order_id) AS `min_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectAvg() throws SQLException, DatabaseUnitException {
String sql = "SELECT AVG(order_id) AS `orders_avg`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectOrderByDesc() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id` ORDER BY orders_sum DESC";
assertDataSet("integrate/dataset/db/expect/select_groupby/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/db/expect/select_group_by/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
}
}
......@@ -37,36 +37,36 @@ public final class SelectGroupByShardingBothDataBasesAndTablesTest extends Abstr
@Test
public void assertSelectSum() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectCount() throws SQLException, DatabaseUnitException {
String sql = "SELECT COUNT(order_id) AS `orders_count`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMax() throws SQLException, DatabaseUnitException {
String sql = "SELECT MAX(order_id) AS `max_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMin() throws SQLException, DatabaseUnitException {
String sql = "SELECT MIN(order_id) AS `min_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectAvg() throws SQLException, DatabaseUnitException {
String sql = "SELECT AVG(order_id) AS `orders_avg`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectOrderByDesc() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id` ORDER BY orders_sum DESC";
assertDataSet("integrate/dataset/dbtbl/expect/select_groupby/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/dbtbl/expect/select_group_by/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
}
}
......@@ -37,36 +37,36 @@ public final class SelectGroupByShardingTablesOnlyTest extends AbstractShardingT
@Test
public void assertSelectSum() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectSum.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectCount() throws SQLException, DatabaseUnitException {
String sql = "SELECT COUNT(order_id) AS `orders_count`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectCount.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMax() throws SQLException, DatabaseUnitException {
String sql = "SELECT MAX(order_id) AS `max_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectMax.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectMin() throws SQLException, DatabaseUnitException {
String sql = "SELECT MIN(order_id) AS `min_order_id`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectMin.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectAvg() throws SQLException, DatabaseUnitException {
String sql = "SELECT AVG(order_id) AS `orders_avg`, `user_id` FROM `t_order` GROUP BY `user_id`";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectAvg.xml", shardingDataSource.getConnection(), "t_order", sql);
}
@Test
public void assertSelectOrderByDesc() throws SQLException, DatabaseUnitException {
String sql = "SELECT SUM(order_id) AS `orders_sum`, `user_id` FROM `t_order` GROUP BY `user_id` ORDER BY orders_sum DESC";
assertDataSet("integrate/dataset/tbl/expect/select_groupby/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
assertDataSet("integrate/dataset/tbl/expect/select_group_by/SelectOrderByDesc.xml", shardingDataSource.getConnection(), "t_order", sql);
}
}
......@@ -34,6 +34,7 @@ public final class MockResultSet<T> extends AbstractUnsupportedOperationMockResu
private Map<String, T> currentValue;
@SafeVarargs
public MockResultSet(@SuppressWarnings("unchecked") final T... data) {
columnNamesMetaData = new ArrayList<>(1);
List<Map<String, T>> list = new ArrayList<>(data.length);
......
......@@ -44,7 +44,7 @@ public final class MySQLPreparedStatementForOneParameterTest extends AbstractBas
@Parameters(name = "{0}")
public static Collection<Object[]> dataParameters() {
return AbstractBaseParseTest.dataParameters("com/dangdang/ddframe/rdb/sharding/parser/mysql/preparedstatement/one_param/");
return AbstractBaseParseTest.dataParameters("com/dangdang/ddframe/rdb/sharding/parser/mysql/prepared_statement/one_param/");
}
@Test
......
......@@ -42,7 +42,7 @@ public final class MySQLPreparedStatementForTowParametersTest extends AbstractBa
@Parameters(name = "{0}")
public static Collection<Object[]> dataParameters() {
return AbstractBaseParseTest.dataParameters("com/dangdang/ddframe/rdb/sharding/parser/mysql/preparedstatement/two_params/");
return AbstractBaseParseTest.dataParameters("com/dangdang/ddframe/rdb/sharding/parser/mysql/prepared_statement/two_params/");
}
@Test
......
......@@ -50,6 +50,6 @@ public final class OrParseTest extends AbstractBaseParseTest {
@Test
public void assertParse() {
assertSQLParsedResult(SQLParserFactory.create(DatabaseType.MySQL, getSql(), Collections.emptyList(),
Arrays.asList("id", "user_id", "name", "age", "days", "fee", "traveldate", "long")).parse());
Arrays.asList("id", "user_id", "name", "age", "days", "fee", "travel_date", "long")).parse());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<asserts>
<assert id="assertSelectWithOrForOne" sql="select id from travelrecord where fee in (3) or days = 5 or name = 'zhangsan'" expected-sql="SELECT id FROM [Token(travelrecord)] WHERE fee IN (3) OR days = 5 OR name = 'zhangsan'">
<assert id="assertSelectWithOrForOne" sql="select id from travel_record where fee in (3) or days = 5 or name = 'zhangsan'" expected-sql="SELECT id FROM [Token(travel_record)] WHERE fee IN (3) OR days = 5 OR name = 'zhangsan'">
<tables>
<table name="travelrecord" />
<table name="travel_record" />
</tables>
<condition-contexts>
<condition-context>
<condition column-name="name" table-name="travelrecord" operator="EQUAL">
<condition column-name="name" table-name="travel_record" operator="EQUAL">
<value value="zhangsan" type="java.lang.String" />
</condition>
</condition-context>
<condition-context>
<condition column-name="days" table-name="travelrecord" operator="EQUAL">
<condition column-name="days" table-name="travel_record" operator="EQUAL">
<value value="5" type="int" />
</condition>
</condition-context>
<condition-context>
<condition column-name="fee" table-name="travelrecord" operator="IN">
<condition column-name="fee" table-name="travel_record" operator="IN">
<value value="3" type="int" />
</condition>
</condition-context>
</condition-contexts>
</assert>
<assert id="assertSelectWithOrAnd" sql="select id from travelrecord where fee in (3) and ( days = 5 or name = 'zhangsan') and age = 3" expected-sql="SELECT id FROM [Token(travelrecord)] WHERE fee IN (3) AND (days = 5 OR name = 'zhangsan') AND age = 3">
<assert id="assertSelectWithOrAnd" sql="select id from travel_record where fee in (3) and ( days = 5 or name = 'zhangsan') and age = 3" expected-sql="SELECT id FROM [Token(travel_record)] WHERE fee IN (3) AND (days = 5 OR name = 'zhangsan') AND age = 3">
<tables>
<table name="travelrecord" />
<table name="travel_record" />
</tables>
<condition-contexts>
<condition-context>
<condition column-name="name" table-name="travelrecord" operator="EQUAL">
<condition column-name="name" table-name="travel_record" operator="EQUAL">
<value value="zhangsan" type="java.lang.String" />
</condition>
<condition column-name="fee" table-name="travelrecord" operator="IN">
<condition column-name="fee" table-name="travel_record" operator="IN">
<value value="3" type="int" />
</condition>
<condition column-name="age" table-name="travelrecord" operator="EQUAL">
<condition column-name="age" table-name="travel_record" operator="EQUAL">
<value value="3" type="int" />
</condition>
</condition-context>
<condition-context>
<condition column-name="days" table-name="travelrecord" operator="EQUAL">
<condition column-name="days" table-name="travel_record" operator="EQUAL">
<value value="5" type="int" />
</condition>
<condition column-name="fee" table-name="travelrecord" operator="IN">
<condition column-name="fee" table-name="travel_record" operator="IN">
<value value="3" type="int" />
</condition>
<condition column-name="age" table-name="travelrecord" operator="EQUAL">
<condition column-name="age" table-name="travel_record" operator="EQUAL">
<value value="3" type="int" />
</condition>
</condition-context>
</condition-contexts>
</assert>
<assert id="assertSelectWithComplicatedOrExpression" sql="select id from travelrecord where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' and (user_id=2 or days=2 or fee = 0))) and id=2" expected-sql="SELECT id FROM [Token(travelrecord)] WHERE id = 1 AND (fee = 3 OR days = 5 OR traveldate = '2015-05-04 00:00:07.375' AND (user_id = 2 OR days = 2 OR fee = 0)) AND id = 2">
<assert id="assertSelectWithComplicatedOrExpression" sql="select id from travel_record where id = 1 and ( fee=3 or days=5 or (travel_date = '2015-05-04 00:00:07.375' and (user_id=2 or days=2 or fee = 0))) and id=2" expected-sql="SELECT id FROM [Token(travel_record)] WHERE id = 1 AND (fee = 3 OR days = 5 OR travel_date = '2015-05-04 00:00:07.375' AND (user_id = 2 OR days = 2 OR fee = 0)) AND id = 2">
<tables>
<table name="travelrecord" />
<table name="travel_record" />
</tables>
<condition-contexts>
<condition-context>
<condition column-name="days" table-name="travelrecord" operator="EQUAL">
<condition column-name="days" table-name="travel_record" operator="EQUAL">
<value value="5" type="java.lang.Integer" />
</condition>
<condition column-name="id" table-name="travelrecord" operator="EQUAL">
<condition column-name="id" table-name="travel_record" operator="EQUAL">
<value value="1" type="java.lang.Integer" />
<value value="2" type="java.lang.Integer" />
</condition>
</condition-context>
<condition-context>
<condition column-name="fee" table-name="travelrecord" operator="EQUAL">
<condition column-name="fee" table-name="travel_record" operator="EQUAL">
<value value="3" type="java.lang.Integer" />
</condition>
<condition column-name="id" table-name="travelrecord" operator="EQUAL">
<condition column-name="id" table-name="travel_record" operator="EQUAL">
<value value="1" type="java.lang.Integer" />
<value value="2" type="java.lang.Integer" />
</condition>
</condition-context>
<condition-context>
<condition column-name="fee" table-name="travelrecord" operator="EQUAL">
<condition column-name="fee" table-name="travel_record" operator="EQUAL">
<value value="0" type="java.lang.Integer" />
</condition>
<condition column-name="traveldate" table-name="travelrecord" operator="EQUAL">
<condition column-name="travel_date" table-name="travel_record" operator="EQUAL">
<value value="2015-05-04 00:00:07.375" type="java.lang.String" />
</condition>
<condition column-name="id" table-name="travelrecord" operator="EQUAL">
<condition column-name="id" table-name="travel_record" operator="EQUAL">
<value value="1" type="java.lang.Integer" />
<value value="2" type="java.lang.Integer" />
</condition>
</condition-context>
<condition-context>
<condition column-name="days" table-name="travelrecord" operator="EQUAL">
<condition column-name="days" table-name="travel_record" operator="EQUAL">
<value value="2" type="java.lang.Integer" />
</condition>
<condition column-name="traveldate" table-name="travelrecord" operator="EQUAL">
<condition column-name="travel_date" table-name="travel_record" operator="EQUAL">
<value value="2015-05-04 00:00:07.375" type="java.lang.String" />
</condition>
<condition column-name="id" table-name="travelrecord" operator="EQUAL">
<condition column-name="id" table-name="travel_record" operator="EQUAL">
<value value="1" type="java.lang.Integer" />
<value value="2" type="java.lang.Integer" />
</condition>
</condition-context>
<condition-context>
<condition column-name="user_id" table-name="travelrecord" operator="EQUAL">
<condition column-name="user_id" table-name="travel_record" operator="EQUAL">
<value value="2" type="java.lang.Integer" />
</condition>
<condition column-name="traveldate" table-name="travelrecord" operator="EQUAL">
<condition column-name="travel_date" table-name="travel_record" operator="EQUAL">
<value value="2015-05-04 00:00:07.375" type="java.lang.String" />
</condition>
<condition column-name="id" table-name="travelrecord" operator="EQUAL">
<condition column-name="id" table-name="travel_record" operator="EQUAL">
<value value="1" type="java.lang.Integer" />
<value value="2" type="java.lang.Integer" />
</condition>
......@@ -115,9 +115,9 @@
</condition-contexts>
</assert>
<assert id="assertNullConditions" sql="select id from travelrecord where 1=1 or id = 1" expected-sql="SELECT id FROM [Token(travelrecord)] WHERE 1 = 1 OR id = 1">
<assert id="assertNullConditions" sql="select id from travel_record where 1=1 or id = 1" expected-sql="SELECT id FROM [Token(travel_record)] WHERE 1 = 1 OR id = 1">
<tables>
<table name="travelrecord" />
<table name="travel_record" />
</tables>
</assert>
</asserts>
<?xml version="1.0" encoding="UTF-8"?>
<asserts>
<assert id="assertUpdateWithParameter" sql="update `order` set 'state'='STOPED' where order_id = ?" expected-sql="UPDATE [Token(order)] SET 'state' = 'STOPED' WHERE order_id = ?">
<assert id="assertUpdateWithParameter" sql="update `order` set 'state'='STOPPED' where order_id = ?" expected-sql="UPDATE [Token(order)] SET 'state' = 'STOPPED' WHERE order_id = ?">
<tables>
<table name="order" />
</tables>
......
<?xml version="1.0" encoding="UTF-8"?>
<asserts>
<assert id="assertUpdate" sql="update `order` set 'state'='STOPED' where order_id in (1, 2, 3)" expected-sql="UPDATE [Token(order)] SET 'state' = 'STOPED' WHERE order_id IN (1, 2, 3)">
<assert id="assertUpdate" sql="update `order` set 'state'='STOPPED' where order_id in (1, 2, 3)" expected-sql="UPDATE [Token(order)] SET 'state' = 'STOPPED' WHERE order_id IN (1, 2, 3)">
<tables>
<table name="order" />
</tables>
......
......@@ -92,7 +92,7 @@ var charStyle = [
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(246,179,107,1)",
pointHoverBorderColor: "rgba(246,179,107,1)",
pointHoverBorderWidth: 2,
pointHoverBorderWidth: 2
},
{
backgroundColor: "rgba(61,134,198,0.2)",
......@@ -103,6 +103,6 @@ var charStyle = [
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(61,134,198,1)",
pointHoverBorderColor: "rgba(61,134,198,1)",
pointHoverBorderWidth: 2,
pointHoverBorderWidth: 2
}
];
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册