Skip to content

Commit eb59254

Browse files
authored
Merge pull request #29 from sharding-sphere/dev
update from origin
2 parents aa8867e + dc4aa93 commit eb59254

File tree

61 files changed

+1962
-1291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1962
-1291
lines changed

sharding-core/src/main/java/io/shardingsphere/core/event/merger/MergeEvent.java renamed to sharding-core/src/main/java/io/shardingsphere/core/event/connection/ConnectionCloseEvent.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@
1515
* </p>
1616
*/
1717

18-
package io.shardingsphere.core.event.merger;
18+
package io.shardingsphere.core.event.connection;
1919

2020
import io.shardingsphere.core.event.ShardingEvent;
21+
import lombok.Getter;
22+
import lombok.RequiredArgsConstructor;
2123

2224
/**
23-
* Merge event.
24-
*
25-
* @author chenqingyang
25+
* Connection close event.
26+
*
27+
* @author zhangyonglun
2628
*/
27-
public final class MergeEvent extends ShardingEvent {
29+
@RequiredArgsConstructor
30+
@Getter
31+
public final class ConnectionCloseEvent extends ShardingEvent {
32+
33+
private final String dataSource;
34+
35+
private final String url;
2836
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2016-2018 shardingsphere.io.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* </p>
16+
*/
17+
18+
package io.shardingsphere.core.event.connection;
19+
20+
import io.shardingsphere.core.event.ShardingEvent;
21+
import lombok.Getter;
22+
import lombok.RequiredArgsConstructor;
23+
import lombok.Setter;
24+
25+
/**
26+
* Get connection event.
27+
*
28+
* @author zhangyonglun
29+
*/
30+
@RequiredArgsConstructor
31+
@Getter
32+
public final class GetConnectionEvent extends ShardingEvent {
33+
34+
private final String dataSource;
35+
36+
@Setter
37+
private String url = "";
38+
}

sharding-core/src/main/java/io/shardingsphere/core/event/executor/sql/DMLExecutionEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public final class DMLExecutionEvent extends SQLExecutionEvent {
3131

32-
public DMLExecutionEvent(final RouteUnit routeUnit, final List<Object> parameters) {
33-
super(routeUnit, parameters);
32+
public DMLExecutionEvent(final RouteUnit routeUnit, final List<Object> parameters, final String url) {
33+
super(routeUnit, parameters, url);
3434
}
3535
}

sharding-core/src/main/java/io/shardingsphere/core/event/executor/sql/DQLExecutionEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public final class DQLExecutionEvent extends SQLExecutionEvent {
3131

32-
public DQLExecutionEvent(final RouteUnit routeUnit, final List<Object> parameters) {
33-
super(routeUnit, parameters);
32+
public DQLExecutionEvent(final RouteUnit routeUnit, final List<Object> parameters, final String url) {
33+
super(routeUnit, parameters, url);
3434
}
3535
}

sharding-core/src/main/java/io/shardingsphere/core/event/executor/sql/SQLExecutionEvent.java

+2
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public class SQLExecutionEvent extends ShardingEvent {
3737
private final RouteUnit routeUnit;
3838

3939
private final List<Object> parameters;
40+
41+
private final String url;
4042
}

sharding-core/src/main/java/io/shardingsphere/core/event/executor/sql/SQLExecutionEventFactory.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* SQL execution event.
29-
*
29+
*
3030
* @author gaohongtao
3131
* @author maxiaoguang
3232
*/
@@ -35,19 +35,20 @@ public final class SQLExecutionEventFactory {
3535

3636
/**
3737
* Create SQL execution event.
38-
*
39-
* @param sqlType SQL type
38+
*
39+
* @param sqlType SQL type
4040
* @param sqlExecuteUnit SQL execute unit
41-
* @param parameters parameters
41+
* @param parameters parameters
42+
* @param url url
4243
* @return SQL execution event
4344
*/
44-
public static SQLExecutionEvent createEvent(final SQLType sqlType, final SQLExecuteUnit sqlExecuteUnit, final List<Object> parameters) {
45+
public static SQLExecutionEvent createEvent(final SQLType sqlType, final SQLExecuteUnit sqlExecuteUnit, final List<Object> parameters, final String url) {
4546
if (SQLType.DQL == sqlType) {
46-
return new DQLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters);
47+
return new DQLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters, url);
4748
}
4849
if (SQLType.DML == sqlType) {
49-
return new DMLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters);
50+
return new DMLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters, url);
5051
}
51-
return new SQLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters);
52+
return new SQLExecutionEvent(sqlExecuteUnit.getRouteUnit(), parameters, url);
5253
}
5354
}

sharding-core/src/main/java/io/shardingsphere/core/event/routing/RoutingEvent.java renamed to sharding-core/src/main/java/io/shardingsphere/core/event/parsing/ParsingEvent.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
* </p>
1616
*/
1717

