mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for refactor
This commit is contained in:
@@ -35,11 +35,7 @@ public class ResultSetMetaDataBase implements ResultSetMetaData {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (iface.isAssignableFrom(ResultSetMetaDataBase.class)) {
|
||||
if (isWrapperFor(iface)) {
|
||||
return (T) this;
|
||||
}
|
||||
return null;
|
||||
@@ -50,8 +46,12 @@ public class ResultSetMetaDataBase implements ResultSetMetaData {
|
||||
if (iface == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iface.isAssignableFrom(this.getClass())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ResultSetMetaDataBase.class.isAssignableFrom(iface);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,8 @@ import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnectionClosedException;
|
||||
|
||||
public abstract class StatementBase implements Statement {
|
||||
|
||||
private Connection connection;
|
||||
@@ -41,8 +43,14 @@ public abstract class StatementBase implements Statement {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
protected void checkOpen() throws SQLException {
|
||||
|
||||
protected void checkOpen() throws SQLException, MockConnectionClosedException {
|
||||
if (closed) {
|
||||
throw new SQLException();
|
||||
}
|
||||
|
||||
if (this.connection != null && this.connection.isClosed()) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,11 +206,7 @@ public abstract class StatementBase implements Statement {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (iface.isInstance(this)) {
|
||||
if (isWrapperFor(iface)) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -215,7 +219,7 @@ public abstract class StatementBase implements Statement {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iface.isInstance(this)) {
|
||||
if (iface == this.getClass() || iface.isInstance(this)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class HiveCreateTableParser extends SQLCreateTableParser {
|
||||
public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
|
||||
HiveCreateTableStatement stmt = (HiveCreateTableStatement) super.parseCrateTable(acceptCreate);
|
||||
|
||||
if (lexer.token() == Token.PARTITIONED) {
|
||||
if (identifierEquals("PARTITIONED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
accept(Token.LPAREN);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.sql.dialect.hive.parser;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
|
||||
public class HiveExprParser extends SQLExprParser {
|
||||
public HiveExprParser(String sql) throws ParserException{
|
||||
super(new HiveLexer(sql));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public HiveExprParser(Lexer lexer){
|
||||
super(lexer);
|
||||
}
|
||||
}
|
||||
@@ -83,9 +83,6 @@ public class HiveLexer extends Lexer {
|
||||
map.put("ANY", Token.ANY);
|
||||
|
||||
map.put("WITH", Token.WITH);
|
||||
map.put("PARTITIONED", Token.PARTITIONED);
|
||||
map.put("SHOW", Token.SHOW);
|
||||
map.put("TABLES", Token.TABLES);
|
||||
|
||||
DEFAULT_SQL_SERVER_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ public class HiveStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
public boolean parseStatementListDialect(List<SQLStatement> statementList) {
|
||||
if (lexer.token() == Token.SHOW) {
|
||||
if (identifierEquals("SHOW")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TABLES) {
|
||||
if (identifierEquals("TABLES")) {
|
||||
lexer.nextToken();
|
||||
|
||||
HiveShowTablesStatement stmt = new HiveShowTablesStatement();
|
||||
@@ -41,7 +41,7 @@ public class HiveStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class PGExprParser extends SQLExprParser{
|
||||
public PGExprParser(String sql) throws ParserException{
|
||||
super(sql);
|
||||
super(new PGLexer(sql));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public PGExprParser(Lexer lexer){
|
||||
|
||||
@@ -185,6 +185,10 @@ public class Lexer {
|
||||
public final Token token() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public String info() {
|
||||
return this.token + " " + this.stringVal();
|
||||
}
|
||||
|
||||
public final void nextToken() {
|
||||
sp = 0;
|
||||
|
||||
@@ -184,6 +184,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("COMMIT")) {
|
||||
SQLStatement stmt = parseCommit();
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
char mark_ch = lexer.current();
|
||||
@@ -225,6 +232,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseCommit() {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
public SQLUseStatement parseUse() {
|
||||
accept(Token.USE);
|
||||
|
||||
@@ -167,9 +167,6 @@ public enum Token {
|
||||
TOP("TOP"),
|
||||
|
||||
// hive
|
||||
PARTITIONED("PARTITIONED"),
|
||||
SHOW("SHOW"),
|
||||
TABLES("TABLES"),
|
||||
|
||||
EOF,
|
||||
ERROR,
|
||||
|
||||
@@ -8,6 +8,7 @@ import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
@@ -68,7 +69,7 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
@@ -85,7 +86,7 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
Statement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE,
|
||||
ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
@@ -102,7 +103,7 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
Statement mockStmt = stmt.unwrap(Statement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
@@ -119,7 +120,7 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
Statement stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE,
|
||||
ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
Statement mockStmt = stmt.unwrap(Statement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.alibaba.druid.bvt.mock;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSetMetaData;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.common.jdbc.ResultSetMetaDataBase;
|
||||
import com.alibaba.druid.common.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
import com.alibaba.druid.mock.MockResultSetMetaData;
|
||||
|
||||
@@ -17,6 +19,8 @@ public class MockResultSetMetaDataTest extends TestCase {
|
||||
Assert.assertTrue(meta.isWrapperFor(MockResultSetMetaData.class));
|
||||
Assert.assertFalse(meta.isWrapperFor(BigDecimal.class));
|
||||
Assert.assertTrue(meta.unwrap(MockResultSetMetaData.class) instanceof MockResultSetMetaData);
|
||||
Assert.assertTrue(meta.unwrap(ResultSetMetaDataBase.class) instanceof MockResultSetMetaData);
|
||||
Assert.assertTrue(meta.unwrap(ResultSetMetaData.class) instanceof MockResultSetMetaData);
|
||||
Assert.assertTrue(meta.unwrap(null) == null);
|
||||
Assert.assertTrue(meta.unwrap(java.sql.ResultSetMetaData.class) != null);
|
||||
Assert.assertTrue(meta.unwrap(Object.class) != null);
|
||||
|
||||
@@ -4,11 +4,11 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Case3 extends TestCase {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
Statement mockStmt = stmt.unwrap(Statement.class);
|
||||
Assert.assertEquals(false, mockStmt.isClosed());
|
||||
|
||||
conn.close();
|
||||
|
||||
@@ -80,6 +80,5 @@ public class TestOraclePrefetch extends TestCase {
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.hive.HiveTest;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
|
||||
public class HiveShowTableTest extends HiveTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user