1 package org.apache.torque.engine.platform;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.sql.Connection;
23 import java.sql.DatabaseMetaData;
24 import java.sql.PreparedStatement;
25 import java.sql.ResultSet;
26 import java.sql.SQLException;
27 import java.util.List;
28
29 import org.apache.torque.engine.database.model.Domain;
30 import org.apache.torque.engine.database.model.SchemaType;
31
32
33
34
35
36
37
38 public class PlatformOracleImpl extends PlatformDefaultImpl {
39
40
41
42 public PlatformOracleImpl() {
43 super();
44 initialize();
45 }
46
47
48
49
50 private void initialize() {
51 setSchemaDomainMapping(new Domain(SchemaType.TINYINT, "NUMBER", "3", "0"));
52 setSchemaDomainMapping(new Domain(SchemaType.SMALLINT, "NUMBER", "5", "0"));
53 setSchemaDomainMapping(new Domain(SchemaType.INTEGER, "NUMBER", "10", "0"));
54 setSchemaDomainMapping(new Domain(SchemaType.BOOLEANINT, "NUMBER", "1", "0"));
55 setSchemaDomainMapping(new Domain(SchemaType.BIGINT, "NUMBER", "20", "0"));
56 setSchemaDomainMapping(new Domain(SchemaType.REAL, "NUMBER"));
57 setSchemaDomainMapping(new Domain(SchemaType.DOUBLE, "FLOAT"));
58 setSchemaDomainMapping(new Domain(SchemaType.DECIMAL, "NUMBER"));
59 setSchemaDomainMapping(new Domain(SchemaType.NUMERIC, "NUMBER"));
60 setSchemaDomainMapping(new Domain(SchemaType.VARCHAR, "VARCHAR2"));
61 setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "VARCHAR2", "2000"));
62 setSchemaDomainMapping(new Domain(SchemaType.TIME, "DATE"));
63 setSchemaDomainMapping(new Domain(SchemaType.TIMESTAMP, "TIMESTAMP"));
64 setSchemaDomainMapping(new Domain(SchemaType.BINARY, "LONG RAW"));
65 setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "BLOB"));
66 setSchemaDomainMapping(new Domain(SchemaType.LONGVARBINARY, "LONG RAW"));
67 }
68
69 @Override
70 public String getSchemaName(String artifactId) {
71 String s = super.getSchemaName(artifactId);
72 return s.toUpperCase();
73 }
74
75
76
77
78 public int getMaxColumnNameLength() {
79 return 30;
80 }
81
82
83
84
85 public String getNativeIdMethod() {
86 return Platform.SEQUENCE;
87 }
88
89
90
91
92 public String getAutoIncrement() {
93 return "";
94 }
95
96 @Override
97 public List<String> getPrimaryKeys(DatabaseMetaData dbMeta, String dbSchema, String tableName) throws SQLException {
98 return super.getPrimaryKeys(dbMeta, dbSchema.toUpperCase(), tableName);
99 }
100
101 public List<String> getTableNames(DatabaseMetaData dbMeta, String databaseSchema) throws SQLException {
102 return super.getTableNames(dbMeta, databaseSchema.toUpperCase());
103 }
104
105 @Override
106 public boolean isSpecialDefault(String defaultValue) {
107 defaultValue = defaultValue.toUpperCase();
108 if (defaultValue.contains("SYS_GUID()") || defaultValue.contains("SYSDATE") || defaultValue.contains("USERENV(\'SESSIONID\')")) {
109 return true;
110 }
111 return false;
112 }
113
114 @Override
115 public Long getSequenceNextVal(Connection con, String schema, String sequenceName) {
116 try {
117 PreparedStatement ps = con.prepareStatement("SELECT last_number FROM all_sequences WHERE sequence_owner = ? AND sequence_name = ?");
118 Long nextVal = 0L;
119 ps.setString(1, schema.toUpperCase());
120 ps.setString(2, sequenceName.toUpperCase());
121 ResultSet rs = ps.executeQuery();
122 if (rs.next()) {
123 nextVal = rs.getLong(1);
124 }
125 rs.close();
126 ps.close();
127 return nextVal;
128 } catch (SQLException ex) {
129 System.err.println("Unable to extract sequence definition: " + schema + "." + sequenceName);
130 ex.printStackTrace();
131 return 0L;
132 }
133 }
134
135 @Override
136 public String getViewDefinition(Connection con, String schema, String viewName) {
137 try {
138 PreparedStatement ps = con.prepareStatement("SELECT text FROM all_views WHERE owner = ? AND view_name = ?");
139 String definition = "";
140 ps.setString(1, schema.toUpperCase());
141 ps.setString(2, viewName.toUpperCase());
142 ResultSet rs = ps.executeQuery();
143 if (rs.next()) {
144 definition = rs.getString(1);
145 }
146 rs.close();
147 ps.close();
148 return definition;
149 } catch (SQLException ex) {
150 System.err.println("Unable to extract view definition: " + schema + "." + viewName);
151 ex.printStackTrace();
152 return "";
153 }
154 }
155
156 }