Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/alibaba/druid
Browse files Browse the repository at this point in the history
  • Loading branch information
高阳 committed Jul 1, 2013
2 parents de25132 + 97f763c commit 5cbc916
Show file tree
Hide file tree
Showing 20 changed files with 513 additions and 178 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.21</version>
<version>0.2.22-SNAPSHOT</version>

<packaging>jar</packaging>
<name>druid</name>
Expand All @@ -17,7 +17,7 @@
<junit.version>4.11</junit.version>

<gpg.skip>true</gpg.skip>
<javadoc.skip>true</javadoc.skip>
<javadoc.skip>true</javadoc.skip>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.6</jdk.version>
Expand Down Expand Up @@ -88,8 +88,8 @@
<version>3.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>

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 = 0;
public final static int MinorVersion = 2;
public final static int RevisionVersion = 21;
public final static int RevisionVersion = 22;

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 @@ -279,7 +279,6 @@ public Properties loadConfig(String filePath) {
}
}

@SuppressWarnings("resource")
private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
InputStream inStream = null;
File file = new File(filePath);
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/com/alibaba/druid/filter/logging/LogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.FilterEventAdapter;
Expand Down Expand Up @@ -82,22 +83,40 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
protected DataSourceProxy dataSource;

public LogFilter(){
configFromProperties(System.getProperties());
}

