empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1295343 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBColumn.java DBTableColumn.java oracle/OracleDDLGenerator.java sqlserver/MSSqlDDLGenerator.java
Date Wed, 29 Feb 2012 23:49:41 GMT
Author: doebele
Date: Wed Feb 29 23:49:40 2012
New Revision: 1295343

URL: http://svn.apache.org/viewvc?rev=1295343&view=rev
Log:
EMPIREDB-123
use DBTableColum.setSingleByteChars(boolean singleByteChars)

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java?rev=1295343&r1=1295342&r2=1295343&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java Wed Feb 29
23:49:40 2012
@@ -23,6 +23,7 @@ import java.util.Set;
 
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.Column;
+import org.apache.empire.data.DataType;
 import org.apache.empire.db.exceptions.DatabaseNotOpenException;
 import org.apache.empire.db.expr.set.DBSetExpr;
 import org.w3c.dom.Element;
@@ -66,6 +67,11 @@ public abstract class DBColumn extends D
      * Maximum value (Integer)
      */
     public static final String DBCOLATTR_MAXVALUE  = "maxValue";
+    
+    /**
+     * Read only column (Boolean)
+     */
+    public static final String DBCOLATTR_SINGLEBYTECHARS  = "singleByteChars";
 
     // basic data
     protected final DBRowSet   rowset;
@@ -117,6 +123,39 @@ public abstract class DBColumn extends D
 
     public abstract void checkValue(Object value);
 
+    /**
+     * Returns true if column the column is a character based column (char, text or clob)
+     * 
+     * @return true if column is a character based column
+     */
+    public boolean isCharacterColumn()
+    {
+        DataType type = getDataType();
+        return (type==DataType.TEXT || type ==DataType.CHAR || type==DataType.CLOB);
+    }
+
+    /**
+     * Returns true if column the column is a numeric column (integer, decimal, float)
+     * 
+     * @return true if column is a numeric column
+     */
+    public boolean isNumericColumn()
+    {
+        DataType type = getDataType();
+        return (type==DataType.INTEGER || type ==DataType.DECIMAL || type==DataType.FLOAT
|| type==DataType.AUTOINC);
+    }
+
+    /**
+     * Returns true if column the column is a date based column (date, datetime)
+     * 
+     * @return true if column is a date based column
+     */
+    public boolean isDateColumn()
+    {
+        DataType type = getDataType();
+        return (type==DataType.DATE || type ==DataType.DATETIME);
+    }
+    
     @Override
     public abstract Element addXml(Element parent, long flags);
 

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1295343&r1=1295342&r2=1295343&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Wed Feb
29 23:49:40 2012
@@ -24,11 +24,14 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.apache.empire.commons.Attributes;
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.exceptions.FieldIllegalValueException;
 import org.apache.empire.db.exceptions.FieldNotNullException;
 import org.apache.empire.db.exceptions.FieldValueTooLongException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotSupportedException;
 import org.apache.empire.exceptions.PropertyReadOnlyException;
 import org.apache.empire.xml.XMLUtil;
 import org.slf4j.Logger;
@@ -71,15 +74,17 @@ public class DBTableColumn extends DBCol
         if (type==DataType.AUTOINC && dataMode!=DataMode.AutoGenerated)
             dataMode=DataMode.AutoGenerated;
         if (type==DataType.INTEGER && dataMode==DataMode.AutoGenerated)
-            type=DataType.AUTOINC;
+            type=DataType.AUTOINC;           
         // set column properties
         this.type = type;
-        this.size = size;
         this.dataMode = dataMode;
         this.defValue = defValue;
         // xml
         this.attributes = new Attributes();
         this.options = null;
+        // size (after attributes!)
+        setSize(size);
+        // Append to table (if supplied)
         if (table != null)
         {
             table.addColumn(this);
@@ -97,7 +102,8 @@ public class DBTableColumn extends DBCol
         this.size = other.size;
         this.dataMode = other.dataMode;
         this.defValue = other.defValue;
-        this.attributes = other.attributes;
+        this.attributes = new Attributes();
+        this.attributes.putAll(other.attributes);
         this.options = other.options;
         if (newTable != null)
         {
@@ -181,6 +187,21 @@ public class DBTableColumn extends DBCol
      */
     public void setSize(double size)
     {
+        // Negative size?
+        if (size<0)
+        {   // For Text-Columns set attribute "SINGLEBYTECHARS"
+            if (isCharacterColumn())
+                setAttribute(DBCOLATTR_SINGLEBYTECHARS, Boolean.TRUE);
+            else
+                throw new InvalidArgumentException("size", size);
+            // Remove sign
+            size = Math.abs(size);
+        }
+        else if (attributes!=null && attributes.containsKey(DBCOLATTR_SINGLEBYTECHARS))
+        {   // Remove single by chars attribute
+            attributes.remove(DBCOLATTR_SINGLEBYTECHARS);
+        }
+        // set now
         this.size = size;
     }
 
@@ -205,6 +226,30 @@ public class DBTableColumn extends DBCol
     {
         return (dataMode==DataMode.AutoGenerated);
     }
+    
+    /**
+     * Returns true if column the column is a single byte text or character column or false
otherwise
+     * 
+     * @return true if column is a single byte character based column
+     */
+    public boolean isSingleByteChars()
+    {
+        if (attributes==null || !attributes.containsKey(DBCOLATTR_SINGLEBYTECHARS))
+            return false;
+        // Check Attribute
+        return ObjectUtils.getBoolean(attributes.get(DBCOLATTR_SINGLEBYTECHARS));
+    }
+    
+    /**
+     * sets whether this column is a single byte character or text column 
+     */
+    public void setSingleByteChars(boolean singleByteChars)
+    {
+        if (!isCharacterColumn())
+            throw new NotSupportedException(this, "setSingleByteChars");
+        // set single byte
+        setAttribute(DBCOLATTR_SINGLEBYTECHARS, singleByteChars);
+    }
 
     /**
      * Changes the required property of the table column<BR>

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java?rev=1295343&r1=1295342&r2=1295343&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/OracleDDLGenerator.java
Wed Feb 29 23:49:40 2012
@@ -72,7 +72,7 @@ public class OracleDDLGenerator extends 
                 sql.append("(");
                 sql.append(String.valueOf(len));
                 // Check sign for char (unicode) or bytes (non-unicode) 
-                sql.append((size>0) ? " CHAR)" : " BYTE)");
+                sql.append((c.isSingleByteChars()) ? " BYTE)" : " CHAR)");
             }
                 break;
             case BOOL:

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java?rev=1295343&r1=1295342&r2=1295343&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/MSSqlDDLGenerator.java
Wed Feb 29 23:49:40 2012
@@ -73,9 +73,9 @@ public class MSSqlDDLGenerator extends D
             case CHAR:
             {   // Char or Varchar
                 if (type==DataType.CHAR)
-                    sql.append((size<0) ? DATATYPE_CHAR.substring(1) : DATATYPE_CHAR);
+                    sql.append((c.isSingleByteChars()) ? DATATYPE_CHAR.substring(1) : DATATYPE_CHAR);
                 else
-                    sql.append((size<0) ? DATATYPE_VARCHAR.substring(1) : DATATYPE_VARCHAR);
+                    sql.append((c.isSingleByteChars()) ? DATATYPE_VARCHAR.substring(1) :
DATATYPE_VARCHAR);
                 // get length
                 int len = Math.abs((int)size);
                 if (len == 0)



Mime
View raw message