Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Limit date-time objects to millisecond-only r…
Browse files Browse the repository at this point in the history
…esolution for compatibility with Jackcess, enable unit test
  • Loading branch information
spannm committed Nov 13, 2023
1 parent ea0f0f7 commit c4072c2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/ucanaccess/complex/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Attachment(ComplexValue.Id id, String tableName, String columnName, Strin
name = _name;
type = _type;
data = _data;
timeStamp = _timeStamp;
timeStamp = handleJackcessLocalDateTimeResolution(_timeStamp);
flags = _flags;
}

Expand Down Expand Up @@ -149,8 +149,8 @@ public void setUrl(String _url) {

@Override
public String toString() {
return "Attachment [url=" + url + ", name=" + name + ", type=" + type + ", data=" + Arrays.toString(data)
+ ", timeStamp=" + timeStamp + ", flags=" + flags + "]";
return String.format("%s[url=%s, name=%s, type=%s, data=%s, timeStamp=%s, flags=%s]",
getClass().getSimpleName(), url, name, type, Arrays.toString(data), timeStamp, flags);
}

}
22 changes: 22 additions & 0 deletions src/main/java/net/ucanaccess/complex/ComplexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;

public abstract class ComplexBase implements Serializable {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -115,4 +117,24 @@ public static Object[] convert(ComplexValueForeignKey fk) throws IOException, Uc
throw new UcanaccessSQLException(ExceptionMessages.COMPLEX_TYPE_UNSUPPORTED);
}

@Override
public String toString() {
return String.format("%s[id=%s, table=%s, column=%s]", getClass().getSimpleName(), id, tableName, columnName);
}

/**
* Converts a local date-time (date/time without timezone) with arbitrary resolution (depends on Java version)
* to millisecond-only resolution for compatibility with Jackcess.
*
* @param _ldt local datetime with arbitrary resolution
* @return local datetime with arbitrary resolution
*/
static LocalDateTime handleJackcessLocalDateTimeResolution(LocalDateTime _ldt) {
if (_ldt == null) {
return _ldt;
}
long millis = TimeUnit.NANOSECONDS.toMillis(_ldt.getNano());
return _ldt.withNano((int) TimeUnit.MILLISECONDS.toNanos(millis));
}

}
18 changes: 9 additions & 9 deletions src/main/java/net/ucanaccess/complex/SingleValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public SingleValue(String _value) {

}

public Object getValue() {
return value;
}

public void setValue(Object _value) {
value = _value;
}

@Override
public boolean equals(Object _obj) {
if (this == _obj) {
Expand All @@ -40,10 +48,6 @@ public boolean equals(Object _obj) {
return true;
}

public Object getValue() {
return value;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -52,13 +56,9 @@ public int hashCode() {
return result;
}

public void setValue(Object _value) {
value = _value;
}

@Override
public String toString() {
return "SingleValue [value=" + value + "]";
return String.format("%s[value=%s]", getClass().getSimpleName(), value);
}

public static SingleValue[] multipleValue(String... rv) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/ucanaccess/complex/UnsupportedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public boolean equals(Object _obj) {
return true;
}

public Map<String, Object> getValues() {
return values;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -49,6 +45,10 @@ public int hashCode() {
return result;
}

public Map<String, Object> getValues() {
return values;
}

public void setValues(Map<String, Object> _values) {
values = _values;
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/net/ucanaccess/complex/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ public Version(com.healthmarketscience.jackcess.complex.Version cv) {
public Version(ComplexValue.Id id, String tableName, String columnName, String _value, LocalDateTime _modifiedDate) {
super(id, tableName, columnName);
value = _value;
modifiedDate = _modifiedDate;
modifiedDate = handleJackcessLocalDateTimeResolution(_modifiedDate);
}

public Version(String _value, LocalDateTime _modifiedDate) {
this(CREATE_ID, null, null, _value, _modifiedDate);
}

public LocalDateTime getModifiedDate() {
return modifiedDate;
}

public void setModifiedDate(LocalDateTime _modifiedDate) {
modifiedDate = _modifiedDate;
}

public String getValue() {
return value;
}

public void setValue(String _value) {
value = _value;
}

@Override
public boolean equals(Object _obj) {
if (this == _obj) {
Expand All @@ -51,14 +67,6 @@ public boolean equals(Object _obj) {
return true;
}

public LocalDateTime getModifiedDate() {
return modifiedDate;
}

public String getValue() {
return value;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -68,17 +76,9 @@ public int hashCode() {
return result;
}

public void setModifiedDate(LocalDateTime _modifiedDate) {
modifiedDate = _modifiedDate;
}

public void setValue(String _value) {
value = _value;
}

@Override
public String toString() {
return "Version [value=" + value + ", modifiedDate=" + modifiedDate + "]";
return String.format("%s[value=%s, modifiedDate=%s]", getClass().getSimpleName(), value, modifiedDate);
}

}
2 changes: 0 additions & 2 deletions src/test/java/net/ucanaccess/jdbc/ComplexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.ucanaccess.test.AccessVersion;
import net.ucanaccess.test.UcanaccessBaseTest;
import net.ucanaccess.util.UcanaccessRuntimeException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.EnumSource.Mode;
Expand All @@ -28,7 +27,6 @@ protected String getAccessPath() {

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class, mode=Mode.INCLUDE, names = {"V2010"})
@Disabled("TODO: Fails with Java 11 under Ubuntu")
void testComplex(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);

Expand Down

0 comments on commit c4072c2

Please sign in to comment.