aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-12-17 23:10:13 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-12-17 23:10:13 +0000
commitc1aa151cd41d0b8da5f16ac2b40bdc7f084f7d70 (patch)
treeea75e2803bd5a5605bae9912ec577ca9c2b7ec6c /src/main
parent21fe1417bb49bbdba8591377c221a4417a8851ee (diff)
downloadjackcess-c1aa151cd41d0b8da5f16ac2b40bdc7f084f7d70.tar.gz
jackcess-c1aa151cd41d0b8da5f16ac2b40bdc7f084f7d70.zip
add LocalDateTime variants for various public Date based methods
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1241 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/DateTimeType.java4
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/Row.java10
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/complex/Attachment.java28
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java46
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/complex/Version.java10
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java1
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/complex/AttachmentColumnInfoImpl.java34
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexValueForeignKeyImpl.java123
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/complex/VersionHistoryColumnInfoImpl.java68
9 files changed, 239 insertions, 85 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/DateTimeType.java b/src/main/java/com/healthmarketscience/jackcess/DateTimeType.java
index 7f5cdb1..8704350 100644
--- a/src/main/java/com/healthmarketscience/jackcess/DateTimeType.java
+++ b/src/main/java/com/healthmarketscience/jackcess/DateTimeType.java
@@ -17,7 +17,9 @@ limitations under the License.
package com.healthmarketscience.jackcess;
/**
- * Enum for selecting how a Database returns date/time types.
+ * Enum for selecting how a Database returns date/time types. Prefer using
+ * {@link DateTimeType#LOCAL_DATE_TIME} as using Date is being phased out and
+ * will eventually be removed.
*
* @author James Ahlborn
*/
diff --git a/src/main/java/com/healthmarketscience/jackcess/Row.java b/src/main/java/com/healthmarketscience/jackcess/Row.java
index 6917628..8fcaf67 100644
--- a/src/main/java/com/healthmarketscience/jackcess/Row.java
+++ b/src/main/java/com/healthmarketscience/jackcess/Row.java
@@ -91,12 +91,20 @@ public interface Row extends Map<String,Object>
/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Date (DataType SHORT_DATE_TIME).
+ * @deprecated this is only valid for Database instances configured for the
+ * legacy {@link DateTimeType#DATE}. Prefer using
+ * {@link DateTimeType#LOCAL_DATE_TIME} and the corresponding
+ * {@link #getLocalDateTime} method. Using Date is being phased
+ * out and will eventually be removed.
*/
+ @Deprecated
public Date getDate(String name);
/**
* Convenience method which gets the value for the row with the given name,
- * casting it to a LocalDateTime (DataType SHORT_DATE_TIME).
+ * casting it to a LocalDateTime (DataType SHORT_DATE_TIME). This method
+ * will only work for Database instances configured for
+ * {@link DateTimeType#LOCAL_DATE_TIME}.
*/
public LocalDateTime getLocalDateTime(String name);
diff --git a/src/main/java/com/healthmarketscience/jackcess/complex/Attachment.java b/src/main/java/com/healthmarketscience/jackcess/complex/Attachment.java
index d35559e..0047719 100644
--- a/src/main/java/com/healthmarketscience/jackcess/complex/Attachment.java
+++ b/src/main/java/com/healthmarketscience/jackcess/complex/Attachment.java
@@ -17,14 +17,16 @@ limitations under the License.
package com.healthmarketscience.jackcess.complex;
import java.io.IOException;
+import java.time.LocalDateTime;
import java.util.Date;
+import com.healthmarketscience.jackcess.DateTimeType;
/**
* Complex value corresponding to an attachment.
*
* @author James Ahlborn
*/
-public interface Attachment extends ComplexValue
+public interface Attachment extends ComplexValue
{
public byte[] getFileData() throws IOException;
@@ -37,20 +39,34 @@ public interface Attachment extends ComplexValue
public String getFileName();
public void setFileName(String fileName);
-
+
public String getFileUrl();
public void setFileUrl(String fileUrl);
-
+
public String getFileType();
public void setFileType(String fileType);
-
+
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public Date getFileTimeStamp();
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public void setFileTimeStamp(Date fileTimeStamp);
-
+
+ public LocalDateTime getFileLocalTimeStamp();
+
+ public void setFileLocalTimeStamp(LocalDateTime fileTimeStamp);
+
+ public Object getFileTimeStampObject();
+
public Integer getFileFlags();
- public void setFileFlags(Integer fileFlags);
+ public void setFileFlags(Integer fileFlags);
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java b/src/main/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
index 150dd07..0e0bc13 100644
--- a/src/main/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
+++ b/src/main/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
@@ -18,10 +18,13 @@ package com.healthmarketscience.jackcess.complex;
import java.io.IOException;
import java.io.ObjectStreamException;
+import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
+
import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.DateTimeType;
/**
@@ -40,33 +43,33 @@ import com.healthmarketscience.jackcess.Column;
*/
public abstract class ComplexValueForeignKey extends Number
{
- private static final long serialVersionUID = 20130319L;
+ private static final long serialVersionUID = 20130319L;
@Override
public byte byteValue() {
return (byte)get();
}
-
+
@Override
public short shortValue() {
return (short)get();
}
-
+
@Override
public int intValue() {
return get();
}
-
+
@Override
public long longValue() {
return get();
}
-
+
@Override
public float floatValue() {
return get();
}
-
+
@Override
public double doubleValue() {
return get();
@@ -78,12 +81,12 @@ public abstract class ComplexValueForeignKey extends Number
// of jackcess)
return Integer.valueOf(get());
}
-
+
@Override
public int hashCode() {
return get();
}
-
+
@Override
public boolean equals(Object o) {
return ((this == o) ||
@@ -94,7 +97,7 @@ public abstract class ComplexValueForeignKey extends Number
@Override
public String toString() {
return String.valueOf(get());
- }
+ }
public abstract int get();
@@ -122,25 +125,50 @@ public abstract class ComplexValueForeignKey extends Number
public abstract Version addVersion(String value)
throws IOException;
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public abstract Version addVersion(String value, Date modifiedDate)
throws IOException;
+ public abstract Version addVersion(String value, LocalDateTime modifiedDate)
+ throws IOException;
+
public abstract Attachment addAttachment(byte[] data)
throws IOException;
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public abstract Attachment addAttachment(
String url, String name, String type, byte[] data,
Date timeStamp, Integer flags)
throws IOException;
+ public abstract Attachment addAttachment(
+ String url, String name, String type, byte[] data,
+ LocalDateTime timeStamp, Integer flags)
+ throws IOException;
+
public abstract Attachment addEncodedAttachment(byte[] encodedData)
throws IOException;
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public abstract Attachment addEncodedAttachment(
String url, String name, String type, byte[] encodedData,
Date timeStamp, Integer flags)
throws IOException;
+ public abstract Attachment addEncodedAttachment(
+ String url, String name, String type, byte[] encodedData,
+ LocalDateTime timeStamp, Integer flags)
+ throws IOException;
+
public abstract Attachment updateAttachment(Attachment attachment)
throws IOException;
diff --git a/src/main/java/com/healthmarketscience/jackcess/complex/Version.java b/src/main/java/com/healthmarketscience/jackcess/complex/Version.java
index a1ace1b..374e047 100644
--- a/src/main/java/com/healthmarketscience/jackcess/complex/Version.java
+++ b/src/main/java/com/healthmarketscience/jackcess/complex/Version.java
@@ -16,7 +16,9 @@ limitations under the License.
package com.healthmarketscience.jackcess.complex;
+import java.time.LocalDateTime;
import java.util.Date;
+import com.healthmarketscience.jackcess.DateTimeType;
/**
* Complex value corresponding to a version of a memo column.
@@ -27,5 +29,13 @@ public interface Version extends ComplexValue, Comparable<Version>
{
public String getValue();
+ /**
+ * @deprecated see {@link DateTimeType} for details
+ */
+ @Deprecated
public Date getModifiedDate();
+
+ public LocalDateTime getModifiedLocalDate();
+
+ public Object getModifiedDateObject();
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java
index 0e6fe6e..9b9ee7a 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java
@@ -91,6 +91,7 @@ public class RowImpl extends LinkedHashMap<String,Object> implements Row
return (Double)get(name);
}
+ @SuppressWarnings("deprecation")
public Date getDate(String name) {
return (Date)get(name);
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/complex/AttachmentColumnInfoImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/complex/AttachmentColumnInfoImpl.java
index 6642a69..1789e92 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/complex/AttachmentColumnInfoImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/complex/AttachmentColumnInfoImpl.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
@@ -166,7 +167,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
String name = (String)getFileNameColumn().getRowValue(rawValue);
String type = (String)getFileTypeColumn().getRowValue(rawValue);
Integer flags = (Integer)getFileFlagsColumn().getRowValue(rawValue);
- Date ts = (Date)getFileTimeStampColumn().getRowValue(rawValue);
+ Object ts = getFileTimeStampColumn().getRowValue(rawValue);
byte[] data = (byte[])getFileDataColumn().getRowValue(rawValue);
return new AttachmentImpl(id, complexValueFk, url, name, type, null,
@@ -182,7 +183,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
getFileNameColumn().setRowValue(row, attachment.getFileName());
getFileTypeColumn().setRowValue(row, attachment.getFileType());
getFileFlagsColumn().setRowValue(row, attachment.getFileFlags());
- getFileTimeStampColumn().setRowValue(row, attachment.getFileTimeStamp());
+ getFileTimeStampColumn().setRowValue(row, attachment.getFileTimeStampObject());
getFileDataColumn().setRowValue(row, attachment.getEncodedFileData());
return row;
}
@@ -198,7 +199,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
public static Attachment newAttachment(
String url, String name, String type, byte[] data,
- Date timeStamp, Integer flags)
+ Object timeStamp, Integer flags)
{
return newAttachment(INVALID_FK, url, name, type, data,
timeStamp, flags);
@@ -206,7 +207,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
public static Attachment newAttachment(
ComplexValueForeignKey complexValueFk, String url, String name,
- String type, byte[] data, Date timeStamp, Integer flags)
+ String type, byte[] data, Object timeStamp, Integer flags)
{
return new AttachmentImpl(INVALID_ID, complexValueFk, url, name, type,
data, timeStamp, flags, null);
@@ -224,7 +225,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
public static Attachment newEncodedAttachment(
String url, String name, String type, byte[] encodedData,
- Date timeStamp, Integer flags)
+ Object timeStamp, Integer flags)
{
return newEncodedAttachment(INVALID_FK, url, name, type,
encodedData, timeStamp, flags);
@@ -232,13 +233,14 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
public static Attachment newEncodedAttachment(
ComplexValueForeignKey complexValueFk, String url, String name,
- String type, byte[] encodedData, Date timeStamp, Integer flags)
+ String type, byte[] encodedData, Object timeStamp, Integer flags)
{
return new AttachmentImpl(INVALID_ID, complexValueFk, url, name, type,
null, timeStamp, flags, encodedData);
}
+ @SuppressWarnings("deprecation")
private static class AttachmentImpl extends ComplexValueImpl
implements Attachment
{
@@ -246,13 +248,13 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
private String _name;
private String _type;
private byte[] _data;
- private Date _timeStamp;
+ private Object _timeStamp;
private Integer _flags;
private byte[] _encodedData;
private AttachmentImpl(Id id, ComplexValueForeignKey complexValueFk,
String url, String name, String type, byte[] data,
- Date timeStamp, Integer flags, byte[] encodedData)
+ Object timeStamp, Integer flags, byte[] encodedData)
{
super(id, complexValueFk);
_url = url;
@@ -313,13 +315,25 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
}
public Date getFileTimeStamp() {
- return _timeStamp;
+ return (Date)_timeStamp;
}
public void setFileTimeStamp(Date fileTimeStamp) {
_timeStamp = fileTimeStamp;
}
+ public LocalDateTime getFileLocalTimeStamp() {
+ return (LocalDateTime)_timeStamp;
+ }
+
+ public void setFileLocalTimeStamp(LocalDateTime fileTimeStamp) {
+ _timeStamp = fileTimeStamp;
+ }
+
+ public Object getFileTimeStampObject() {
+ return _timeStamp;
+ }
+
public Integer getFileFlags() {
return _flags;
}
@@ -348,7 +362,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
return "Attachment(" + getComplexValueForeignKey() + "," + getId() +
") " + getFileUrl() + ", " + getFileName() + ", " + getFileType()
- + ", " + getFileTimeStamp() + ", " + getFileFlags() + ", " +
+ + ", " + getFileTimeStampObject() + ", " + getFileFlags() + ", " +
dataStr;
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexValueForeignKeyImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexValueForeignKeyImpl.java
index a73d3ed..06c0cd7 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexValueForeignKeyImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexValueForeignKeyImpl.java
@@ -17,11 +17,14 @@ limitations under the License.
package com.healthmarketscience.jackcess.impl.complex;
import java.io.IOException;
+import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.Database;
+import com.healthmarketscience.jackcess.DateTimeType;
import com.healthmarketscience.jackcess.Row;
import com.healthmarketscience.jackcess.complex.Attachment;
import com.healthmarketscience.jackcess.complex.AttachmentColumnInfo;
@@ -50,14 +53,15 @@ import com.healthmarketscience.jackcess.complex.VersionHistoryColumnInfo;
*
* @author James Ahlborn
*/
+@SuppressWarnings("deprecation")
public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
{
- private static final long serialVersionUID = 20110805L;
-
+ private static final long serialVersionUID = 20110805L;
+
private transient final Column _column;
private final int _value;
private transient List<? extends ComplexValue> _values;
-
+
public ComplexValueForeignKeyImpl(Column column, int value) {
_column = column;
_value = value;
@@ -72,12 +76,12 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
public Column getColumn() {
return _column;
}
-
+
@Override
public ComplexDataType getComplexType() {
return getComplexInfo().getType();
}
-
+
protected ComplexColumnInfo<? extends ComplexValue> getComplexInfo() {
return _column.getComplexInfo();
}
@@ -85,7 +89,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
protected VersionHistoryColumnInfo getVersionInfo() {
return (VersionHistoryColumnInfo)getComplexInfo();
}
-
+
protected AttachmentColumnInfo getAttachmentInfo() {
return (AttachmentColumnInfo)getComplexInfo();
}
@@ -93,27 +97,27 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
protected MultiValueColumnInfo getMultiValueInfo() {
return (MultiValueColumnInfo)getComplexInfo();
}
-
+
protected UnsupportedColumnInfo getUnsupportedInfo() {
return (UnsupportedColumnInfo)getComplexInfo();
}
-
+
@Override
public int countValues() throws IOException {
return getComplexInfo().countValues(get());
}
-
+
public List<Row> getRawValues() throws IOException {
return getComplexInfo().getRawValues(get());
- }
-
+ }
+
@Override
public List<? extends ComplexValue> getValues() throws IOException {
if(_values == null) {
_values = getComplexInfo().getValues(this);
}
return _values;
- }
+ }
@Override
@SuppressWarnings("unchecked")
@@ -123,7 +127,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
}
return (List<Version>)getValues();
}
-
+
@Override
@SuppressWarnings("unchecked")
public List<Attachment> getAttachments() throws IOException {
@@ -132,7 +136,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
}
return (List<Attachment>)getValues();
}
-
+
@Override
@SuppressWarnings("unchecked")
public List<SingleValue> getMultiValues() throws IOException {
@@ -141,7 +145,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
}
return (List<SingleValue>)getValues();
}
-
+
@Override
@SuppressWarnings("unchecked")
public List<UnsupportedValue> getUnsupportedValues() throws IOException {
@@ -150,20 +154,29 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
}
return (List<UnsupportedValue>)getValues();
}
-
+
@Override
public void reset() {
// discard any cached values
_values = null;
}
-
+
@Override
public Version addVersion(String value) throws IOException {
- return addVersion(value, new Date());
+ return addVersionImpl(value, now());
}
-
+
@Override
public Version addVersion(String value, Date modifiedDate) throws IOException {
+ return addVersionImpl(value, modifiedDate);
+ }
+
+ @Override
+ public Version addVersion(String value, LocalDateTime modifiedDate) throws IOException {
+ return addVersionImpl(value, modifiedDate);
+ }
+
+ private Version addVersionImpl(String value, Object modifiedDate) throws IOException {
reset();
Version v = VersionHistoryColumnInfoImpl.newVersion(this, value, modifiedDate);
getVersionInfo().addValue(v);
@@ -172,15 +185,32 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
@Override
public Attachment addAttachment(byte[] data) throws IOException {
- return addAttachment(null, null, null, data, null, null);
+ return addAttachmentImpl(null, null, null, data, null, null);
}
-
+
@Override
public Attachment addAttachment(
String url, String name, String type, byte[] data,
Date timeStamp, Integer flags)
throws IOException
{
+ return addAttachmentImpl(url, name, type, data, timeStamp, flags);
+ }
+
+ @Override
+ public Attachment addAttachment(
+ String url, String name, String type, byte[] data,
+ LocalDateTime timeStamp, Integer flags)
+ throws IOException
+ {
+ return addAttachmentImpl(url, name, type, data, timeStamp, flags);
+ }
+
+ private Attachment addAttachmentImpl(
+ String url, String name, String type, byte[] data,
+ Object timeStamp, Integer flags)
+ throws IOException
+ {
reset();
Attachment a = AttachmentColumnInfoImpl.newAttachment(
this, url, name, type, data, timeStamp, flags);
@@ -192,36 +222,55 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
public Attachment addEncodedAttachment(byte[] encodedData)
throws IOException
{
- return addEncodedAttachment(null, null, null, encodedData, null, null);
+ return addEncodedAttachmentImpl(null, null, null, encodedData, null, null);
}
-
+
@Override
public Attachment addEncodedAttachment(
String url, String name, String type, byte[] encodedData,
Date timeStamp, Integer flags)
throws IOException
{
+ return addEncodedAttachmentImpl(url, name, type, encodedData, timeStamp,
+ flags);
+ }
+
+ @Override
+ public Attachment addEncodedAttachment(
+ String url, String name, String type, byte[] encodedData,
+ LocalDateTime timeStamp, Integer flags)
+ throws IOException
+ {
+ return addEncodedAttachmentImpl(url, name, type, encodedData, timeStamp,
+ flags);
+ }
+
+ private Attachment addEncodedAttachmentImpl(
+ String url, String name, String type, byte[] encodedData,
+ Object timeStamp, Integer flags)
+ throws IOException
+ {
reset();
Attachment a = AttachmentColumnInfoImpl.newEncodedAttachment(
this, url, name, type, encodedData, timeStamp, flags);
getAttachmentInfo().addValue(a);
return a;
}
-
+
@Override
public Attachment updateAttachment(Attachment attachment) throws IOException {
reset();
getAttachmentInfo().updateValue(attachment);
return attachment;
}
-
+
@Override
public Attachment deleteAttachment(Attachment attachment) throws IOException {
reset();
getAttachmentInfo().deleteValue(attachment);
return attachment;
}
-
+
@Override
public SingleValue addMultiValue(Object value) throws IOException {
reset();
@@ -229,21 +278,21 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
getMultiValueInfo().addValue(v);
return v;
}
-
+
@Override
public SingleValue updateMultiValue(SingleValue value) throws IOException {
reset();
getMultiValueInfo().updateValue(value);
return value;
}
-
+
@Override
public SingleValue deleteMultiValue(SingleValue value) throws IOException {
reset();
getMultiValueInfo().deleteValue(value);
return value;
}
-
+
@Override
public UnsupportedValue addUnsupportedValue(Map<String,?> values)
throws IOException
@@ -253,7 +302,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
getUnsupportedInfo().addValue(v);
return v;
}
-
+
@Override
public UnsupportedValue updateUnsupportedValue(UnsupportedValue value)
throws IOException
@@ -262,7 +311,7 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
getUnsupportedInfo().updateValue(value);
return value;
}
-
+
@Override
public UnsupportedValue deleteUnsupportedValue(UnsupportedValue value)
throws IOException
@@ -271,16 +320,24 @@ public class ComplexValueForeignKeyImpl extends ComplexValueForeignKey
getUnsupportedInfo().deleteValue(value);
return value;
}
-
+
@Override
public void deleteAllValues() throws IOException {
reset();
getComplexInfo().deleteAllValues(this);
}
-
+
@Override
public boolean equals(Object o) {
return(super.equals(o) &&
(_column == ((ComplexValueForeignKeyImpl)o)._column));
}
+
+ private Object now() {
+ Database db = getColumn().getDatabase();
+ if(db.getDateTimeType() == DateTimeType.DATE) {
+ return new Date();
+ }
+ return LocalDateTime.now(db.getZoneId());
+ }
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/complex/VersionHistoryColumnInfoImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/complex/VersionHistoryColumnInfoImpl.java
index a64788f..14667d0 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/complex/VersionHistoryColumnInfoImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/complex/VersionHistoryColumnInfoImpl.java
@@ -17,6 +17,7 @@ limitations under the License.
package com.healthmarketscience.jackcess.impl.complex;
import java.io.IOException;
+import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -42,14 +43,14 @@ import com.healthmarketscience.jackcess.impl.ColumnImpl;
*
* @author James Ahlborn
*/
-public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
+public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
implements VersionHistoryColumnInfo
{
private final Column _valueCol;
private final Column _modifiedCol;
-
+
public VersionHistoryColumnInfoImpl(Column column, int complexId,
- Table typeObjTable, Table flatTable)
+ Table typeObjTable, Table flatTable)
throws IOException
{
super(column, complexId, typeObjTable, flatTable);
@@ -83,7 +84,7 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
getValueColumn().getName());
((ColumnImpl)versionedCol).setVersionHistoryColumn((ColumnImpl)getColumn());
}
-
+
public Column getValueColumn() {
return _valueCol;
}
@@ -91,7 +92,7 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
public Column getModifiedDateColumn() {
return _modifiedCol;
}
-
+
@Override
public ComplexDataType getType() {
return ComplexDataType.VERSION_HISTORY;
@@ -124,7 +125,7 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
// order versions newest to oldest
Collections.sort(versions);
-
+
return versions;
}
@@ -133,7 +134,7 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
Row rawValue) {
ComplexValue.Id id = getValueId(rawValue);
String value = (String)getValueColumn().getRowValue(rawValue);
- Date modifiedDate = (Date)getModifiedDateColumn().getRowValue(rawValue);
+ Object modifiedDate = getModifiedDateColumn().getRowValue(rawValue);
return new VersionImpl(id, complexValueFk, value, modifiedDate);
}
@@ -142,47 +143,55 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
protected Object[] asRow(Object[] row, Version version) throws IOException {
super.asRow(row, version);
getValueColumn().setRowValue(row, version.getValue());
- getModifiedDateColumn().setRowValue(row, version.getModifiedDate());
+ getModifiedDateColumn().setRowValue(row, version.getModifiedDateObject());
return row;
}
-
- public static Version newVersion(String value, Date modifiedDate) {
+
+ public static Version newVersion(String value, Object modifiedDate) {
return newVersion(INVALID_FK, value, modifiedDate);
}
-
+
public static Version newVersion(ComplexValueForeignKey complexValueFk,
- String value, Date modifiedDate) {
+ String value, Object modifiedDate) {
return new VersionImpl(INVALID_ID, complexValueFk, value, modifiedDate);
}
-
+ @SuppressWarnings("deprecation")
private static class VersionImpl extends ComplexValueImpl implements Version
{
private final String _value;
- private final Date _modifiedDate;
+ private final Object _modifiedDate;
private VersionImpl(Id id, ComplexValueForeignKey complexValueFk,
- String value, Date modifiedDate)
+ String value, Object modifiedDate)
{
super(id, complexValueFk);
_value = value;
_modifiedDate = modifiedDate;
}
-
+
public String getValue() {
return _value;
}
public Date getModifiedDate() {
+ return (Date)_modifiedDate;
+ }
+
+ public LocalDateTime getModifiedLocalDate() {
+ return (LocalDateTime)_modifiedDate;
+ }
+
+ public Object getModifiedDateObject() {
return _modifiedDate;
- }
-
+ }
+
public int compareTo(Version o) {
- Date d1 = getModifiedDate();
- Date d2 = o.getModifiedDate();
+ Object d1 = getModifiedDateObject();
+ Object d2 = o.getModifiedDateObject();
// sort by descending date (newest/greatest first)
- int cmp = d2.compareTo(d1);
+ int cmp = compare(d2, d1);
if(cmp != 0) {
return cmp;
}
@@ -200,11 +209,20 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
((id1 < id2) ? 1 : 0));
}
+ @SuppressWarnings("unchecked")
+ private static <C extends Comparable<C>> int compare(Object o1, Object o2) {
+ // each date/time type (Date, LocalDateTime) is mutually Comparable, so
+ // just silence the compiler
+ C c1 = (C)o1;
+ C c2 = (C)o2;
+ return c1.compareTo(c2);
+ }
+
public void update() throws IOException {
throw new UnsupportedOperationException(
"This column does not support value updates");
}
-
+
public void delete() throws IOException {
throw new UnsupportedOperationException(
"This column does not support value deletes");
@@ -214,8 +232,8 @@ public class VersionHistoryColumnInfoImpl extends ComplexColumnInfoImpl<Version>
public String toString()
{
return "Version(" + getComplexValueForeignKey() + "," + getId() + ") " +
- getModifiedDate() + ", " + getValue();
- }
+ getModifiedDateObject() + ", " + getValue();
+ }
}
-
+
}