Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first of all, for code clarity, instead of writing</p> <pre><code> private DataPersistenceInterface DataDAO; </code></pre> <p>write :</p> <pre><code> private DataPersistenceInterface dataPersistenceInterface; </code></pre> <p>Always use camel case for java properties and with the same name of the class you are using. A best pratice would also be to name the implementation the same name of the interface plus a Impl:</p> <pre><code>DataPersistenceInterfaceImpl </code></pre> <p>It is a pattern problem, if you want to create a connection using the constructor of the Dao, you have three choices:</p> <p>1) You can add a closeConnection method to the DataPersistenceInterface interface by adding it to the interface signature:</p> <pre><code>public void closeConnection(); </code></pre> <p>2) But because the AppSystem class does know which implementation it uses to create the DataPersistenceInterface (DataDao), you can cast back the interface to the implementation. You will have your closeConnection() back. This would be my best guest.</p> <pre><code> public void closeConnection() { ((DataDAO)dataPersistenceInterface).closeConnection(); } </code></pre> <p>3) Depending of the usage of your AppSys, don't care about closing the connection. Put the close connection method in the finalize() method of the DataDAO implementation. The connection will be close when the AppSys application will end. </p> <pre><code>protected void finalize() throws Throwable { try{ connection.close; }catch(Exception e){ ... } } </code></pre> <p>The best pratice would be to use a ConnectionPool like c3po, or Apache ConnectionPool.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload