use of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig in project druid by alibaba.
the class DruidDriver method parseConfig.
public static DataSourceProxyConfig parseConfig(String url, Properties info) throws SQLException {
String restUrl = url.substring(DEFAULT_PREFIX.length());
DataSourceProxyConfig config = new DataSourceProxyConfig();
if (restUrl.startsWith(DRIVER_PREFIX)) {
int pos = restUrl.indexOf(':', DRIVER_PREFIX.length());
String driverText = restUrl.substring(DRIVER_PREFIX.length(), pos);
if (driverText.length() > 0) {
config.setRawDriverClassName(driverText.trim());
}
restUrl = restUrl.substring(pos + 1);
}
if (restUrl.startsWith(FILTERS_PREFIX)) {
int pos = restUrl.indexOf(':', FILTERS_PREFIX.length());
String filtersText = restUrl.substring(FILTERS_PREFIX.length(), pos);
for (String filterItem : filtersText.split(",")) {
FilterManager.loadFilter(config.getFilters(), filterItem);
}
restUrl = restUrl.substring(pos + 1);
}
if (restUrl.startsWith(NAME_PREFIX)) {
int pos = restUrl.indexOf(':', NAME_PREFIX.length());
String name = restUrl.substring(NAME_PREFIX.length(), pos);
config.setName(name);
restUrl = restUrl.substring(pos + 1);
}
if (restUrl.startsWith(JMX_PREFIX)) {
int pos = restUrl.indexOf(':', JMX_PREFIX.length());
String jmxOption = restUrl.substring(JMX_PREFIX.length(), pos);
config.setJmxOption(jmxOption);
restUrl = restUrl.substring(pos + 1);
}
String rawUrl = restUrl;
config.setRawUrl(rawUrl);
if (config.getRawDriverClassName() == null) {
String rawDriverClassname = JdbcUtils.getDriverClassName(rawUrl);
config.setRawDriverClassName(rawDriverClassname);
}
config.setUrl(url);
return config;
}
use of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig in project druid by alibaba.
the class DruidDriver method getDataSource.
/**
* 参数定义: com.alibaba.druid.log.LogFilter=filter com.alibaba.druid.log.LogFilter.p1=prop-value
* com.alibaba.druid.log.LogFilter.p2=prop-value
*
* @param url
* @return
* @throws SQLException
*/
private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
DataSourceProxyImpl dataSource = proxyDataSources.get(url);
if (dataSource == null) {
DataSourceProxyConfig config = parseConfig(url, info);
Driver rawDriver = createDriver(config.getRawDriverClassName());
DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);
{
String property = System.getProperty("druid.filters");
if (property != null && property.length() > 0) {
for (String filterItem : property.split(",")) {
FilterManager.loadFilter(config.getFilters(), filterItem);
}
}
}
{
int dataSourceId = createDataSourceId();
newDataSource.setId(dataSourceId);
for (Filter filter : config.getFilters()) {
filter.init(newDataSource);
}
}
DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
if (oldDataSource == null) {
if (config.isJmxOption()) {
JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
}
}
dataSource = proxyDataSources.get(url);
}
return dataSource;
}
use of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig in project druid by alibaba.
the class CallableStatementProxyImplTest method test_call.
public void test_call() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
DataSourceProxy dataSource = new DataSourceProxyImpl(null, config);
FilterEventAdapter filter = new FilterEventAdapter() {
};
filter.init(dataSource);
config.getFilters().add(filter);
String sql = "CALL P_0(?, ?)";
CallableStatementProxyImpl rawCallStatement = new FakeCallableStatement(new ConnectionProxyImpl(null, null, null, 0), null, sql, 1001);
ConnectionProxy connection = new ConnectionProxyImpl(dataSource, null, new Properties(), 1001);
CallableStatementProxyImpl cstmt = new CallableStatementProxyImpl(connection, rawCallStatement, sql, 2001);
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.registerOutParameter(1, Types.VARCHAR, "VARCHAR");
cstmt.registerOutParameter(1, Types.VARCHAR, 3);
cstmt.registerOutParameter("1", Types.VARCHAR);
cstmt.registerOutParameter("1", Types.VARCHAR, "VARCHAR");
cstmt.registerOutParameter("1", Types.VARCHAR, 3);
cstmt.setBoolean("1", true);
cstmt.setByte("1", (byte) 0);
cstmt.setShort("1", (short) 0);
cstmt.setInt("1", 0);
cstmt.setLong("1", 0);
cstmt.setFloat("1", 0);
cstmt.setDouble("1", 0);
cstmt.setBigDecimal("1", new BigDecimal("111"));
cstmt.setString("1", "X");
cstmt.setURL("1", null);
cstmt.setSQLXML("1", null);
cstmt.setBytes("1", null);
cstmt.setDate("1", null);
cstmt.setDate("1", null, Calendar.getInstance());
cstmt.setTime("1", null);
cstmt.setTime("1", null, Calendar.getInstance());
cstmt.setTimestamp("1", null);
cstmt.setTimestamp("1", null, Calendar.getInstance());
cstmt.setAsciiStream("1", null);
cstmt.setAsciiStream("1", null, 0);
cstmt.setAsciiStream("1", null, 0L);
cstmt.setBinaryStream("1", null);
cstmt.setBinaryStream("1", null, 0);
cstmt.setBinaryStream("1", null, 0L);
cstmt.setObject("1", null);
cstmt.setObject("1", null, Types.VARCHAR);
cstmt.setObject("1", null, Types.VARCHAR, 3);
cstmt.setCharacterStream("1", null);
cstmt.setCharacterStream("1", null, 0);
cstmt.setCharacterStream("1", null, 0L);
cstmt.setNull("1", Types.VARCHAR);
cstmt.setNull("1", Types.VARCHAR, "VARCHAR");
cstmt.setRowId("1", null);
cstmt.setNString("1", null);
cstmt.setNCharacterStream("1", null);
cstmt.setNCharacterStream("1", null, 0);
cstmt.setNClob("1", (NClob) null);
cstmt.setNClob("1", (Reader) null);
cstmt.setNClob("1", (Reader) null, 0);
cstmt.setClob("1", (Clob) null);
cstmt.setClob("1", (Reader) null);
cstmt.setClob("1", (Reader) null, 0);
cstmt.setBlob("1", (Blob) null);
cstmt.setBlob("1", (InputStream) null);
cstmt.setBlob("1", (InputStream) null, 0);
cstmt.setURL(1, null);
cstmt.setSQLXML(1, null);
cstmt.setArray(1, null);
cstmt.setNCharacterStream(1, null);
cstmt.setNCharacterStream(1, null, 0);
cstmt.setNClob(1, (NClob) null);
cstmt.setNClob(1, (Reader) null);
cstmt.setNClob(1, (Reader) null, 0);
cstmt.setNString(1, null);
cstmt.setObject(1, null);
cstmt.setRef(1, null);
cstmt.setRowId(1, null);
cstmt.setUnicodeStream(1, null, 0);
cstmt.getClob(1);
cstmt.getClob("1");
cstmt.cancel();
cstmt.getResultSet();
}
use of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig in project druid by alibaba.
the class ConnectionProxyImplTest method test_connection.
public void test_connection() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
DataSourceProxy dataSource = new DataSourceProxyImpl(null, config);
FilterEventAdapter filter = new FilterEventAdapter() {
};
filter.init(dataSource);
ConnectionProxyImpl rawConnection = new ConnectionProxyImpl(null, null, new Properties(), 0) {
public void setClientInfo(String name, String value) throws SQLClientInfoException {
}
};
ConnectionProxyImpl connection = new ConnectionProxyImpl(dataSource, rawConnection, new Properties(), 1001);
connection.setClientInfo("name", null);
}
use of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig in project druid by alibaba.
the class LogFilterTest method test_logFilter_1.
public void test_logFilter_1() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
Log4jFilter log4jFilter = new Log4jFilter();
log4jFilter.init(dataSource);
config.getFilters().add(log4jFilter);
setLogDisableAll(log4jFilter, true);
CommonsLogFilter commonLogFilter = new CommonsLogFilter() {
@Override
public boolean isDataSourceLogEnabled() {
return false;
}
@Override
public boolean isConnectionLogEnabled() {
return false;
}
@Override
public boolean isStatementLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogErrorEnabled() {
return false;
}
@Override
public boolean isResultSetNextAfterLogEnabled() {
return false;
}
};
commonLogFilter.init(dataSource);
config.getFilters().add(commonLogFilter);
setLogDisableAll(commonLogFilter, true);
executeSQL(dataSource);
}
Aggregations