aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2015-01-31 19:30:55 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2015-01-31 19:30:55 +0000
commit95d0db424ea8dfb4cc00657cddb8bbf12fe1579d (patch)
tree74769fc74e1746e9bd4ef5ac791449c2f8fbbd9c /src/main/java
parent03490053350b104516bc09a5301f7c02afc5000c (diff)
downloadjackcess-95d0db424ea8dfb4cc00657cddb8bbf12fe1579d.tar.gz
jackcess-95d0db424ea8dfb4cc00657cddb8bbf12fe1579d.zip
Make ColumnBuilder.setMaxLength do the right thing regardless of column type. Add setMaxScale and setMaxPrecision helpers. Make default length for TEXT columns the max length
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@910 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java31
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/DataType.java4
2 files changed, 31 insertions, 4 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java
index bbfca27..f013e3b 100644
--- a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java
+++ b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java
@@ -130,6 +130,17 @@ public class ColumnBuilder {
}
/**
+ * Sets the precision for the new column to the max length for the type.
+ * Does nothing for types which do not have a precision.
+ */
+ public ColumnBuilder setMaxPrecision() {
+ if(_type.getHasScalePrecision()) {
+ setPrecision(_type.getMaxPrecision());
+ }
+ return this;
+ }
+
+ /**
* Sets the scale for the new column.
*/
public ColumnBuilder setScale(int newScale) {
@@ -142,6 +153,17 @@ public class ColumnBuilder {
}
/**
+ * Sets the scale for the new column to the max length for the type. Does
+ * nothing for types which do not have a scale.
+ */
+ public ColumnBuilder setMaxScale() {
+ if(_type.getHasScalePrecision()) {
+ setScale(_type.getMaxScale());
+ }
+ return this;
+ }
+
+ /**
* Sets the length (in bytes) for the new column.
*/
public ColumnBuilder setLength(int length) {
@@ -163,10 +185,15 @@ public class ColumnBuilder {
}
/**
- * Sets the length for the new column to the max length for the type.
+ * Sets the length for the new column to the max length for the type. Does
+ * nothing for types which are not variable length.
*/
public ColumnBuilder setMaxLength() {
- return setLength(_type.getMaxSize());
+ // length setting only makes sense for variable length columns
+ if(_type.isVariableLength()) {
+ setLength(_type.getMaxSize());
+ }
+ return this;
}
/**
diff --git a/src/main/java/com/healthmarketscience/jackcess/DataType.java b/src/main/java/com/healthmarketscience/jackcess/DataType.java
index ffd5bf4..ad6deaf 100644
--- a/src/main/java/com/healthmarketscience/jackcess/DataType.java
+++ b/src/main/java/com/healthmarketscience/jackcess/DataType.java
@@ -114,8 +114,8 @@ public enum DataType {
* null}. Equivalent to SQL {@link Types#VARCHAR}, {@link Types#CHAR}.
*/
TEXT((byte) 0x0A, Types.VARCHAR, null, true, false, 0,
- 50 * JetFormat.TEXT_FIELD_UNIT_SIZE,
- JetFormat.TEXT_FIELD_MAX_LENGTH, JetFormat.TEXT_FIELD_UNIT_SIZE),
+ JetFormat.TEXT_FIELD_MAX_LENGTH, JetFormat.TEXT_FIELD_MAX_LENGTH,
+ JetFormat.TEXT_FIELD_UNIT_SIZE),
/**
* Corresponds to a java {@code byte[]} of max length 16777215 bytes.
* Accepts a {@code byte[]}, or {@code null}. Equivalent to SQL