View Javadoc
1   package fr.ifremer.quadrige3.core.dao.technical;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Core Shared
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.quadrige3.core.exception.DatabaseSchemaUpdateException;
27  import fr.ifremer.quadrige3.core.exception.VersionNotFoundException;
28  import org.nuiton.version.Version;
29  
30  import java.io.File;
31  import java.io.IOException;
32  import java.util.Properties;
33  
34  
35  /**
36   * <p>DatabaseSchemaDao interface.</p>
37   */
38  public interface DatabaseSchemaDao {
39  
40      /**
41       * Generate a file with all SQL for database creation
42       *
43       * @param filename full path of the file to generate
44       */
45      void generateCreateSchemaFile(String filename);
46  
47      /**
48       * <p>generateCreateSchemaFile.</p>
49       *
50       * @param filename   The file to generate, or null if only execution is need
51       * @param doExecute  The SQL script must be execute on database ?
52       * @param withDrop   generate drop statement ?
53       * @param withCreate generate create statement ?
54       */
55      void generateCreateSchemaFile(String filename, boolean doExecute, boolean withDrop, boolean withCreate);
56  
57      /**
58       * Generate a file with update SQL statement.
59       * SQL statements will NOT be executed on database
60       *
61       * @param filename a {@link java.lang.String} object.
62       */
63      void generateUpdateSchemaFile(String filename);
64  
65      /**
66       * Generate a file with update SQL statement, and/or execute it on database.
67       *
68       * @param filename The file to generate, or null if only execution on database is need
69       * @param doUpdate true if execution is need on database
70       */
71      void generateUpdateSchemaFile(String filename, boolean doUpdate);
72  
73      /**
74       * Execute all changes need on database schema
75       *
76       * @throws DatabaseSchemaUpdateException if could not update schema
77       * @since 1.0
78       */
79      void updateSchema() throws DatabaseSchemaUpdateException;
80  
81  
82      /**
83       * Execute all changes need on database schema, from the given connection
84       *
85       * @param connectionProperties the connection properties. If null, will use default (see config.getConnectionProperties())
86       * @throws DatabaseSchemaUpdateException if could not update schema
87       * @since 1.0
88       */
89      void updateSchema(Properties connectionProperties) throws DatabaseSchemaUpdateException;
90  
91      /**
92       * Execute all changes need on database schema, from the given DB directory
93       *
94       * @param dbDirectory the DB directory. If null, will use default (see config.getConnectionProperties())
95       * @throws DatabaseSchemaUpdateException if could not update schema
96       * @since 1.0
97       */
98      void updateSchema(File dbDirectory) throws DatabaseSchemaUpdateException;
99  
100     /**
101      * Retrieve the schema version, from table SYSTEM_VERSION,
102      *
103      * @return The database version (i.e. '3.2.3' @see Version)
104      * @throws VersionNotFoundException if the version could not be found, or has a bad format
105      * @since 1.0
106      */
107     Version getSchemaVersion() throws VersionNotFoundException;
108 
109     /**
110      * Get the database schema version if updates is apply
111      * (the version that the database should have if updateSchema() was called)
112      *
113      * @return The database version (i.e. '3.2.3' @see Version)
114      * @since 1.0
115      */
116     Version getSchemaVersionIfUpdate();
117 
118     /**
119      * Check if a update schema if need
120      * This is equivalent to : <code>getSchemaVersion().compareTo(getSchemaVersionIfUpdate()) >= 0</code>
121      *
122      * @return true if a update is need
123      * @since 1.0
124      * @throws VersionNotFoundException if any.
125      */
126     boolean shouldUpdateSchema() throws VersionNotFoundException;
127     
128     /**
129      * Check if connection could be open.
130      * If a validation query has been set in configuration, test it
131      *
132      * @return if db is loaded
133      */
134     boolean isDbLoaded();
135     
136     /**
137      * Check if db files exists. If not a database file, return true
138      *
139      * @return if db files exists
140      */
141     boolean isDbExists();
142     
143     /**
144      * Report into a file the liquibase status of database
145      *
146      * @param outputFile a {@link java.io.File} object.
147      * @throws java.io.IOException if any.
148      */
149     void generateStatusReport(File outputFile) throws IOException;
150     
151     /**
152      * Generate a diff of database
153      *
154      * @param typesToControl a comma separated database object to check (i.e Table, View, Column...). If null, all types are checked
155      * @param outputFile a {@link java.io.File} object.
156      */
157     void generateDiffReport(File outputFile, String typesToControl);
158     
159     /**
160      * Generate a diff change log
161      *
162      * @param typesToControl a comma separated database object to check (i.e Table, View, Column...). If null, all types are checked
163      * @param outputChangelogFile a {@link java.io.File} object.
164      */
165     void generateDiffChangeLog(File outputChangelogFile, String typesToControl);
166     
167     /**
168      * Generate a new DB directory
169      *
170      * @param dbDirectory a {@link java.io.File} object.
171      * @param replaceIfExists a boolean.
172      */
173     void generateNewDb(File dbDirectory, boolean replaceIfExists);
174 
175     /**
176      * Generate a new DB directory with the specified script and connection properties
177      *
178      * @param dbDirectory a {@link java.io.File} object.
179      * @param replaceIfExists a boolean.
180      * @param scriptFile a file with the HSQLDB script (e.g. quadrige3.script), or null for default script file
181      * @param connectionProperties a {@link java.util.Properties} object.
182      * @param isTemporaryDb is target DB is temporay DB (for synchro), some changes are done (e.g. TEMP_QUERY_PARAMETER table)
183      */
184     void generateNewDb(File dbDirectory, boolean replaceIfExists, File scriptFile, Properties connectionProperties, boolean isTemporaryDb);
185 }