diff --git a/src/main/java/com/alibaba/druid/sql/ast/SQLZOrderBy.java b/src/main/java/com/alibaba/druid/sql/ast/SQLZOrderBy.java new file mode 100644 index 0000000000..3b350b9723 --- /dev/null +++ b/src/main/java/com/alibaba/druid/sql/ast/SQLZOrderBy.java @@ -0,0 +1,133 @@ +/* + * Copyright 1999-2017 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.ast; + +import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem; +import com.alibaba.druid.sql.visitor.SQLASTVisitor; + +import java.util.ArrayList; +import java.util.List; + +public final class SQLZOrderBy extends SQLObjectImpl implements SQLReplaceable { + + protected final List items = new ArrayList(); + + // for postgres + private boolean sibings; + + public SQLZOrderBy(){ + + } + + public SQLZOrderBy(SQLExpr expr){ + SQLSelectOrderByItem item = new SQLSelectOrderByItem(expr); + addItem(item); + } + + public SQLZOrderBy(SQLExpr expr, SQLOrderingSpecification type){ + SQLSelectOrderByItem item = new SQLSelectOrderByItem(expr, type); + addItem(item); + } + + public void addItem(SQLSelectOrderByItem item) { + if (item != null) { + item.setParent(this); + } + this.items.add(item); + } + + public void addItem(SQLExpr item) { + addItem(new SQLSelectOrderByItem(item)); + } + + public List getItems() { + return this.items; + } + + public boolean isSibings() { + return this.sibings; + } + + public void setSibings(boolean sibings) { + this.sibings = sibings; + } + + protected void accept0(SQLASTVisitor v) { + if (v.visit(this)) { + for (int i = 0; i < this.items.size(); i++) { + final SQLSelectOrderByItem item = this.items.get(i); + item.accept(v); + } + } + + v.endVisit(this); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SQLZOrderBy order = (SQLZOrderBy) o; + + if (sibings != order.sibings) return false; + return items.equals(order.items); + } + + @Override + public int hashCode() { + int result = items.hashCode(); + result = 31 * result + (sibings ? 1 : 0); + return result; + } + + public void addItem(SQLExpr expr, SQLOrderingSpecification type) { + SQLSelectOrderByItem item = createItem(); + item.setExpr(expr); + item.setType(type); + addItem(item); + } + + @Override + public boolean replace(SQLExpr expr, SQLExpr target) { + + for (SQLSelectOrderByItem item : items) { + if(item.replace(expr, target)) { + return true; + } + } + + return false; + } + + protected SQLSelectOrderByItem createItem() { + return new SQLSelectOrderByItem(); + } + + public SQLZOrderBy clone() { + SQLZOrderBy x = new SQLZOrderBy(); + + for (SQLSelectOrderByItem item : items) { + SQLSelectOrderByItem item1 = item.clone(); + item1.setParent(x); + x.items.add(item1); + } + + x.sibings = sibings; + + return x; + } +} diff --git a/src/main/java/com/alibaba/druid/sql/ast/statement/SQLPurgeTemporaryOutputStatement.java b/src/main/java/com/alibaba/druid/sql/ast/statement/SQLPurgeTemporaryOutputStatement.java new file mode 100644 index 0000000000..98786da184 --- /dev/null +++ b/src/main/java/com/alibaba/druid/sql/ast/statement/SQLPurgeTemporaryOutputStatement.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2017 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.ast.statement; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.SQLName; +import com.alibaba.druid.sql.ast.SQLStatementImpl; +import com.alibaba.druid.sql.visitor.SQLASTVisitor; + +public class SQLPurgeTemporaryOutputStatement extends SQLStatementImpl implements SQLDropStatement { + private SQLName name; + + public SQLPurgeTemporaryOutputStatement() { + + } + + public SQLPurgeTemporaryOutputStatement(DbType dbType) { + super (dbType); + } + + @Override + protected void accept0(SQLASTVisitor visitor) { + if (visitor.visit(this)) { + acceptChild(visitor, name); + } + visitor.endVisit(this); + } + + public SQLName getName() { + return name; + } + + public void setName(SQLName x) { + if (x != null) { + x.setParent(this); + } + this.name = x; + } + +} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/odps/ast/OdpsInstallPackageStatement.java b/src/main/java/com/alibaba/druid/sql/dialect/odps/ast/OdpsInstallPackageStatement.java new file mode 100644 index 0000000000..b06d697703 --- /dev/null +++ b/src/main/java/com/alibaba/druid/sql/dialect/odps/ast/OdpsInstallPackageStatement.java @@ -0,0 +1,27 @@ +package com.alibaba.druid.sql.dialect.odps.ast; + +import com.alibaba.druid.sql.ast.SQLName; +import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor; + +public class OdpsInstallPackageStatement extends OdpsStatementImpl { + private SQLName packageName; + + @Override + protected void accept0(OdpsASTVisitor v) { + if (v.visit(this)) { + acceptChild(v, packageName); + } + v.endVisit(this); + } + + public SQLName getPackageName() { + return packageName; + } + + public void setPackageName(SQLName x) { + if (x != null) { + x.setParent(this); + } + this.packageName = x; + } +}