01: package org.dbbrowser.db.engine.updateengine;
02:
03: import java.sql.Statement;
04: import java.sql.Types;
05: import java.text.DateFormat;
06: import java.text.ParseException;
07: import java.text.SimpleDateFormat;
08: import java.util.Date;
09: import org.dbbrowser.db.engine.exception.DBEngineException;
10: import org.dbbrowser.db.engine.model.DBTableCell;
11:
12: /**
13: * This class is used to update the database
14: * @author amangat
15: */
16: public class OracleDBUpdateEngine extends GenericDBUpdateEngine {
17: private static final String ORACLE_DATE_FORMAT_STRING = "dd/MM/YYYY hh:mi am"; //In Oracle minutes are represented as mi
18:
19: /**
20: * Constructer
21: * @param statement
22: */
23: public OracleDBUpdateEngine(Statement statement) {
24: super (statement);
25: }
26:
27: /**
28: * Overrides date formatting for Oracle DB
29: */
30: protected String formatValue(Object value, int dataType)
31: throws DBEngineException {
32: String formattedValue = "";
33:
34: if (dataType == Types.DATE || dataType == Types.TIMESTAMP) {
35: formattedValue = value.toString();
36: try {
37: DateFormat dateFormatForDisplay = DBTableCell
38: .getDateFormat();
39: Date date = dateFormatForDisplay
40: .parse(value.toString());
41: DateFormat dateFormatForUpdate = new SimpleDateFormat(
42: DBTableCell.DATE_FORMAT_STRING);
43: formattedValue = "to_date('"
44: + dateFormatForUpdate.format(date) + "', '"
45: + ORACLE_DATE_FORMAT_STRING + "')";
46: } catch (ParseException exc) {
47: throw new DBEngineException(exc.getMessage());
48: }
49: } else {
50: formattedValue = super.formatValue(value, dataType);
51: }
52:
53: return formattedValue;
54: }
55:
56: }
|