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