Skip to content

Commit

Permalink
result filter && tenant support
Browse files Browse the repository at this point in the history
  • Loading branch information
kiki authored and kiki committed Jan 10, 2014
1 parent f0bbca5 commit 1f59bba
Show file tree
Hide file tree
Showing 24 changed files with 1,593 additions and 189 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<packaging>jar</packaging>
<name>druid</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alibaba/druid/VERSION.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class VERSION {

public final static int MajorVersion = 1;
public final static int MinorVersion = 0;
public final static int RevisionVersion = 1;
public final static int RevisionVersion = 2;

public static String getVersionNumber() {
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.DruidPasswordCallback;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.util.Utils;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.druid.util.Utils;

/**
* @author wenshao<szujobs@hotmail.com>
Expand Down Expand Up @@ -1314,6 +1314,7 @@ public void setClearFiltersEnable(boolean clearFiltersEnable) {
protected final AtomicLong statementIdSeed = new AtomicLong(20000);
protected final AtomicLong resultSetIdSeed = new AtomicLong(50000);
protected final AtomicLong transactionIdSeed = new AtomicLong(60000);
protected final AtomicLong metaDataIdSeed = new AtomicLong(80000);

public long createConnectionId() {
return connectionIdSeed.incrementAndGet();
Expand All @@ -1323,6 +1324,10 @@ public long createStatementId() {
return statementIdSeed.getAndIncrement();
}

public long createMetaDataId() {
return metaDataIdSeed.getAndIncrement();
}

public long createResultSetId() {
return resultSetIdSeed.getAndIncrement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface DataSourceProxy {

long createResultSetId();

long createMetaDataId();

long createTransactionId();

Properties getConnectProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import com.alibaba.druid.filter.FilterChainImpl;
import com.alibaba.druid.stat.JdbcDataSourceStat;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.util.Utils;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.Utils;

/**
* @author wenshao<szujobs@hotmail.com>
Expand All @@ -58,6 +58,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
private final AtomicLong connectionIdSeed = new AtomicLong(10000);
private final AtomicLong statementIdSeed = new AtomicLong(20000);
private final AtomicLong resultSetIdSeed = new AtomicLong(50000);
private final AtomicLong metaDataIdSeed = new AtomicLong(100000);
private final AtomicLong transactionIdSeed = new AtomicLong(0);

private final JdbcDataSourceStat dataSourceStat;
Expand Down Expand Up @@ -364,6 +365,10 @@ public long createResultSetId() {
return resultSetIdSeed.getAndIncrement();
}

public long createMetaDataId() {
return metaDataIdSeed.getAndIncrement();
}

@Override
public long createTransactionId() {
return transactionIdSeed.getAndIncrement();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.druid.proxy.jdbc;

import java.sql.ResultSetMetaData;

/**
* @author kiki
*/
public interface ResultSetMetaDataProxy extends ResultSetMetaData, WrapperProxy {

ResultSetMetaData getResultSetMetaDataRaw();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.druid.proxy.jdbc;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import com.alibaba.druid.filter.FilterChain;

/**
* @author kiki
*/
public class ResultSetMetaDataProxyImpl extends WrapperProxyImpl implements ResultSetMetaDataProxy {

private final ResultSetMetaData metaData;

private final ResultSetProxy resultSetProxy;

public ResultSetMetaDataProxyImpl(ResultSetMetaData metaData, long id, ResultSetProxy resultSetProxy){
super(metaData, id);
this.metaData = metaData;
this.resultSetProxy = resultSetProxy;
}

@Override
public int getColumnCount() throws SQLException {
return metaData.getColumnCount() - resultSetProxy.getHiddenColumnCount();
}

@Override
public boolean isAutoIncrement(int column) throws SQLException {
return metaData.isAutoIncrement(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isCaseSensitive(int column) throws SQLException {
return metaData.isCaseSensitive(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isSearchable(int column) throws SQLException {
return metaData.isSearchable(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isCurrency(int column) throws SQLException {
return metaData.isCurrency(resultSetProxy.getPhysicalColumn(column));
}

@Override
public int isNullable(int column) throws SQLException {
return metaData.isNullable(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isSigned(int column) throws SQLException {
return metaData.isSigned(resultSetProxy.getPhysicalColumn(column));
}

@Override
public int getColumnDisplaySize(int column) throws SQLException {
return metaData.getColumnDisplaySize(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getColumnLabel(int column) throws SQLException {
return metaData.getColumnLabel(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getColumnName(int column) throws SQLException {
return metaData.getColumnName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getSchemaName(int column) throws SQLException {
return metaData.getSchemaName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public int getPrecision(int column) throws SQLException {
return metaData.getPrecision(resultSetProxy.getPhysicalColumn(column));
}

@Override
public int getScale(int column) throws SQLException {
return metaData.getScale(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getTableName(int column) throws SQLException {
return metaData.getTableName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getCatalogName(int column) throws SQLException {
return metaData.getCatalogName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public int getColumnType(int column) throws SQLException {
return metaData.getColumnType(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getColumnTypeName(int column) throws SQLException {
return metaData.getColumnTypeName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isReadOnly(int column) throws SQLException {
return metaData.isReadOnly(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isWritable(int column) throws SQLException {
return metaData.isWritable(resultSetProxy.getPhysicalColumn(column));
}

@Override
public boolean isDefinitelyWritable(int column) throws SQLException {
return metaData.isDefinitelyWritable(resultSetProxy.getPhysicalColumn(column));
}

@Override
public String getColumnClassName(int column) throws SQLException {
return metaData.getColumnClassName(resultSetProxy.getPhysicalColumn(column));
}

@Override
public ResultSetMetaData getResultSetMetaDataRaw() {
return metaData;
}

@Override
public FilterChain createChain() {
return null;
}

}
35 changes: 25 additions & 10 deletions src/main/java/com/alibaba/druid/proxy/jdbc/ResultSetProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.alibaba.druid.proxy.jdbc;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

import com.alibaba.druid.stat.JdbcSqlStat;

Expand All @@ -29,7 +31,7 @@ public interface ResultSetProxy extends ResultSet, WrapperProxy {
StatementProxy getStatementProxy();

String getSql();

JdbcSqlStat getSqlStat();

int getCursorIndex();
Expand All @@ -41,22 +43,35 @@ public interface ResultSetProxy extends ResultSet, WrapperProxy {
void setConstructNano(long constructNano);

void setConstructNano();

int getCloseCount();

void addReadStringLength(int length);

long getReadStringLength();

void addReadBytesLength(int length);

long getReadBytesLength();

void incrementOpenInputStreamCount();

int getOpenInputStreamCount();

void incrementOpenReaderCount();

int getOpenReaderCount();

int getPhysicalColumn(int logicColumn);

List<Integer> getHiddenColumns();

int getHiddenColumnCount();

void setLogicColumnMap(Map<Integer, Integer> logicColumnMap);

void setPhysicalColumnMap(Map<Integer, Integer> physicalColumnMap);

void setHiddenColumns(List<Integer> hiddenColumns);

}
Loading

0 comments on commit 1f59bba

Please sign in to comment.