1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.riverock.dbrevision.db.impl;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.InputStream;
30 import java.sql.Blob;
31 import java.sql.Connection;
32 import java.sql.PreparedStatement;
33 import java.sql.ResultSet;
34 import java.sql.SQLException;
35 import java.sql.Types;
36 import java.sql.DatabaseMetaData;
37 import java.util.ArrayList;
38 import java.util.List;
39
40 import org.riverock.dbrevision.annotation.schema.db.DbDataFieldData;
41 import org.riverock.dbrevision.annotation.schema.db.DbField;
42 import org.riverock.dbrevision.annotation.schema.db.DbForeignKey;
43 import org.riverock.dbrevision.annotation.schema.db.DbSequence;
44 import org.riverock.dbrevision.annotation.schema.db.DbTable;
45 import org.riverock.dbrevision.annotation.schema.db.DbView;
46 import org.riverock.dbrevision.db.Database;
47 import org.riverock.dbrevision.db.DatabaseManager;
48 import org.riverock.dbrevision.exception.DbRevisionException;
49 import org.riverock.dbrevision.utils.DbUtils;
50
51
52
53
54 public class MaxDBDatabase extends Database {
55
56 public int getMaxLengthStringField() {
57 return 2000;
58 }
59
60 public boolean isBatchUpdate() {
61 throw new Error("not tested");
62
63 }
64
65 public boolean isNeedUpdateBracket() {
66 return true;
67 }
68
69 public boolean isByteArrayInUtf8() {
70 return false;
71 }
72
73 public boolean isSchemaSupports() {
74 return false;
75 }
76
77 public String getDefaultSchemaName(DatabaseMetaData databaseMetaData) {
78 return null;
79 }
80
81 public void createTable(DbTable table) {
82 throw new DbRevisionException("not implemented");
83 }
84
85 public void createForeignKey(DbTable view) {
86 }
87
88 public void dropTable(DbTable table) {
89 }
90
91 public void dropTable(String nameTable) {
92 }
93
94 public void dropSequence(String nameSequence) {
95 }
96
97 public void dropConstraint(DbForeignKey impPk) {
98 }
99
100 public void addColumn(DbTable table, DbField field) {
101 }
102
103 public String getOnDeleteSetNull() {
104 return null;
105 }
106
107 public String getDefaultTimestampValue() {
108 return "SYSDATE";
109 }
110
111 public List<DbView> getViewList(String schemaPattern, String tablePattern) {
112 return DatabaseManager.getViewList(getConnection(), schemaPattern, tablePattern);
113 }
114
115 public List<DbSequence> getSequnceList(String schemaPattern) {
116 return new ArrayList<DbSequence>();
117 }
118
119 public String getViewText(DbView view) {
120 return null;
121 }
122
123 public void createView(DbView view) {
124 if (view == null ||
125 view.getName() == null || view.getName().length() == 0 ||
126 view.getText() == null || view.getText().length() == 0
127 )
128 return;
129
130 String sql_ = "create VIEW " + view.getName() + " as " + view.getText();
131 PreparedStatement ps = null;
132 try {
133 ps = this.getConnection().prepareStatement(sql_);
134 ps.executeUpdate();
135 }
136 catch (SQLException e) {
137 throw new DbRevisionException(e);
138 } finally {
139 DbUtils.close(ps);
140 ps = null;
141 }
142 }
143
144 public void createSequence(DbSequence seq) {
145 }
146
147 public void setLongVarbinary(PreparedStatement ps, int index, DbDataFieldData fieldData) {
148 try {
149 ps.setNull(index, Types.LONGVARBINARY);
150 }
151 catch (SQLException e) {
152 throw new DbRevisionException(e);
153 }
154 }
155
156 public void setLongVarchar(PreparedStatement ps, int index, DbDataFieldData fieldData) {
157 try {
158 ps.setNull(index, Types.LONGVARCHAR);
159 }
160 catch (SQLException e) {
161 throw new DbRevisionException(e);
162 }
163 }
164
165 public String getClobField(ResultSet rs, String nameField) {
166 return getClobField(rs, nameField, 20000);
167 }
168
169 public byte[] getBlobField(ResultSet rs, String nameField, int maxLength) {
170 try {
171 Blob blob = rs.getBlob(nameField);
172 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
173 int count;
174 byte buffer[] = new byte[1024];
175
176 InputStream inputStream = blob.getBinaryStream();
177 while ((count = inputStream.read(buffer)) >= 0) {
178 outputStream.write(buffer, 0, count);
179 outputStream.flush();
180 }
181 outputStream.close();
182 return outputStream.toByteArray();
183 }
184 catch (Exception e) {
185 throw new DbRevisionException(e);
186 }
187 }
188
189 public String getClobField(ResultSet rs, String nameField, int maxLength) {
190 return "";
191
192
193
194
195
196
197
198
199 }
200
201 public boolean testExceptionTableNotFound(Exception e) {
202
203 if ((e instanceof SQLException) &&
204 (e.toString().indexOf("ORA-00942") != -1))
205 return true;
206 return false;
207 }
208
209 public boolean testExceptionIndexUniqueKey(Exception e, String index) {
210 if ((e instanceof SQLException) &&
211 ((e.toString().indexOf("ORA-00001") != -1) &&
212 (e.toString().indexOf(index) != -1)))
213
214 return true;
215
216 return false;
217 }
218
219 public boolean testExceptionIndexUniqueKey(Exception e) {
220 return false;
221 }
222
223 public boolean testExceptionTableExists(Exception e) {
224 return false;
225 }
226
227 public boolean testExceptionViewExists(Exception e) {
228 return false;
229 }
230
231 public boolean testExceptionSequenceExists(Exception e) {
232 return false;
233 }
234
235 public boolean testExceptionConstraintExists(Exception e) {
236 return false;
237 }
238
239
240
241
242
243 public Family getFamily() {
244 return Family.MAXDB;
245 }
246
247 public void setBlobField(String tableName, String fieldName, byte[] bytes, String whereQuery, Object[] objects, int[] fieldTyped) {
248
249 }
250
251 public MaxDBDatabase(Connection conn) {
252 super(conn);
253 }
254 }