18-
package io.shardingsphere.core.event.routing;
18+
package io.shardingsphere.core.event.parsing;
1919

2020
import io.shardingsphere.core.event.ShardingEvent;
2121
import lombok.Getter;
2222
import lombok.RequiredArgsConstructor;
2323

2424
/**
25-
* Routing event.
25+
* Parsing event.
2626
*
27-
* @author chenqingyang
27+
* @author zhangyonglun
2828
*/
2929
@RequiredArgsConstructor
3030
@Getter
31-
public final class RoutingEvent extends ShardingEvent {
31+
public final class ParsingEvent extends ShardingEvent {
3232

3333
private final String sql;
3434
}

sharding-core/src/main/java/io/shardingsphere/core/executor/sql/execute/SQLExecuteCallback.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private T execute0(final SQLExecuteUnit sqlExecuteUnit) throws SQLException {
7373
ExecutorDataMap.setDataMap(dataMap);
7474
List<SQLExecutionEvent> events = new LinkedList<>();
7575
for (List<Object> each : sqlExecuteUnit.getRouteUnit().getSqlUnit().getParameterSets()) {
76-
SQLExecutionEvent event = SQLExecutionEventFactory.createEvent(sqlType, sqlExecuteUnit, each);
76+
SQLExecutionEvent event = SQLExecutionEventFactory.createEvent(sqlType, sqlExecuteUnit, each, sqlExecuteUnit.getStatement().getConnection().getMetaData().getURL());
7777
events.add(event);
7878
shardingEventBus.post(event);
7979
}
@@ -88,8 +88,8 @@ private T execute0(final SQLExecuteUnit sqlExecuteUnit) throws SQLException {
8888
for (SQLExecutionEvent each : events) {
8989
each.setExecuteFailure(ex);
9090
shardingEventBus.post(each);
91-
ExecutorExceptionHandler.handleException(ex);
9291
}
92+
ExecutorExceptionHandler.handleException(ex);
9393
return null;
9494
}
9595
}

sharding-core/src/main/java/io/shardingsphere/core/executor/sql/execute/SQLExecuteTemplate.java

+17-37
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package io.shardingsphere.core.executor.sql.execute;
1919

20-
import io.shardingsphere.core.event.ShardingEventBusInstance;
21-
import io.shardingsphere.core.event.executor.overall.OverallExecutionEvent;
2220
import io.shardingsphere.core.executor.ShardingExecuteEngine;
2321
import io.shardingsphere.core.executor.ShardingExecuteGroup;
2422
import io.shardingsphere.core.executor.sql.SQLExecuteUnit;
@@ -32,7 +30,7 @@
3230

3331
/**
3432
* SQL execute template.
35-
*
33+
*
3634
* @author gaohongtao
3735
* @author zhangliang
3836
* @author maxiaoguang
@@ -47,8 +45,8 @@ public final class SQLExecuteTemplate {
4745
* Execute.
4846
*
4947
* @param sqlExecuteUnits SQL execute units
50-
* @param callback SQL execute callback
51-
* @param <T> class type of return value
48+
* @param callback SQL execute callback
49+
* @param <T> class type of return value
5250
* @return execute result
5351
* @throws SQLException SQL exception
5452
*/
@@ -59,39 +57,30 @@ public <T> List<T> execute(final Collection<? extends SQLExecuteUnit> sqlExecute
5957
/**
6058
* Execute.
6159
*
62-
* @param sqlExecuteUnits SQL execute units
60+
* @param sqlExecuteUnits SQL execute units
6361
* @param firstExecuteCallback first SQL execute callback
64-
* @param callback SQL execute callback
65-
* @param <T> class type of return value
62+
* @param callback SQL execute callback
63+
* @param <T> class type of return value
6664
* @return execute result
6765
* @throws SQLException SQL exception
6866
*/
6967
@SuppressWarnings("unchecked")
7068
public <T> List<T> execute(final Collection<? extends SQLExecuteUnit> sqlExecuteUnits,
7169
final SQLExecuteCallback<T> firstExecuteCallback, final SQLExecuteCallback<T> callback) throws SQLException {
72-
OverallExecutionEvent event = new OverallExecutionEvent(sqlExecuteUnits.size() > 1);
73-
ShardingEventBusInstance.getInstance().post(event);
7470
try {
75-
List<T> result = executeEngine.execute((Collection) sqlExecuteUnits, firstExecuteCallback, callback);
76-
event.setExecuteSuccess();
77-
return result;
78-
// CHECKSTYLE:OFF
79-
} catch (final Exception ex) {
80-
// CHECKSTYLE:ON
81-
event.setExecuteFailure(ex);
71+
return executeEngine.execute((Collection) sqlExecuteUnits, firstExecuteCallback, callback);
72+
} catch (final SQLException ex) {
8273
ExecutorExceptionHandler.handleException(ex);
8374
return Collections.emptyList();
84-
} finally {
85-
ShardingEventBusInstance.getInstance().post(event);
8675
}
8776
}
8877

8978
/**
9079
* Execute group.
9180
*
9281
* @param sqlExecuteGroups SQL execute groups
93-
* @param callback SQL execute callback
94-
* @param <T> class type of return value
82+
* @param callback SQL execute callback
83+
* @param <T> class type of return value
9584
* @return execute result
9685
* @throws SQLException SQL exception
9786
*/
@@ -103,29 +92,20 @@ public <T> List<T> executeGroup(final Collection<ShardingExecuteGroup<? extends
10392
* Execute group.
10493
*
10594
* @param sqlExecuteGroups SQL execute groups
106-
* @param firstCallback first SQL execute callback
107-
* @param callback SQL execute callback
108-
* @param <T> class type of return value
95+
* @param firstCallback first SQL execute callback
96+
* @param callback SQL execute callback
97+
* @param <T> class type of return value
10998
* @return execute result
11099
* @throws SQLException SQL exception
111100
*/
112101
@SuppressWarnings("unchecked")
113-
public <T> List<T> executeGroup(final Collection<ShardingExecuteGroup<? extends SQLExecuteUnit>> sqlExecuteGroups,
114-
final SQLExecuteCallback<T> firstCallback, final SQLExecuteCallback<T> callback) throws SQLException {
115-
OverallExecutionEvent event = new OverallExecutionEvent(sqlExecuteGroups.size() > 1);
116-
ShardingEventBusInstance.getInstance().post(event);
102+
public <T> List<T> executeGroup(final Collection<ShardingExecuteGroup<? extends SQLExecuteUnit>> sqlExecuteGroups,
103+
final SQLExecuteCallback<T> firstCallback, final SQLExecuteCallback<T> callback) throws SQLException {
117104
try {
118-
List<T> result = executeEngine.groupExecute((Collection) sqlExecuteGroups, firstCallback, callback);
119-
event.setExecuteSuccess();
120-
return result;
121-
// CHECKSTYLE:OFF
122-
} catch (final Exception ex) {
123-
// CHECKSTYLE:ON
124-
event.setExecuteFailure(ex);
105+
return executeEngine.groupExecute((Collection) sqlExecuteGroups, firstCallback, callback);
106+
} catch (final SQLException ex) {
125107
ExecutorExceptionHandler.handleException(ex);
126108
return Collections.emptyList();
127-
} finally {
128-
ShardingEventBusInstance.getInstance().post(event);
129109
}
130110
}
131111
}

sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.common.base.Optional;
2121
import io.shardingsphere.core.constant.DatabaseType;
22+
import io.shardingsphere.core.event.ShardingEventBusInstance;
23+
import io.shardingsphere.core.event.parsing.ParsingEvent;
24+
import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
2225
import io.shardingsphere.core.metadata.table.ShardingTableMetaData;
2326
import io.shardingsphere.core.optimizer.OptimizeEngineFactory;
2427
import io.shardingsphere.core.optimizer.condition.ShardingConditions;
@@ -34,7 +37,6 @@
3437
import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement;
3538
import io.shardingsphere.core.parsing.parser.sql.dml.insert.InsertStatement;
3639
import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement;
37-
import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
3840
import io.shardingsphere.core.rewrite.SQLBuilder;
3941
import io.shardingsphere.core.rewrite.SQLRewriteEngine;
4042
import io.shardingsphere.core.routing.RouteUnit;
@@ -60,7 +62,7 @@
6062

6163
/**
6264
* Sharding router with parse.
63-
*
65+
*
6466
* @author zhangiang
6567
* @author maxiaoguang
6668
* @author panjuan
@@ -82,7 +84,20 @@ public final class ParsingSQLRouter implements ShardingRouter {
8284

8385
@Override
8486
public SQLStatement parse(final String logicSQL, final boolean useCache) {
85-
return new SQLParsingEngine(databaseType, logicSQL, shardingRule, shardingTableMetaData).parse(useCache);
87+
ParsingEvent event = new ParsingEvent(logicSQL);
88+
ShardingEventBusInstance.getInstance().post(event);
89+
try {
90+
SQLStatement sqlStatement = new SQLParsingEngine(databaseType, logicSQL, shardingRule, shardingTableMetaData).parse(useCache);
91+
event.setExecuteSuccess();
92+
return sqlStatement;
93+
// CHECKSTYLE:OFF
94+
} catch (final Exception ex) {
95+
// CHECKSTYLE:ON
96+
event.setExecuteFailure(ex);
97+
throw ex;
98+
} finally {
99+
ShardingEventBusInstance.getInstance().post(event);
100+
}
86101
}
87102

88103
@Override

0 commit comments

Comments
 (0)