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