Skip to content

Commit

Permalink
0001286: Failed to create trigger when table contains timestamp with …
Browse files Browse the repository at this point in the history
…time zone column in Oracle
  • Loading branch information
chenson42 committed Oct 27, 2014
1 parent 3aef986 commit f454c5e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
Expand Up @@ -37,6 +37,7 @@ public OracleTriggerTemplate(ISymmetricDialect symmetricDialect) {
numberColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', '\"'||cast($(tableAlias).\"$(columnName)\" as number("+symmetricDialect.getTemplateNumberPrecisionSpec()+"))||'\"')" ;
datetimeColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', concat(concat('\"',to_char($(tableAlias).\"$(columnName)\", 'YYYY-MM-DD HH24:MI:SS.FF3')),'\"'))" ;
dateTimeWithTimeZoneColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', concat(concat('\"',to_char($(tableAlias).\"$(columnName)\", 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM')),'\"'))" ;
dateTimeWithLocalTimeZoneColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', concat(concat('\"',to_char(cast($(tableAlias).\"$(columnName)\" as timestamp), 'YYYY-MM-DD HH24:MI:SS.FF')),'\"'))" ;
timeColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', concat(concat('\"',to_char($(tableAlias).\"$(columnName)\", 'YYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=''GREGORIAN''')),'\"'))" ;
dateColumnTemplate = "decode($(tableAlias).\"$(columnName)\", null, '', concat(concat('\"',to_char($(tableAlias).\"$(columnName)\", 'YYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=''GREGORIAN''')),'\"'))" ;
clobColumnTemplate = "decode(dbms_lob.getlength($(tableAlias).\"$(columnName)\"), null, to_clob(''), '\"'||replace(replace($(tableAlias).\"$(columnName)\",'\\','\\\\'),'\"','\\\"')||'\"')" ;
Expand Down
Expand Up @@ -83,6 +83,8 @@ abstract public class AbstractTriggerTemplate {
protected String dateColumnTemplate;

protected String dateTimeWithTimeZoneColumnTemplate;

protected String dateTimeWithLocalTimeZoneColumnTemplate;

protected String geometryColumnTemplate;

Expand Down Expand Up @@ -791,6 +793,10 @@ protected ColumnString fillOutColumnTemplate(String origTableAlias, String table
&& StringUtils.isNotBlank(this.dateTimeWithTimeZoneColumnTemplate)) {
templateToUse = this.dateTimeWithTimeZoneColumnTemplate;
break;
} else if (column.getMappedType().equals(TypeMap.TIMESTAMPLTZ)
&& StringUtils.isNotBlank(this.dateTimeWithLocalTimeZoneColumnTemplate)) {
templateToUse = this.dateTimeWithLocalTimeZoneColumnTemplate;
break;
}

}
Expand Down
Expand Up @@ -91,6 +91,8 @@ public abstract class TypeMap
public static final String TIMESTAMP = "TIMESTAMP";

public static final String TIMESTAMPTZ = "TIMESTAMPTZ";

public static final String TIMESTAMPLTZ = "TIMESTAMPLTZ";

/** The string representation of the {@link java.sql.Types#TINYINT} constant. */
public static final String TINYINT = "TINYINT";
Expand Down Expand Up @@ -154,7 +156,7 @@ public abstract class TypeMap
registerJdbcType(Types.VARBINARY, VARBINARY, JdbcTypeCategoryEnum.BINARY);
registerJdbcType(Types.VARCHAR, VARCHAR, JdbcTypeCategoryEnum.TEXTUAL);
registerJdbcType(ORACLE_TIMESTAMPTZ, TIMESTAMPTZ, JdbcTypeCategoryEnum.DATETIME);
registerJdbcType(ORACLE_TIMESTAMPLTZ, TIMESTAMPTZ, JdbcTypeCategoryEnum.DATETIME);
registerJdbcType(ORACLE_TIMESTAMPLTZ, TIMESTAMPLTZ, JdbcTypeCategoryEnum.DATETIME);

// only available in JDK 1.4 and above:
if (PlatformUtils.supportsJava14JdbcTypes())
Expand Down
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -564,7 +565,14 @@ public java.util.Date parseDate(int type, String value, boolean useVariableDates
try {
return Timestamp.valueOf(value);
} catch (IllegalArgumentException ex) {
return FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS);
try {
return FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS);
} catch (Exception e) {
int split = value.lastIndexOf(" ");
return FormatUtils.parseDate(value.substring(0, split).trim(),
FormatUtils.TIMESTAMP_PATTERNS,
TimeZone.getTimeZone(value.substring(split).trim()));
}
}
} else if (type == Types.TIME) {
if (value.indexOf(".") == 8) {
Expand Down
Expand Up @@ -526,6 +526,8 @@ public static Object getResultSetValue(ResultSet rs, int index, boolean readStri
obj = rs.getTimestamp(index);
} else if (className != null && "oracle.sql.TIMESTAMPTZ".equals(className)) {
obj = rs.getString(index);
} else if (className != null && "oracle.sql.TIMESTAMPLTZ".equals(className)) {
obj = rs.getString(index);
} else if (className != null && className.startsWith("oracle.sql.DATE")) {
String metaDataClassName = metaData.getColumnClassName(index);
if ("java.sql.Timestamp".equals(metaDataClassName)
Expand Down
Expand Up @@ -202,6 +202,8 @@ protected String getMappedType(int typeCode) {
case Types.TIME:
case OracleTypes.TIMESTAMPTZ:
return "timestamp with time zone";
case OracleTypes.TIMESTAMPLTZ:
return "timestamp with local time zone";
case Types.TIMESTAMP:
return "timestamp";
case Types.NUMERIC:
Expand All @@ -227,6 +229,7 @@ protected String getTypeName(int typeCode) {
case Types.DATE:
case Types.TIME:
case OracleTypes.TIMESTAMPTZ:
case OracleTypes.TIMESTAMPLTZ:
case Types.TIMESTAMP:
return String.format("%s_%s_t", procedurePrefix, "timestamp").toUpperCase();
case Types.NUMERIC:
Expand Down

0 comments on commit f454c5e

Please sign in to comment.