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.ResultSet; |
19 | |
import java.sql.SQLException; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import org.apache.commons.lang.StringUtils; |
27 | |
import org.apache.torque.engine.database.model.Domain; |
28 | |
import org.apache.torque.engine.database.model.SchemaType; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class PlatformDefaultImpl implements Platform { |
37 | |
private Map<SchemaType, Domain> schemaDomainMap; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public PlatformDefaultImpl() { |
43 | 0 | initialize(); |
44 | 0 | } |
45 | |
|
46 | |
private void initialize() { |
47 | 0 | schemaDomainMap = new HashMap<SchemaType, Domain>(30); |
48 | 0 | Iterator<SchemaType> iter = SchemaType.iterator(); |
49 | 0 | while (iter.hasNext()) { |
50 | 0 | SchemaType type = iter.next(); |
51 | 0 | schemaDomainMap.put(type, new Domain(type)); |
52 | 0 | } |
53 | 0 | schemaDomainMap.put(SchemaType.BOOLEANCHAR, new Domain(SchemaType.BOOLEANCHAR, "CHAR")); |
54 | 0 | schemaDomainMap.put(SchemaType.BOOLEANINT, new Domain(SchemaType.BOOLEANINT, "INTEGER")); |
55 | 0 | } |
56 | |
|
57 | |
protected void setSchemaDomainMapping(Domain domain) { |
58 | 0 | schemaDomainMap.put(domain.getType(), domain); |
59 | 0 | } |
60 | |
|
61 | |
public String getServerUrl(String url) { |
62 | |
|
63 | 0 | return url; |
64 | |
} |
65 | |
|
66 | |
public String getSchemaName(String artifactId) { |
67 | 0 | String suffix = "-db"; |
68 | 0 | if (artifactId.endsWith(suffix)) { |
69 | 0 | int length = artifactId.length(); |
70 | 0 | artifactId = artifactId.substring(0, length - suffix.length()); |
71 | |
} |
72 | 0 | return StringUtils.remove(artifactId, "-"); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public int getMaxColumnNameLength() { |
79 | 0 | return 64; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public String getNativeIdMethod() { |
86 | 0 | return Platform.IDENTITY; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public Domain getDomainForSchemaType(SchemaType jdbcType) { |
93 | 0 | return schemaDomainMap.get(jdbcType); |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public String getNullString(boolean notNull) { |
101 | |
|
102 | |
|
103 | 0 | return (notNull ? "NOT NULL" : ""); |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public String getAutoIncrement() { |
110 | 0 | return "IDENTITY"; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public boolean hasScale(String sqlType) { |
117 | 0 | return true; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public boolean hasSize(String sqlType) { |
124 | 0 | return true; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public boolean createNotNullBeforeAutoincrement() { |
131 | 0 | return true; |
132 | |
} |
133 | |
|
134 | |
public String filterInvalidDefaultValues(String defaultValue) { |
135 | 0 | return defaultValue; |
136 | |
} |
137 | |
|
138 | |
public boolean isSpecialDefault(String defaultValue) { |
139 | 0 | return false; |
140 | |
} |
141 | |
|
142 | |
public Long getSequenceNextVal(Connection con, String schema, String sequenceName) { |
143 | 0 | throw new UnsupportedOperationException("getSequenceDefinition"); |
144 | |
} |
145 | |
|
146 | |
public String getViewDefinition(Connection con, String schema, String viewName) { |
147 | 0 | throw new UnsupportedOperationException("getViewDefinition"); |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
public List<String> getPrimaryKeys(DatabaseMetaData dbMeta, String dbSchema, String tableName) throws SQLException { |
161 | 0 | List<String> pk = new ArrayList<String>(); |
162 | 0 | ResultSet parts = null; |
163 | |
try { |
164 | 0 | parts = dbMeta.getPrimaryKeys(null, dbSchema, tableName); |
165 | 0 | while (parts.next()) { |
166 | 0 | pk.add(parts.getString(4)); |
167 | |
} |
168 | |
} finally { |
169 | 0 | if (parts != null) { |
170 | 0 | parts.close(); |
171 | |
} |
172 | |
} |
173 | 0 | return pk; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public List<String> getTableNames(DatabaseMetaData dbMeta, String databaseSchema) throws SQLException { |
185 | |
|
186 | 0 | List<String> tables = new ArrayList<String>(); |
187 | 0 | ResultSet tableNames = null; |
188 | |
|
189 | 0 | String[] types = { "TABLE" }; |
190 | |
try { |
191 | 0 | tableNames = dbMeta.getTables(null, databaseSchema, null, types); |
192 | 0 | while (tableNames.next()) { |
193 | 0 | String name = tableNames.getString(3); |
194 | 0 | tables.add(name); |
195 | 0 | } |
196 | |
} finally { |
197 | 0 | if (tableNames != null) { |
198 | 0 | tableNames.close(); |
199 | |
} |
200 | |
} |
201 | |
|
202 | 0 | return tables; |
203 | |
} |
204 | |
} |