This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 54d5633  EMPIREDB-381 Added postgres @@ comparator
54d5633 is described below

commit 54d5633cfdc21ddd1d7193e114dcc1f928bb80d9
Author: Rainer Döbele <[email protected]>
AuthorDate: Sun Mar 6 12:03:43 2022 +0100

    EMPIREDB-381 Added postgres @@ comparator
---
 .../empire/dbms/postgresql/DBCommandPostgres.java  |  5 ++
 .../empire/dbms/postgresql/PostgresAtAt.java       | 96 ++++++++++++++++++++++
 2 files changed, 101 insertions(+)

diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBCommandPostgres.java
 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBCommandPostgres.java
index 00f381a..d7099b8 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBCommandPostgres.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBCommandPostgres.java
@@ -81,6 +81,11 @@ public class DBCommandPostgres extends DBCommand
         return new PostgresBoolAndOrExpr(cmpExpr, true);
     }
     
+    public PostgresAtAt compareAtAt(DBColumnExpr left, DBColumnExpr right)
+    {
+        return new PostgresAtAt(left, right);
+    }
+    
     @Override
     public DBCommand limitRows(int numRows)
     {
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/postgresql/PostgresAtAt.java 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/PostgresAtAt.java
new file mode 100644
index 0000000..b61317f
--- /dev/null
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/PostgresAtAt.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.empire.dbms.postgresql;
+
+import java.util.Set;
+
+import org.apache.empire.commons.Unwrappable;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.expr.compare.DBCompareExpr;
+
+/**
+ * PostgresAtAt
+ * create a Postgres @@ comparator 
+ */
+public class PostgresAtAt extends DBCompareExpr
+{
+    private final DBColumnExpr left;
+    private final DBColumnExpr right;
+
+    public PostgresAtAt(DBColumnExpr left, DBColumnExpr right)
+    {
+        this.left = left;
+        this.right = right;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public DBDatabase getDatabase()
+    {
+        return this.left.getDatabase();
+    }
+
+    @Override
+    public void prepareCommand(DBCommand cmd)
+    {
+        /* nothing */
+    }
+
+    @Override
+    public DBCompareExpr copy(DBCommand newCmd)
+    {
+        return new PostgresAtAt(this.left, this.right);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public boolean isMutuallyExclusive(DBCompareExpr other)
+    {
+        if ((other instanceof Unwrappable<?>) && 
((Unwrappable<?>)other).isWrapper())
+        {   // unwrap
+            other = ((Unwrappable<DBCompareExpr>)other).unwrap();
+        }
+        if (other instanceof PostgresAtAt)
+        {   // compare
+            PostgresAtAt otherAtAt = (PostgresAtAt)other;
+            return this.left.equals(otherAtAt.left) &&
+                   this.right.equals(otherAtAt.right);
+        }
+        return false;
+    }
+
+    @Override
+    public void addReferencedColumns(Set<DBColumn> list)
+    {
+        // forward
+        this.left.addReferencedColumns(list);
+        this.right.addReferencedColumns(list);
+    }
+
+    @Override
+    public void addSQL(StringBuilder buf, long context)
+    {
+        this.left.addSQL(buf, context);
+        buf.append(" @@ ");
+        this.right.addSQL(buf, context);
+    }
+}

Reply via email to