Skip to content

Commit

Permalink
for #1172, move ot event to spi package
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 24, 2018
1 parent b3d5618 commit c3906e4
Show file tree
Hide file tree
Showing 43 changed files with 106 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.shardingsphere.core.event.ShardingEventBusInstance;
import io.shardingsphere.core.event.executor.SQLExecutionEvent;
import io.shardingsphere.core.event.executor.SQLExecutionEventFactory;
import io.shardingsphere.core.event.executor.SQLExecutionEventHandlerSPILoader;
import io.shardingsphere.core.event.executor.SQLExecutionFinishEvent;
import io.shardingsphere.core.event.executor.SQLExecutionStartEvent;
import io.shardingsphere.core.spi.executor.SQLExecutionEventHandlerSPILoader;
import io.shardingsphere.core.spi.executor.SQLExecutionFinishEvent;
import io.shardingsphere.core.spi.executor.SQLExecutionStartEvent;
import io.shardingsphere.core.executor.ShardingExecuteCallback;
import io.shardingsphere.core.executor.ShardingGroupExecuteCallback;
import io.shardingsphere.core.executor.StatementExecuteUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import com.google.common.base.Optional;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.event.parsing.ParsingEventHandlerSPILoader;
import io.shardingsphere.core.event.parsing.ParsingFinishEvent;
import io.shardingsphere.core.event.parsing.ParsingStartEvent;
import io.shardingsphere.core.spi.parsing.ParsingEventHandlerSPILoader;
import io.shardingsphere.core.spi.parsing.ParsingFinishEvent;
import io.shardingsphere.core.spi.parsing.ParsingStartEvent;
import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import io.shardingsphere.core.metadata.table.ShardingTableMetaData;
import io.shardingsphere.core.optimizer.OptimizeEngineFactory;
Expand Down Expand Up @@ -89,12 +89,11 @@ public SQLStatement parse(final String logicSQL, final boolean useCache) {
ParsingFinishEvent finishEvent = new ParsingFinishEvent();
try {
SQLStatement sqlStatement = new SQLParsingEngine(databaseType, logicSQL, shardingRule, shardingTableMetaData).parse(useCache);
finishEvent.setExecuteSuccess();
return sqlStatement;
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
finishEvent.setExecuteFailure(ex);
finishEvent.setException(ex);
throw ex;
} finally {
ParsingEventHandlerSPILoader.getInstance().handle(finishEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.event;
package io.shardingsphere.core.spi;

/**
* Sharding event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
* </p>
*/

package io.shardingsphere.core.event;
package io.shardingsphere.core.spi;

import lombok.Getter;
import lombok.Setter;

/**
* Sharding finish event.
*
* @author zhangyonglun
*/
public class ShardingFinishEvent extends ShardingEvent {
@Getter
@Setter
public class ShardingFinishEvent {

private Exception exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* </p>
*/

package io.shardingsphere.core.event;
package io.shardingsphere.core.spi;

/**
* Sharding start event.
*
* @author zhangyonglun
*/
public class ShardingStartEvent extends ShardingEvent {
public class ShardingStartEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.close;

import io.shardingsphere.core.event.ShardingEventHandler;
import io.shardingsphere.core.spi.ShardingEventHandler;

/**
* Connection event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.close;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.close;

import io.shardingsphere.core.event.ShardingFinishEvent;
import io.shardingsphere.core.spi.ShardingFinishEvent;

/**
* Close connection finish event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.close;

import io.shardingsphere.core.event.ShardingStartEvent;
import io.shardingsphere.core.spi.ShardingStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.get;

import io.shardingsphere.core.event.ShardingEventHandler;
import io.shardingsphere.core.spi.ShardingEventHandler;

/**
* Connection event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.get;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.get;

import io.shardingsphere.core.event.ShardingFinishEvent;
import io.shardingsphere.core.spi.ShardingFinishEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.connection;
package io.shardingsphere.core.spi.connection.get;

import io.shardingsphere.core.event.ShardingStartEvent;
import io.shardingsphere.core.spi.ShardingStartEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.executor;
package io.shardingsphere.core.spi.executor;

import io.shardingsphere.core.event.ShardingEventHandler;
import io.shardingsphere.core.spi.ShardingEventHandler;

/**
* SQL Execution event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.event.executor;
package io.shardingsphere.core.spi.executor;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.executor;
package io.shardingsphere.core.spi.executor;

import io.shardingsphere.core.event.ShardingFinishEvent;
import io.shardingsphere.core.spi.ShardingFinishEvent;

/**
* SQL execution finish event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.executor;
package io.shardingsphere.core.spi.executor;

import io.shardingsphere.core.event.ShardingStartEvent;
import io.shardingsphere.core.spi.ShardingStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import io.shardingsphere.core.routing.RouteUnit;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.parsing;
package io.shardingsphere.core.spi.parsing;

import io.shardingsphere.core.event.ShardingEventHandler;
import io.shardingsphere.core.spi.ShardingEventHandler;

/**
* Parsing event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.event.parsing;
package io.shardingsphere.core.spi.parsing;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.parsing;
package io.shardingsphere.core.spi.parsing;

import io.shardingsphere.core.event.ShardingFinishEvent;
import io.shardingsphere.core.spi.ShardingFinishEvent;

/**
* Parsing finish event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* </p>
*/

package io.shardingsphere.core.event.parsing;
package io.shardingsphere.core.spi.parsing;

import io.shardingsphere.core.event.ShardingStartEvent;
import io.shardingsphere.core.spi.ShardingStartEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.spi;
package io.shardingsphere.core.spi.root;

/**
* Root invoke handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* </p>
*/

package io.shardingsphere.core.spi;
package io.shardingsphere.core.spi.root;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.ShardingEventBusInstance;
import io.shardingsphere.core.event.connection.CloseConnectionEventHandlerSPILoader;
import io.shardingsphere.core.event.connection.CloseConnectionFinishEvent;
import io.shardingsphere.core.event.connection.CloseConnectionStartEvent;
import io.shardingsphere.core.event.connection.GetConnectionEventHandlerSPILoader;
import io.shardingsphere.core.event.connection.GetConnectionFinishEvent;
import io.shardingsphere.core.event.connection.GetConnectionStartEvent;
import io.shardingsphere.core.spi.connection.close.CloseConnectionEventHandlerSPILoader;
import io.shardingsphere.core.spi.connection.close.CloseConnectionFinishEvent;
import io.shardingsphere.core.spi.connection.close.CloseConnectionStartEvent;
import io.shardingsphere.core.spi.connection.get.GetConnectionEventHandlerSPILoader;
import io.shardingsphere.core.spi.connection.get.GetConnectionFinishEvent;
import io.shardingsphere.core.spi.connection.get.GetConnectionStartEvent;
import io.shardingsphere.core.event.transaction.xa.XATransactionEvent;
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.jdbc.adapter.executor.ForceExecuteCallback;
import io.shardingsphere.core.jdbc.adapter.executor.ForceExecuteTemplate;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaDataFactory;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
import io.shardingsphere.core.spi.RootInvokeHandlerSPILoader;
import io.shardingsphere.core.spi.root.RootInvokeHandlerSPILoader;
import io.shardingsphere.core.transaction.TransactionTypeHolder;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -124,7 +124,8 @@ public final List<Connection> getConnections(final ConnectionMode connectionMode
cachedConnections.putAll(dataSourceName, result);
}
}
handleGetConnectionEvent(result);
GetConnectionEventHandlerSPILoader.getInstance().handle(
new GetConnectionFinishEvent(connections.size(), DataSourceMetaDataFactory.newInstance(databaseType, result.get(0).getMetaData().getURL())));
return result;
}

Expand Down Expand Up @@ -155,12 +156,6 @@ private Connection createConnection(final DataSource dataSource) throws SQLExcep
return result;
}

private void handleGetConnectionEvent(final List<Connection> connections) throws SQLException {
GetConnectionFinishEvent finishEvent = new GetConnectionFinishEvent(connections.size(), DataSourceMetaDataFactory.newInstance(databaseType, connections.get(0).getMetaData().getURL()));
finishEvent.setExecuteSuccess();
GetConnectionEventHandlerSPILoader.getInstance().handle(finishEvent);
}

protected abstract Map<String, DataSource> getDataSourceMap();

protected final void removeCache(final Connection connection) {
Expand Down Expand Up @@ -238,11 +233,10 @@ public void execute(final Entry<String, Connection> cachedConnectionsEntrySet) t
CloseConnectionFinishEvent finishEvent = new CloseConnectionFinishEvent();
try {
connection.close();
finishEvent.setExecuteSuccess();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
finishEvent.setExecuteFailure(ex);
finishEvent.setException(ex);
throw ex;
} finally {
CloseConnectionEventHandlerSPILoader.getInstance().handle(finishEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.shardingsphere.core.jdbc.core.statement.ShardingPreparedStatement;
import io.shardingsphere.core.jdbc.core.statement.ShardingStatement;
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.core.spi.RootInvokeHandlerSPILoader;
import io.shardingsphere.core.spi.root.RootInvokeHandlerSPILoader;
import lombok.Getter;

import javax.sql.DataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.opentracing.Span;
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.tag.Tags;
import io.shardingsphere.core.event.ShardingEventHandler;
import io.shardingsphere.core.event.ShardingFinishEvent;
import io.shardingsphere.core.event.ShardingStartEvent;
import io.shardingsphere.core.spi.ShardingEventHandler;
import io.shardingsphere.core.spi.ShardingFinishEvent;
import io.shardingsphere.core.spi.ShardingStartEvent;
import io.shardingsphere.opentracing.ShardingTracer;
import io.shardingsphere.opentracing.constant.ShardingErrorLogTags;
import io.shardingsphere.opentracing.constant.ShardingTags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.opentracing.Span;
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.tag.Tags;
import io.shardingsphere.core.event.connection.CloseConnectionEventHandler;
import io.shardingsphere.core.event.connection.CloseConnectionFinishEvent;
import io.shardingsphere.core.event.connection.CloseConnectionStartEvent;
import io.shardingsphere.core.spi.connection.close.CloseConnectionEventHandler;
import io.shardingsphere.core.spi.connection.close.CloseConnectionFinishEvent;
import io.shardingsphere.core.spi.connection.close.CloseConnectionStartEvent;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.OpenTracingHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.opentracing.Span;
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.tag.Tags;
import io.shardingsphere.core.event.connection.GetConnectionEventHandler;
import io.shardingsphere.core.event.connection.GetConnectionFinishEvent;
import io.shardingsphere.core.event.connection.GetConnectionStartEvent;
import io.shardingsphere.core.spi.connection.get.GetConnectionEventHandler;
import io.shardingsphere.core.spi.connection.get.GetConnectionFinishEvent;
import io.shardingsphere.core.spi.connection.get.GetConnectionStartEvent;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.OpenTracingHandler;

Expand Down
Loading

0 comments on commit c3906e4

Please sign in to comment.