Skip to content

Commit

Permalink
Issue 1540: Improve Oracle platform java time support (#1835)
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
  • Loading branch information
dazey3 committed Mar 16, 2023
1 parent 30c7b6a commit f291911
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,6 +19,10 @@

package org.eclipse.persistence.platform.database;

import java.util.Hashtable;

import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;

/**
* <p><b>Purpose:</b>
* Provides Oracle version specific behavior when
Expand All @@ -30,6 +34,21 @@ public Oracle10Platform(){
super();
}

/**
* INTERNAL:
* Add XMLType as the default database type for org.w3c.dom.Documents.
* Add TIMESTAMP, TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE
*/
@Override
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
Hashtable<Class<?>, FieldTypeDefinition> fieldTypes = super.buildFieldTypes();
// Offset classes contain an offset from UTC/Greenwich in the ISO-8601 calendar system so TZ should be included
// TIMESTAMP WITH TIME ZONE is supported since 10g
fieldTypes.put(java.time.OffsetDateTime.class, new FieldTypeDefinition("TIMESTAMP WITH TIME ZONE"));
fieldTypes.put(java.time.OffsetTime.class, new FieldTypeDefinition("TIMESTAMP WITH TIME ZONE"));
return fieldTypes;
}

/**
* Build the hint string used for first rows.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -242,6 +242,14 @@ protected Hashtable buildFieldTypes() {
//bug 5871089 the default generator requires definitions based on all java types
fieldTypeMapping.put(java.util.Calendar.class, new FieldTypeDefinition("TIMESTAMP"));
fieldTypeMapping.put(java.util.Date.class, new FieldTypeDefinition("TIMESTAMP"));
// Local classes have no TZ information included
fieldTypeMapping.put(java.time.LocalDate.class, new FieldTypeDefinition("DATE"));
fieldTypeMapping.put(java.time.LocalDateTime.class, new FieldTypeDefinition("TIMESTAMP"));
fieldTypeMapping.put(java.time.LocalTime.class, new FieldTypeDefinition("TIMESTAMP"));
// Offset classes contain an offset from UTC/Greenwich in the ISO-8601 calendar system so TZ should be included
// but TIMESTAMP WITH TIME ZONE is not supported until 10g
fieldTypeMapping.put(java.time.OffsetDateTime.class, new FieldTypeDefinition("TIMESTAMP"));
fieldTypeMapping.put(java.time.OffsetTime.class, new FieldTypeDefinition("TIMESTAMP"));

return fieldTypeMapping;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -15,8 +16,10 @@
package org.eclipse.persistence.platform.database.oracle;

import java.sql.Statement;
import java.util.Hashtable;

import org.eclipse.persistence.internal.databaseaccess.DatabaseCall;
import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;

import oracle.jdbc.OraclePreparedStatement;

Expand All @@ -30,6 +33,21 @@ public Oracle10Platform(){
super();
}

/**
* INTERNAL:
* Add XMLType as the default database type for org.w3c.dom.Documents.
* Add TIMESTAMP, TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE
*/
@Override
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
Hashtable<Class<?>, FieldTypeDefinition> fieldTypes = super.buildFieldTypes();
// Offset classes contain an offset from UTC/Greenwich in the ISO-8601 calendar system so TZ should be included
// TIMESTAMP WITH TIME ZONE is supported since 10g
fieldTypes.put(java.time.OffsetDateTime.class, new FieldTypeDefinition("TIMESTAMP WITH TIME ZONE"));
fieldTypes.put(java.time.OffsetTime.class, new FieldTypeDefinition("TIMESTAMP WITH TIME ZONE"));
return fieldTypes;
}

/**
* Build the hint string used for first rows.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ protected Hashtable buildFieldTypes() {
fieldTypes.put(ORACLE_SQL_TIMESTAMP, new FieldTypeDefinition("TIMESTAMP", false));
fieldTypes.put(ORACLE_SQL_TIMESTAMPTZ, new FieldTypeDefinition("TIMESTAMP WITH TIME ZONE", false));
fieldTypes.put(ORACLE_SQL_TIMESTAMPLTZ, new FieldTypeDefinition("TIMESTAMP WITH LOCAL TIME ZONE", false));

fieldTypes.put(java.time.LocalDate.class, new FieldTypeDefinition("DATE"));
fieldTypes.put(java.time.LocalDateTime.class, new FieldTypeDefinition("TIMESTAMP"));
fieldTypes.put(java.time.LocalTime.class, new FieldTypeDefinition("TIMESTAMP"));
fieldTypes.put(java.time.OffsetDateTime.class, new FieldTypeDefinition("TIMESTAMP")); //TIMESTAMP WITH TIME ZONE ???
fieldTypes.put(java.time.OffsetTime.class, new FieldTypeDefinition("TIMESTAMP")); //TIMESTAMP WITH TIME ZONE ???
return fieldTypes;
}

Expand Down

0 comments on commit f291911

Please sign in to comment.