You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2008/10/23 18:51:45 UTC
svn commit: r707414 - in /db/derby/code/trunk/java/engine/org/apache/derby:
catalog/DefaultInfo.java catalog/types/DefaultInfoImpl.java
iapi/sql/dictionary/ColumnDescriptor.java
iapi/sql/dictionary/TableDescriptor.java
Author: rhillegas
Date: Thu Oct 23 09:51:45 2008
New Revision: 707414
URL: http://svn.apache.org/viewvc?rev=707414&view=rev
Log:
DERBY-481: Catalog changes supporting generated columns.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java
db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptor.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java?rev=707414&r1=707413&r2=707414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java Thu Oct 23 09:51:45 2008
@@ -33,6 +33,12 @@
*/
public String getDefaultText();
+ /**
+ * If this default is a generation clause, then return the 1-based ids of
+ * other columns in the row which the generation clause references.
+ */
+ public int[] getReferencedColumnIDs();
+
/**
* Is default value generated by auto increment?
@@ -46,4 +52,11 @@
//should be gotten from this interface.
public boolean isDefaultValueAutoinc();
+
+ /**
+ * Return true if this is the generation clause for a generated column.
+ */
+ public boolean isGeneratedColumn();
+
+
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java?rev=707414&r1=707413&r2=707414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java Thu Oct 23 09:51:45 2008
@@ -55,8 +55,10 @@
private DataValueDescriptor defaultValue;
private String defaultText;
private int type;
+ private int[] referencedColumnIDs;
final private static int BITS_MASK_IS_DEFAULTVALUE_AUTOINC = 0x1 << 0;
+ final private static int BITS_MASK_IS_GENERATED_COLUMN = 0x2;
/**
* Public niladic constructor. Needed for Formatable interface to work.
@@ -79,6 +81,22 @@
}
/**
+ * Constructor for use with generated columns
+ */
+ public DefaultInfoImpl
+ (
+ String defaultText,
+ int[] referencedColumnIDs
+ )
+ {
+ if ( referencedColumnIDs == null ) { referencedColumnIDs = new int[0]; }
+
+ this.type = BITS_MASK_IS_GENERATED_COLUMN;
+ this.defaultText = defaultText;
+ this.referencedColumnIDs = referencedColumnIDs;
+ }
+
+ /**
* @see DefaultInfo#getDefaultText
*/
public String getDefaultText()
@@ -86,6 +104,14 @@
return defaultText;
}
+ /**
+ * @see DefaultInfo#getReferencedColumnIDs
+ */
+ public int[] getReferencedColumnIDs()
+ {
+ return referencedColumnIDs;
+ }
+
public String toString()
{
if(isDefaultValueAutoinc()){
@@ -110,6 +136,13 @@
defaultText = (String) in.readObject();
defaultValue = (DataValueDescriptor) in.readObject();
type = in.readInt();
+
+ if ( isGeneratedColumn() )
+ {
+ int count = in.readInt();
+ referencedColumnIDs = new int[ count ];
+ for ( int i = 0; i < count; i++ ) { referencedColumnIDs[ i ] = in.readInt(); }
+ }
}
/**
@@ -125,6 +158,13 @@
out.writeObject( defaultText );
out.writeObject( defaultValue );
out.writeInt(type);
+
+ if ( isGeneratedColumn() )
+ {
+ int count = referencedColumnIDs.length;
+ out.writeInt( count );
+ for ( int i = 0; i < count; i++ ) { out.writeInt( referencedColumnIDs[ i ] ); }
+ }
}
/**
@@ -164,6 +204,13 @@
}
/**
+ * @see DefaultInfo#isGeneratedColumn
+ */
+ public boolean isGeneratedColumn(){
+ return (type & BITS_MASK_IS_GENERATED_COLUMN ) != 0;
+ }
+
+ /**
* This function returns stored value for flags and so on.
*/
private static int calcType(boolean isDefaultValueAutoinc){
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptor.java?rev=707414&r1=707413&r2=707414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptor.java Thu Oct 23 09:51:45 2008
@@ -358,6 +358,15 @@
}
/**
+ * Is this column a generated column
+ */
+ public boolean hasGenerationClause()
+ {
+ if ( columnDefaultInfo == null ) { return false; }
+ else { return columnDefaultInfo.isGeneratedColumn(); }
+ }
+
+ /**
* Is this column to have autoincremented value always ?
*/
public boolean isAutoincAlways(){
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=707414&r1=707413&r2=707414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java Thu Oct 23 09:51:45 2008
@@ -889,6 +889,24 @@
}
/**
+ * Gets the list of columns defined by generation clauses.
+ */
+ public ColumnDescriptorList getGeneratedColumns()
+ {
+ ColumnDescriptorList fullList = getColumnDescriptorList();
+ ColumnDescriptorList result = new ColumnDescriptorList();
+ int count = fullList.size();
+
+ for ( int i = 0; i < count; i++ )
+ {
+ ColumnDescriptor cd = fullList.elementAt( i );
+ if ( cd.hasGenerationClause() ) { result.add( oid, cd ); }
+ }
+
+ return result;
+ }
+
+ /**
* Gets the constraint descriptor list
*
* @return The constraint descriptor list for this table descriptor