add db2 PageUtils support

This commit is contained in:
wenshao
2013-07-26 01:01:58 +08:00
parent 89f1106e34
commit 9722e3aeea
19 changed files with 538 additions and 14 deletions
@@ -0,0 +1,24 @@
/*
* 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.sql.dialect.db2.ast;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
public interface DB2Object extends SQLObject {
void accept0(DB2ASTVisitor visitor);
}
@@ -15,11 +15,46 @@
*/
package com.alibaba.druid.sql.dialect.db2.ast.stmt;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.db2.ast.DB2Object;
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class DB2SelectQueryBlock extends SQLSelectQueryBlock {
public class DB2SelectQueryBlock extends SQLSelectQueryBlock implements DB2Object {
private SQLExpr first;
private static final long serialVersionUID = 1L;
public SQLExpr getFirst() {
return first;
}
public void setFirst(SQLExpr first) {
this.first = first;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof DB2ASTVisitor) {
accept0((DB2ASTVisitor) visitor);
return;
}
super.accept0(visitor);
}
@Override
public void accept0(DB2ASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.first);
}
visitor.endVisit(this);
}
}
@@ -1,3 +1,18 @@
/*
* 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.sql.dialect.db2.parser;
import com.alibaba.druid.sql.parser.Lexer;
@@ -1,3 +1,18 @@
/*
* 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.sql.dialect.db2.parser;
import java.util.HashMap;
@@ -17,6 +32,10 @@ public class DB2Lexer extends Lexer {
map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords());
map.put("FETCH", Token.FETCH);
map.put("FIRST", Token.FIRST);
map.put("ONLY", Token.ONLY);
DEFAULT_DB2_KEYWORDS = new Keywords(map);
}
@@ -15,10 +15,11 @@
*/
package com.alibaba.druid.sql.dialect.db2.parser;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.SQLSelectParser;
import com.alibaba.druid.sql.parser.Token;
@@ -49,7 +50,7 @@ public class DB2SelectParser extends SQLSelectParser {
}
accept(Token.SELECT);
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
}
@@ -74,6 +75,17 @@ public class DB2SelectParser extends SQLSelectParser {
parseWhere(queryBlock);
parseGroupBy(queryBlock);
if (lexer.token() == Token.FETCH) {
lexer.nextToken();
accept(Token.FIRST);
SQLExpr first = this.exprParser.primary();
queryBlock.setFirst(first);
if (identifierEquals("ROW") || identifierEquals("ROWS")) {
lexer.nextToken();
}
accept(Token.ONLY);
}
return queryRest(queryBlock);
}
@@ -1,3 +1,18 @@
/*
* 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.sql.dialect.db2.parser;
import com.alibaba.druid.sql.parser.Lexer;
@@ -1,8 +1,26 @@
/*
* 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.sql.dialect.db2.visitor;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public interface DB2ASTVisitor extends SQLASTVisitor {
boolean visit(DB2SelectQueryBlock x);
void endVisit(DB2SelectQueryBlock x);
}
@@ -1,7 +1,33 @@
/*
* 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.sql.dialect.db2.visitor;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
public class DB2ASTVisitorAdapter extends SQLASTVisitorAdapter implements DB2ASTVisitor {
@Override
public boolean visit(DB2SelectQueryBlock x) {
return true;
}
@Override
public void endVisit(DB2SelectQueryBlock x) {
}
}
@@ -1,10 +1,46 @@
/*
* 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.sql.dialect.db2.visitor;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisitor {
public DB2OutputVisitor(Appendable appender){
super(appender);
}
@Override
public boolean visit(DB2SelectQueryBlock x) {
this.visit((SQLSelectQueryBlock) x);
if (x.getFirst() != null) {
println();
print("FETCH FIRST ");
x.getFirst().accept(this);
print(" ROWS ONLY");
}
return false;
}
@Override
public void endVisit(DB2SelectQueryBlock x) {
}
}
@@ -15,6 +15,8 @@
*/
package com.alibaba.druid.sql.dialect.db2.visitor;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
import com.alibaba.druid.util.JdbcUtils;
@@ -25,4 +27,14 @@ public class DB2SchemaStatVisitor extends SchemaStatVisitor implements DB2ASTVis
return JdbcUtils.DB2;
}
@Override
public boolean visit(DB2SelectQueryBlock x) {
return this.visit((SQLSelectQueryBlock) x);
}
@Override
public void endVisit(DB2SelectQueryBlock x) {
}
}