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