empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1235876 - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBDDLGenerator.java DBExpressionIndex.java DBIndex.java DBTable.java
Date Wed, 25 Jan 2012 19:00:42 GMT
Author: doebele
Date: Wed Jan 25 19:00:41 2012
New Revision: 1235876

URL: http://svn.apache.org/viewvc?rev=1235876&view=rev
Log:
EMPIREDB-129
added new class DBExpressionIndex

Added:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java
  (with props)
Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java?rev=1235876&r1=1235875&r2=1235876&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
Wed Jan 25 19:00:41 2012
@@ -405,7 +405,7 @@ public abstract class DBDDLGenerator<T e
 
             // columns
             boolean addSeparator = false;
-            DBColumn[] idxColumns = idx.getColumns();
+            DBColumnExpr[] idxColumns = idx.getColumnExpressions();
             for (int i = 0; i < idxColumns.length; i++)
             {
                 sql.append((addSeparator) ? ", " : "");

Added: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java?rev=1235876&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java
Wed Jan 25 19:00:41 2012
@@ -0,0 +1,112 @@
+/*
+ * 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.db;
+
+import org.apache.empire.exceptions.InvalidArgumentException;
+
+/**
+ * This class handles the primary key for the tables.
+ * The primary key contains one or more columns.
+ * <P>
+ * 
+ *
+ */
+public class DBExpressionIndex extends DBIndex
+{
+    private final static long serialVersionUID = 1L;
+    
+    private DBColumnExpr[] columnExpressions;
+
+    /**
+     * Constructs a DBExpresionIndex
+     * 
+     * @param name the index name
+     * @param unique true if the index has only unique values or false otherwise
+     * @param columnExpressions an array of one or more column expressions of the index
+     */
+    public DBExpressionIndex(String name, boolean unique, DBColumnExpr[] columnExpressions)
+    {
+        super(name, (unique ? UNIQUE : STANDARD), null);
+        // columnExpressions
+        if (columnExpressions==null || columnExpressions.length==0)
+            throw new InvalidArgumentException("columnExpressions", columnExpressions);
+        // set expression
+        this.columnExpressions = columnExpressions;
+    }
+
+    /**
+     * Constructs a DBExpresionIndex
+     * 
+     * @param name the index name
+     * @param unique true if the index has only unique values or false otherwise
+     * @param columnExpression an column expressions that defines the key values for the
index
+     */
+    public DBExpressionIndex(String name, boolean unique, DBColumnExpr expr)
+    {
+        this(name, unique, new DBColumnExpr[] { expr });
+    }
+    
+    @Override
+    public DBDatabase getDatabase()
+    {
+        return columnExpressions[0].getDatabase();
+    }
+
+    /**
+     * Returns the columnExpressions belonging to this index.
+     * 
+     * @return the columnExpressions belonging to this index
+     */
+    @Override
+    public DBColumnExpr[] getColumnExpressions()
+    {
+        return columnExpressions;
+    }
+
+    /**
+     * Checks if this index contains the column col  
+     * 
+     * @param col the column
+     * 
+     * @return true if this index contains this column
+     */
+    @Override
+    public boolean contains(DBColumn col)
+    {
+        for (int i = 0; i < columnExpressions.length; i++)
+            if (col.equals(columnExpressions[i].getUpdateColumn()))
+                return true;
+        return false;
+    }
+
+    /**
+     * Gets the position of a specified DBColumn object.
+     * 
+     * @param col the column 
+     * 
+     * @return the position or -1 if the column was not found
+     */
+    @Override
+    public int getColumnPos(DBColumn col)
+    {
+        return -1;
+    }
+
+}
+

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBExpressionIndex.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java?rev=1235876&r1=1235875&r2=1235876&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java Wed
Jan 25 19:00:41 2012
@@ -91,6 +91,16 @@ public class DBIndex extends DBObject
     }
 
     /**
+     * Returns the columnExpressions belonging to this index.
+     * 
+     * @return the columnExpressions belonging to this index
+     */
+    public DBColumnExpr[] getColumnExpressions()
+    {
+        return columns;
+    }
+
+    /**
      * Returns the full qualified table name.
      * 
      * @return the full qualified table name

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java?rev=1235876&r1=1235875&r2=1235876&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java Wed
Jan 25 19:00:41 2012
@@ -332,12 +332,38 @@ public class DBTable extends DBRowSet im
      * 
      * @return true on success
      */
+    public void addIndex(DBIndex index)
+    {
+        if (index==null)
+            throw new InvalidArgumentException("index", null);
+        // Check index name
+        String name = index.getName();
+        for (DBIndex i : indexes)
+        {
+            if (i==index || name.equalsIgnoreCase(i.getName()))
+            {
+                throw new ItemExistsException(name);
+            }
+        }        
+        // add Index now
+        indexes.add(index);
+    }
+
+    /**
+     * Adds an index.
+     * 
+     * @param name the index name
+     * @param unique is this a unique index
+     * @param columns the columns indexed by this index
+     * 
+     * @return true on success
+     */
     public void addIndex(String name, boolean unique, DBColumn[] columns)
     {
         if (name==null || columns==null || columns.length==0)
             throw new InvalidArgumentException("name|columns", null);
         // add Index now
-        indexes.add(new DBIndex(name, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, columns));
+        addIndex(new DBIndex(name, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, columns));
     }
 
     /**



Mime
View raw message