View Javadoc

1   /*
2    * org.riverock.dbrevision - Database revision engine
3    * For more information about DbRevision, please visit project site
4    * http://www.riverock.org
5    *
6    * Copyright (C) 2006-2006, Riverock Software, All Rights Reserved.
7    *
8    * Riverock - The Open-source Java Development Community
9    * http://www.riverock.org
10   *
11   *
12   * This library is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU Lesser General Public
14   * License as published by the Free Software Foundation; either
15   * version 2.1 of the License, or (at your option) any later version.
16   *
17   * This library is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25   */
26  package org.riverock.dbrevision.db;
27  
28  import java.sql.Connection;
29  import java.sql.PreparedStatement;
30  import java.sql.ResultSet;
31  import java.sql.DatabaseMetaData;
32  import java.util.List;
33  
34  import org.riverock.dbrevision.annotation.schema.db.DbDataFieldData;
35  import org.riverock.dbrevision.annotation.schema.db.DbField;
36  import org.riverock.dbrevision.annotation.schema.db.DbForeignKey;
37  import org.riverock.dbrevision.annotation.schema.db.DbSequence;
38  import org.riverock.dbrevision.annotation.schema.db.DbTable;
39  import org.riverock.dbrevision.annotation.schema.db.DbView;
40  
41  /**
42   * Database
43   *
44   * $Revision: 1141 $ $Date: 2006-12-14 17:43:29 +0300 (Чт, 14 дек 2006) $
45   */
46  public abstract class Database {
47      private Connection conn = null;
48  
49      /**
50       * Database family
51       */
52      public enum Family {
53          ORACLE, MYSQL, DB2, SQLSERVER, HYPERSONIC, MAXDB, INTERBASE, POSTGREES
54      }
55  
56      /**
57       * Constructor
58       *
59       * @param conn connection
60       */
61      public Database(Connection conn) {
62          this.conn = conn;
63      }
64  
65      public void setConnection(Connection conn) {
66          this.conn = conn;
67      }
68  
69      /**
70       * Get jdbc connection
71       *
72       * @return connection
73       */
74      public Connection getConnection() {
75          return conn;
76      }
77  
78      /**
79       * get family for this adapter
80       * @return family
81       */
82      public abstract Family getFamily();
83  
84      abstract public void setBlobField(
85          String tableName, String fieldName, byte[] bytes,
86          String whereQuery,
87          Object[] objects, int[] fieldTyped
88      );
89  
90      /**
91       * Is this db support batch update?
92       *
93       * @return true if support
94       */
95      public abstract boolean isBatchUpdate();
96  
97      public abstract boolean isNeedUpdateBracket();
98  
99      public abstract boolean isByteArrayInUtf8();
100 
101     public abstract boolean isSchemaSupports();
102 
103     public abstract String getDefaultSchemaName(DatabaseMetaData databaseMetaData);
104 
105     public abstract String getClobField(ResultSet rs, String nameFeld);
106 
107     public abstract byte[] getBlobField(ResultSet rs, String nameField, int maxLength);
108 
109     public abstract void createTable(DbTable table);
110 
111     public abstract void createView(DbView view);
112 
113     public abstract void createSequence(DbSequence seq);
114 
115     public abstract void dropTable(DbTable table);
116 
117     public abstract void dropTable(String nameTable);
118 
119     public abstract void dropSequence(String nameSequence);
120 
121     public abstract void dropConstraint(DbForeignKey impPk);
122 
123     public abstract void addColumn(DbTable table, DbField field);
124 
125     public abstract void createForeignKey(DbTable view);
126 
127     public abstract String getOnDeleteSetNull();
128 
129     public abstract String getDefaultTimestampValue();
130 
131     public abstract List<DbView> getViewList(String schemaPattern, String tablePattern);
132 
133     public abstract List<DbSequence> getSequnceList(String schemaPattern);
134 
135     public abstract String getViewText(DbView view);
136 
137     public abstract void setLongVarbinary(PreparedStatement ps, int index, DbDataFieldData fieldData);
138 
139     public abstract void setLongVarchar(PreparedStatement ps, int index, DbDataFieldData fieldData);
140 
141     /**
142      * @param rs result set
143      * @param nameFeld name of field
144      * @param maxLength max length of CLOB field
145      * @return value of specific table columns
146      */
147     public abstract String getClobField(ResultSet rs, String nameFeld, int maxLength);
148 
149     public abstract boolean testExceptionTableNotFound(Exception e);
150 
151     public abstract boolean testExceptionIndexUniqueKey(Exception e, String index);
152 
153     public abstract boolean testExceptionIndexUniqueKey(Exception e);
154 
155     public abstract boolean testExceptionTableExists(Exception e);
156 
157     public abstract boolean testExceptionViewExists(Exception e);
158 
159     public abstract boolean testExceptionSequenceExists(Exception e);
160 
161     public abstract boolean testExceptionConstraintExists(Exception e);
162 
163     /**
164      * @return - int. Max size of char field
165      */
166     public abstract int getMaxLengthStringField();
167 }