View Javadoc
1   package de.fhdw.wtf.persistence.facade;
2   
3   import java.io.IOException;
4   
5   import de.fhdw.wtf.persistence.exception.ClassFacadeUninitializedException;
6   import de.fhdw.wtf.persistence.exception.PersistenceException;
7   import de.fhdw.wtf.persistence.utils.PropertiesReader;
8   
9   /**
10   * This is the Interface that will connect to a database, create and return the ObjectFacade and the ClassFacade.
11   */
12  public abstract class DatabaseManager {
13  	
14  	/**
15  	 * Loads the configuration from a given file.
16  	 * 
17  	 * @param reader
18  	 *            The reader where the connection properties are stored.
19  	 * @throws IOException
20  	 */
21  	public abstract void setConnectionConstantsFromFile(PropertiesReader reader) throws IOException;
22  	
23  	/**
24  	 * Connects to the Database with the given Information. After the successful execution of this method, it is
25  	 * possible to get Access to the default connection.
26  	 * 
27  	 * @throws PersistenceException
28  	 *             If the Database is not accessible or the given credentials were wrong, a Persistence Exception will
29  	 *             be thrown.
30  	 * 
31  	 */
32  	public abstract void connect() throws PersistenceException;
33  	
34  	/**
35  	 * Returns the class facade that works with this manager.
36  	 * 
37  	 * @return The class facade
38  	 */
39  	public abstract ClassFacade getClassFacade();
40  	
41  	/**
42  	 * Returns the object facade that works with this manager.
43  	 * 
44  	 * @return The object facade
45  	 * @throws ClassFacadeUninitializedException
46  	 *             thrown if the facade is not initialized
47  	 */
48  	public abstract ObjectFacade getObjectFacade() throws ClassFacadeUninitializedException;
49  	
50  	/**
51  	 * This Method closes the connection with the database. It should be invoked at last.
52  	 * 
53  	 * @throws PersistenceException
54  	 *             A Persistence Exception is thrown if something on the database side goes wrong.
55  	 */
56  	public abstract void disconnect() throws PersistenceException;
57  	
58  	/**
59  	 * Checks if the manager is connected.
60  	 * 
61  	 * @return Provides true whether connect has been successfully invoked or not.
62  	 */
63  	public abstract boolean isConnected();
64  	
65  	/**
66  	 * Clears the database. Recreates the database-schema and creates database-procedures if necessary.
67  	 * 
68  	 * @throws PersistenceException
69  	 *             if access to database failed.
70  	 * @throws IOException
71  	 *             will be thrown if a file is not accessible.
72  	 */
73  	public abstract void resetDatabase() throws PersistenceException, IOException;
74  	
75  	/**
76  	 * Clears all database tables.
77  	 * 
78  	 * @throws PersistenceException
79  	 *             access to database failed
80  	 */
81  	public abstract void clearTables() throws PersistenceException;
82  }