aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience/jackcess/impl
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/java/com/healthmarketscience/jackcess/impl
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/java/com/healthmarketscience/jackcess/impl')
-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
4 files changed, 158 insertions, 68 deletions
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();
+ }
}
-
+
}