public void configFromProperties(Properties properties) {
{
String prop = properties.getProperty("druid.log.conn");
if ("false".equals(prop)) {
connectionLogEnabled = false;
} else if ("true".equals(prop)) {
connectionLogEnabled = true;
}
}
{
String prop = System.getProperty("druid.log.stmt");
if (prop == "false") {
String prop = properties.getProperty("druid.log.stmt");
if ("false".equals(prop)) {
statementLogEnabled = false;
} else if ("true".equals(prop)) {
statementLogEnabled = true;
}
}
{
String prop = System.getProperty("druid.log.rs");
if (prop == "false") {
String prop = properties.getProperty("druid.log.rs");
if ("false".equals(prop)) {
resultSetLogEnabled = false;
} else if ("true".equals(prop)) {
resultSetLogEnabled = true;
}
}
{
String prop = System.getProperty("druid.log.stmt.executableSql");
if (prop == "true") {
String prop = properties.getProperty("druid.log.stmt.executableSql");
if ("true".equals(prop)) {
statementExecutableSqlLogEnable = true;
} else if ("false".equals(prop)) {
statementExecutableSqlLogEnable = false;
}
}
}
Expand Down Expand Up @@ -306,7 +325,7 @@ public boolean isStatementParameterSetLogEnabled() {
public void setStatementParameterSetLogEnabled(boolean statementParameterSetLogEnable) {
this.statementParameterSetLogEnable = statementParameterSetLogEnable;
}

public boolean isStatementParameterClearLogEnable() {
return isStatementLogEnabled() && statementParameterClearLogEnable;
}
Expand Down Expand Up @@ -737,7 +756,7 @@ protected void logParameter(PreparedStatementProxy statement) {
buf.append(stmtId(statement));
buf.append("}");
buf.append(" Parameters : [");

for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) {
JdbcParameter parameter = statement.getParameter(i);
if (i != 0) {
Expand All @@ -746,7 +765,7 @@ protected void logParameter(PreparedStatementProxy statement) {
if (parameter == null) {
continue;
}

int sqlType = parameter.getSqlType();
Object value = parameter.getValue();
switch (sqlType) {
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat

private boolean useGloalDataSourceStat = false;

private boolean mbeanRegistered = false;

public DruidDataSource(){
this(false);
}
Expand Down Expand Up @@ -614,8 +616,7 @@ public void init() throws SQLException {
initedLatch.await();

initedTime = new Date();
ObjectName objectName = DruidDataSourceStatManager.addDataSource(this, this.name);
this.setObjectName(objectName);
registerMbean();

if (connectError != null && poolingCount == 0) {
throw connectError;
Expand Down Expand Up @@ -1222,7 +1223,7 @@ public void close() {
}
}
poolingCount = 0;
DruidDataSourceStatManager.removeDataSource(this);
unregisterMbean();

enable = false;
notEmpty.signalAll();
Expand All @@ -1243,6 +1244,25 @@ public void close() {
}
}

public void registerMbean() {
if (!mbeanRegistered) {
ObjectName objectName = DruidDataSourceStatManager.addDataSource(this, this.name);
this.setObjectName(objectName);
this.mbeanRegistered = true;
}
}

public void unregisterMbean() {
if (mbeanRegistered) {
DruidDataSourceStatManager.removeDataSource(this);
mbeanRegistered = false;
}
}

public boolean isMbeanRegistered() {
return mbeanRegistered;
}

void putLast(DruidConnectionHolder e, long lastActiveTimeMillis) {
e.setLastActiveTimeMillis(lastActiveTimeMillis);
connections[poolingCount++] = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,8 @@ public class MySqlExceptionSorter implements ExceptionSorter {

@Override
public boolean isExceptionFatal(SQLException e) {
int loopCount = 20;

Throwable cause = e;
while (cause != null) {
if (cause instanceof SQLException) {
SQLException sqlException = (SQLException) cause;

if (isExceptionFatal0(sqlException)) {
return true;
}
}
cause = cause.getCause();
if (--loopCount < 0) {
break;
}
}
return false;
}

private boolean isExceptionFatal0(SQLException e) {
String sqlState = e.getSQLState();
final int errorCode = Math.abs(e.getErrorCode());
final int errorCode = e.getErrorCode();

if (sqlState != null && sqlState.startsWith("08")) {
return true;
Expand All @@ -71,20 +51,31 @@ private boolean isExceptionFatal0(SQLException e) {
case 1037: // ER_OUTOFMEMORY
case 1038: // ER_OUT_OF_SORTMEMORY
return true;
default:
break;
}

if (errorCode >= -10000 && errorCode <= -9000) {
return true;
}

if (StringUtils.isNotBlank(e.getMessage())) {
final String errorText = e.getMessage().toUpperCase();
String message = e.getMessage();
if (message != null && message.length() > 0) {
final String errorText = message.toUpperCase();

if (errorCode == 0
&& (errorText.indexOf("COMMUNICATIONS LINK FAILURE") > -1 || errorText
.indexOf("COULD NOT CREATE CONNECTION") > -1)
|| errorText.indexOf("NO DATASOURCE") > -1
if ((errorCode == 0 && (errorText.indexOf("COMMUNICATIONS LINK FAILURE") > -1) //
|| errorText.indexOf("COULD NOT CREATE CONNECTION") > -1) //
|| errorText.indexOf("NO DATASOURCE") > -1 //
|| errorText.indexOf("NO ALIVE DATASOURCE") > -1) {
return true;
}
}
return false;
}

@Override
public void configFromProperties(Properties properties) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.alibaba.druid.sql.ast.SQLDataType;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
Expand Down Expand Up @@ -55,8 +57,11 @@

public class MySqlExprParser extends SQLExprParser {

public static String[] AGGREGATE_FUNCTIONS = { "AVG", "COUNT", "GROUP_CONCAT", "MAX", "MIN", "STDDEV", "SUM" };

public MySqlExprParser(Lexer lexer){
super(lexer);
this.aggregateFunctions = AGGREGATE_FUNCTIONS;
}

public MySqlExprParser(String sql){
Expand Down Expand Up @@ -769,4 +774,19 @@ public MySqlForeignKey parseForeignKey() {
accept(Token.RPAREN);
return fk;
}

protected SQLAggregateExpr parseAggregateExprRest(SQLAggregateExpr aggregateExpr) {
if (lexer.token() == Token.ORDER) {
SQLOrderBy orderBy = this.parseOrderBy();
aggregateExpr.putAttribute("ORDER BY", orderBy);
}
if (identifierEquals("SEPARATOR")) {
lexer.nextToken();

SQLExpr seperator = this.primary();

aggregateExpr.putAttribute("SEPARATOR", seperator);
}
return aggregateExpr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.alibaba.druid.sql.ast.SQLDataType;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
Expand Down Expand Up @@ -594,8 +596,7 @@ public boolean visit(SQLVariantRefExpr x) {
&& (!varName.equals("?")) //
&& (!varName.startsWith("#")) //
&& (!varName.startsWith("$")) //
&& (!varName.startsWith(":"))
) {
&& (!varName.startsWith(":"))) {
print("@@");
}
}
Expand Down Expand Up @@ -3061,4 +3062,21 @@ public void endVisit(InValues x) {

}

protected void visitAggreateRest(SQLAggregateExpr aggregateExpr) {
{
SQLOrderBy value = (SQLOrderBy) aggregateExpr.getAttribute("ORDER BY");
if (value != null) {
print(" ");
((SQLObject) value).accept(this);
}
}
{
Object value = aggregateExpr.getAttribute("SEPARATOR");
if (value != null) {
print(" SEPARATOR ");
((SQLObject) value).accept(this);
}
}
}

} //
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,6 @@
public class OracleExprParser extends SQLExprParser {


















public boolean allowStringAdditive = false;

/**
Expand Down Expand Up @@ -137,10 +121,11 @@ public class OracleExprParser extends SQLExprParser {

public OracleExprParser(Lexer lexer){
super(lexer);
this.aggregateFunctions = AGGREGATE_FUNCTIONS;
}

public OracleExprParser(String text){
super(new OracleLexer(text));
this(new OracleLexer(text));
this.lexer.nextToken();
}

Expand Down Expand Up @@ -267,16 +252,6 @@ public SQLDataType parseDataType() {
return parseDataTypeRest(dataType);
}

public boolean isAggreateFunction(String word) {
for (int i = 0; i < AGGREGATE_FUNCTIONS.length; ++i) {
if (AGGREGATE_FUNCTIONS[i].compareToIgnoreCase(word) == 0) {
return true;
}
}

return false;
}

public SQLExpr primary() {
final Token tok = lexer.token();

Expand Down
Loading

0 comments on commit 5cbc916

Please sign in to comment.