]> source.dussan.org Git - jackcess.git/commitdiff
cleanup some ColumnBuilder stuff around copying existing columns, remove useless...
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 19 Mar 2015 02:32:10 +0000 (02:32 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 19 Mar 2015 02:32:10 +0000 (02:32 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@923 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java

index dcd9f90251b0afd6751ffe95a7a3710c24c664e8..1155d4130e8ee89443bca536a70d75e2704c83ec 100644 (file)
       <action dev="jahlborn" type="add" system="SourceForge2Features" issue="29">
         Implement support for indexes on BINARY fields.
       </action>
+      <action dev="jahlborn" type="fix" system="SourceForge2" issue="120">
+        Remove useless warning for fixed length columns lengths with longer
+        length.  Cleanup some other stuff related to copying existing columns
+        in ColumnBuilder.
+      </action>
     </release>
     <release version="2.0.8" date="2014-12-26">
       <action dev="jahlborn" type="fix" system="SourceForge2" issue="113">
index 84092b4dde2f42ab6499ad382f5542fe1ef311ef..041a3c83421bf04e166d9518acab856bbaf17947 100644 (file)
@@ -27,6 +27,7 @@ King of Prussia, PA 19406
 
 package com.healthmarketscience.jackcess;
 
+import java.io.IOException;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
@@ -273,10 +274,7 @@ public class ColumnBuilder {
    * Sets the column property with the given name and type to the given value.
    */
   public ColumnBuilder putProperty(String name, DataType type, Object value) {
-    if(_props == null) {
-      _props = new HashMap<String,PropertyMap.Property>();
-    }
-    _props.put(name, PropertyMapImpl.createProperty(name, type, value));
+    setProperty(name, PropertyMapImpl.createProperty(name, type, value));
     return this;
   }
 
@@ -284,14 +282,27 @@ public class ColumnBuilder {
     return _props;
   }
 
+  private void setProperty(String name, PropertyMap.Property prop) {
+    if(prop == null) {
+      return;
+    }
+    if(_props == null) {
+      _props = new HashMap<String,PropertyMap.Property>();
+    }
+    _props.put(name, prop);
+  }
+
   private PropertyMap.Property getProperty(String name) {
     return ((_props != null) ? _props.get(name) : null);
   }
   
   /**
-   * Sets all attributes except name from the given Column template.
+   * Sets all attributes except name from the given Column template (including
+   * all column properties except GUID).
    */
-  public ColumnBuilder setFromColumn(Column template) {
+  public ColumnBuilder setFromColumn(Column template) 
+    throws IOException
+  {
     DataType type = template.getType();
     setType(type);
     setLength(template.getLength());
@@ -300,8 +311,20 @@ public class ColumnBuilder {
       setScale(template.getScale());
       setPrecision(template.getPrecision());
     }
+    setCalculated(template.isCalculated());
     setCompressedUnicode(template.isCompressedUnicode());
     setHyperlink(template.isHyperlink());
+    if(template instanceof ColumnImpl) {
+      setTextSortOrder(((ColumnImpl)template).getTextSortOrder());
+    }
+
+    PropertyMap colProps = template.getProperties();
+    for(PropertyMap.Property colProp : colProps) {
+      // copy everything but guid
+      if(!PropertyMap.GUID_PROP.equalsIgnoreCase(colProp.getName())) {
+        setProperty(colProp.getName(), colProp);
+      }
+    }
     
     return this;
   }
@@ -311,15 +334,21 @@ public class ColumnBuilder {
    */
   public ColumnBuilder setFromColumn(ColumnBuilder template) {
     DataType type = template.getType();
-    setType(type);
-    setLength(template.getLength());
-    setAutoNumber(template.isAutoNumber());
+    _type = type;
+    _length = template._length;
+    _autoNumber = template._autoNumber;
     if(type.getHasScalePrecision()) {
-      setScale(template.getScale());
-      setPrecision(template.getPrecision());
+      _scale = template._scale;
+      _precision = template._precision;
+    }
+    _calculated = template._calculated;
+    _compressedUnicode = template._compressedUnicode;
+    _hyperlink = template._hyperlink;
+    _sortOrder = template._sortOrder;
+
+    if(template._props != null) {
+      _props = new HashMap<String,PropertyMap.Property>(template._props);
     }
-    setCompressedUnicode(template.isCompressedUnicode());
-    setHyperlink(template.isHyperlink());
     
     return this;
   }
@@ -383,19 +412,15 @@ public class ColumnBuilder {
     }
     
     if(!getType().isVariableLength()) {
-      if(getLength() != getType().getFixedSize()) {
-        if(getLength() < getType().getFixedSize()) {
-          throw new IllegalArgumentException(withErrorContext(
-              "invalid fixed length size"));
-        }
-        LOG.warn(withErrorContext(
-                "Column length " + getLength() + 
-                " longer than expected fixed size " + getType().getFixedSize()));
+      if(getLength() < getType().getFixedSize()) {
+        throw new IllegalArgumentException(withErrorContext(
+            "Invalid fixed length size " + getLength()));
       }
     } else if(!getType().isLongValue()) {
       if(!getType().isValidSize(getLength())) {
         throw new IllegalArgumentException(withErrorContext(
-            "var length out of range"));
+            "Var length must be from " + getType().getMinSize() + " to " +
+            getType().getMaxSize() + " inclusive, found " + getLength()));
       }
     }
 
@@ -403,12 +428,13 @@ public class ColumnBuilder {
       if(!getType().isValidScale(getScale())) {
         throw new IllegalArgumentException(withErrorContext(
             "Scale must be from " + getType().getMinScale() + " to " +
-            getType().getMaxScale() + " inclusive"));
+            getType().getMaxScale() + " inclusive, found " + getScale()));
       }
       if(!getType().isValidPrecision(getPrecision())) {
         throw new IllegalArgumentException(withErrorContext(
             "Precision must be from " + getType().getMinPrecision() + " to " +
-            getType().getMaxPrecision() + " inclusive"));
+            getType().getMaxPrecision() + " inclusive, found " + 
+            getPrecision()));
       }
     }