View Javadoc
1   package net.sumaris.core.service.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  
28  
29  
30  import net.sumaris.core.exception.VersionNotFoundException;
31  import org.nuiton.version.Version;
32  import org.springframework.transaction.annotation.Transactional;
33  
34  import java.io.File;
35  import java.io.IOException;
36  
37  /**
38   * <p>DatabaseSchemaService interface.</p>
39   *
40   */
41  @Transactional(readOnly = true)
42  public interface DatabaseSchemaService {
43  
44  	/**
45  	 * Return the version, stored in the database (e.g. in SYSTEM_VERSION table)
46  	 *
47  	 * @return a {@link Version} object.
48  	 */
49  	Version getDbVersion();
50  
51  	/**
52  	 * Return the version of the applciation. This version comes from database updates (e.g. liquibase patch)
53  	 *
54  	 * @return the version, or null if not patch available
55  	 */
56  	Version getApplicationVersion();
57  
58  	/**
59  	 * <p>updateSchema.</p>
60  	 */
61  	@Transactional()
62  	void updateSchema();
63  
64      /**
65       * Check if connection could be open.
66       * If a validation query has been set in configuration, test it
67       *
68       * @return if db is loaded
69       */
70      boolean isDbLoaded();
71  
72      /**
73       * Check if db files exists. If not a database file, return true
74       *
75       * @return if db files exists
76       */
77      boolean isDbExists();
78  
79      /**
80       * Report into a file the liquibase status of database
81       *
82       * @param outputFile a {@link File} object.
83       * @throws IOException if any.
84       */
85      void generateStatusReport(File outputFile) throws IOException;
86  
87      /**
88       * Generate a diff report, from Hibernate model to database
89       *
90       * @param outputFile a {@link File} object.
91       */
92      void generateDiffReport(File outputFile);
93  
94      /**
95       * Generate a diff changelog, from Hibernate model to database
96       *
97       * @param outputFile a {@link File} object.
98       */
99  	@Transactional(readOnly = true)
100     void generateDiffChangeLog(File outputFile);
101 
102     /**
103      * <p>export schema creation SQL to file</p>
104      *
105      * @param outputFile a {@link File} object.
106      * @param withDrop a boolean.
107      * @throws IOException if any.
108      */
109     void createSchemaToFile(File outputFile, boolean withDrop) throws IOException;
110 
111 	/**
112 	 * <p>export schema update to file</p>
113 	 *
114 	 * @param outputFile a {@link File} object.	 *
115 	 * @throws IOException if any.
116 	 */
117 	void updateSchemaToFile(File outputFile) throws IOException;
118 }