-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datasource support #58
Conversation
System.out.println("finally interceptor"); | ||
} | ||
return reVal; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sample 我们补充一个 https://www.sqlite.org/index.html sqllite 或者 http://www.h2database.com/html/main.html H2DB 的实例吧,这样场景更完整些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已补充
int result = st | ||
.executeUpdate("insert into mars (id, gmt_create, gmt_modified, username) \n" | ||
+ "values (100, now(), now(), 'neo')"); | ||
Assert.assertTrue("数据检查", result == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么 comment 就不出现中文了。
if (closed) { | ||
throw new IllegalStateException("BasePreparedStatement has been closed"); | ||
} | ||
if (initialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (initialized) {
return;
}
realPreparedStatement = doPrepareStatement(sql);
for (PreparedParameter preparedParameter : preparedParameters) {
preparedParameter.invoke(realPreparedStatement);
}
initialized = true;
- 这里在并发时,会有重复初始化的风险
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
理论上不会出现并发
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QilongZhang 这里多个线程同时调用这个实例方法就会有并发初始化的问题。 @Xiaoshu-Yan 关注哈。
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>tracer-sofa-boot-starter</artifactId> | ||
</dependency> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
H2 客户端的依赖;还有启动方式也在这里加一下吧
该样例工程使用 H2 内存数据库,并暴露 /create 用于新建一张数据表,用户访问 /create 即可执行创建数据库表 SQL 语句: | ||
```sql | ||
DROP TABLE IF EXISTS TEST; | ||
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
光这个 SQL 语句,用户拿到还是很蒙圈的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个仅仅是为了演示该条sql语句的tracer记录
@QilongZhang 和同步之前的代码冲突了。 |
if (closed) { | ||
throw new IllegalStateException("BasePreparedStatement has been closed"); | ||
} | ||
if (initialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QilongZhang 这里多个线程同时调用这个实例方法就会有并发初始化的问题。 @Xiaoshu-Yan 关注哈。
|
||
import java.util.List; | ||
|
||
import static com.alipay.common.tracer.core.configuration.SofaTracerConfiguration.TRACER_APPNAME_KEY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already import SofaTracerConfiguration
, No need import static field of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ujjboy it need. I try to delete it , but compile error.
applicationName); | ||
} | ||
String applicationName = environment.getProperty(TRACER_APPNAME_KEY); | ||
Assert.isTrue(!StringUtils.isBlank(applicationName), TRACER_APPNAME_KEY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TRACER_APPNAME_KEY
change to SofaTracerConfiguration.TRACER_APPNAME_KEY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
@Test | ||
public void testDataSource() { | ||
Assert.isTrue(dataSource instanceof HikariDataSource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to org.junit.Assert#assertTrue()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
@Test | ||
public void testDataSource() { | ||
Assert.isTrue(dataSource instanceof SmartDataSource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to org.junit.Assert#assertTrue()
|
||
import com.alipay.sofa.tracer.boot.datasource.processor.DataSourceBeanFactoryPostProcessor; | ||
import org.junit.Test; | ||
import org.springframework.util.Assert; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to org.junit.Assert#assertTrue()
createDataSourceProxy(beanFactory, beanName, dataSource, getTomcatJdbcUrlKey()); | ||
} else if (DataSourceUtils.isHikariDataSource(dataSource.getBeanClassName())) { | ||
createDataSourceProxy(beanFactory, beanName, dataSource, getHikariJdbcUrlKey()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems getXXKey()
can move to DataSourceUtils
, too. The code will more simple, like
createDataSourceProxy(beanFactory, beanName, dataSource, getJdbcUrlKeyByDataSource());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has been moved to DataSourceUtils.
sofaTracerSpan.setTag(DataSourceTracerKeys.CONNECTION_ESTABLISH_COST, | ||
(Long) getStateValue(DataSourceTracerKeys.CONNECTION_ESTABLISH_COST)); | ||
} else { | ||
sofaTracerSpan.setStartTime((Long) getStateValue(DataSourceTracerKeys.START_TIME)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是当前时间
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YanXs 已改成当前时间
* @author qilong.zql | ||
* @since 2.2.0 | ||
*/ | ||
public abstract class BasePreparedStatement implements PreparedStatement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类可以去掉,只是trace的话不会修改sql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Xiaoshu-Yan 保留? 主站会使用sql服务端埋点,可以直接依赖开源版扩展。
* @author qilong.zql | ||
* @since 2.2.0 | ||
*/ | ||
public interface SecuritySpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个也删掉吧,没啥用
return originalSql; | ||
} | ||
|
||
class PreparedAbstractStatementInterceptorChainImpl extends AbstractStatementInterceptorChain { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类名去掉Abstract改成 PreparedStatementInterceptorChainImpl
} | ||
|
||
class AbstractStatementInterceptorChainImpl extends AbstractStatementInterceptorChain { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类名也改一下吧 StatementInterceptorChainImpl
} | ||
|
||
public static String resolveDatabaseFromUrl(String url) { | ||
Assert.isTrue(!StringUtils.isBlank(url), "Jdbc url must not be empty!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑一下其他类型数据库,比如
oracle(jdbc:oracle:thin:@localhost:1521:sid)
sqlserver(jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Xiaoshu-Yan 已修改,1、支持 SQLServer 2、支持 oracle SID 格式
@QilongZhang 修改一下前面review |
#53