summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java')
-rw-r--r--src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
index 85ff60d5d9..81c0568f15 100644
--- a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
+++ b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
@@ -36,6 +36,7 @@ final public class ColumnProperty implements Property {
private boolean modified;
private boolean versionColumn;
+ private boolean primaryKey = false;
/**
* Prevent instantiation without required parameters.
@@ -44,9 +45,50 @@ final public class ColumnProperty implements Property {
private ColumnProperty() {
}
+ /**
+ * Deprecated constructor for ColumnProperty. If this is used the primary
+ * keys are not identified correctly in some cases for some databases (i.e.
+ * Oracle). See http://dev.vaadin.com/ticket/9145.
+ *
+ * @param propertyId
+ * @param readOnly
+ * @param allowReadOnlyChange
+ * @param nullable
+ * @param value
+ * @param type
+ *
+ * @deprecated
+ */
+ @Deprecated
public ColumnProperty(String propertyId, boolean readOnly,
boolean allowReadOnlyChange, boolean nullable, Object value,
Class<?> type) {
+ this(propertyId, readOnly, allowReadOnlyChange, nullable, false, value,
+ type);
+ }
+
+ /**
+ * Creates a new ColumnProperty instance.
+ *
+ * @param propertyId
+ * The ID of this property.
+ * @param readOnly
+ * Whether this property is read-only.
+ * @param allowReadOnlyChange
+ * Whether the read-only status of this property can be changed.
+ * @param nullable
+ * Whether this property accepts null values.
+ * @param primaryKey
+ * Whether this property corresponds to a database primary key.
+ * @param value
+ * The value of this property.
+ * @param type
+ * The type of this property.
+ */
+ public ColumnProperty(String propertyId, boolean readOnly,
+ boolean allowReadOnlyChange, boolean nullable, boolean primaryKey,
+ Object value, Class<?> type) {
+
if (propertyId == null) {
throw new IllegalArgumentException("Properties must be named.");
}
@@ -60,8 +102,15 @@ final public class ColumnProperty implements Property {
this.allowReadOnlyChange = allowReadOnlyChange;
this.nullable = nullable;
this.readOnly = readOnly;
+ this.primaryKey = primaryKey;
}
+ /**
+ * Returns the current value for this property. To get the previous value
+ * (if one exists) for a modified property use {@link #getOldValue()}.
+ *
+ * @return
+ */
public Object getValue() {
if (isModified()) {
return changedValue;
@@ -69,6 +118,17 @@ final public class ColumnProperty implements Property {
return value;
}
+ /**
+ * Returns the original non-modified value of this property if it has been
+ * modified.
+ *
+ * @return The original value if <code>isModified()</code> is true,
+ * <code>getValue()</code> otherwise.
+ */
+ public Object getOldValue() {
+ return value;
+ }
+
public void setValue(Object newValue) throws ReadOnlyException,
ConversionException {
if (newValue == null && !nullable) {
@@ -154,6 +214,17 @@ final public class ColumnProperty implements Property {
return readOnly;
}
+ /**
+ * Returns whether the read-only status of this property can be changed
+ * using {@link #setReadOnly(boolean)}.
+ * <p>
+ * Used to prevent setting to read/write mode a property that is not allowed
+ * to be written by the underlying database. Also used for values like
+ * VERSION and AUTO_INCREMENT fields that might be set to read-only by the
+ * container but the database still allows writes.
+ *
+ * @return true if the read-only status can be changed, false otherwise.
+ */
public boolean isReadOnlyChangeAllowed() {
return allowReadOnlyChange;
}
@@ -164,6 +235,10 @@ final public class ColumnProperty implements Property {
}
}
+ public boolean isPrimaryKey() {
+ return primaryKey;
+ }
+
public String getPropertyId() {
return propertyId;
}
@@ -205,6 +280,32 @@ final public class ColumnProperty implements Property {
}
/**
+ * Return whether the value of this property should be persisted to the
+ * database.
+ *
+ * @return true if the value should be written to the database, false
+ * otherwise.
+ */
+ public boolean isPersistent() {
+ if (isVersionColumn()) {
+ return false;
+ } else if (isReadOnlyChangeAllowed() && !isReadOnly()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns whether or not this property is used as a row identifier.
+ *
+ * @return true if the property is a row identifier, false otherwise.
+ */
+ public boolean isRowIdentifier() {
+ return isPrimaryKey() || isVersionColumn();
+ }
+
+ /**
* An exception that signals that a <code>null</code> value was passed to
* the <code>setValue</code> method, but the value of this property can not
* be set to <code>null</code>.