]> git.mxchange.org Git - jfinancials-swing.git/commitdiff
Updated jcore + added more thrown exceptions + catched them
authorRoland Haeder <roland@mxchange.org>
Mon, 24 Aug 2015 12:18:10 +0000 (14:18 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 24 Aug 2015 12:18:10 +0000 (14:18 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcore.jar
src/org/mxchange/addressbook/client/console/ConsoleClient.java
src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java
src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java
src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java
src/org/mxchange/addressbook/manager/contact/ManageableAddressbookContact.java

index d426e0dec31b4479bf275fbb9cc6ca3ba25ffd7c..5a46f43c19df0400e7fd341521152ed3a8d56f59 100644 (file)
Binary files a/lib/jcore.jar and b/lib/jcore.jar differ
index a9c81cbf6fe60756c42a400ea5348dfdf920e126..06a6cc2b4d2a58f24948d78ef9ce79724d105a85 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.addressbook.client.console;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Arrays;
@@ -36,6 +37,7 @@ import org.mxchange.jcore.application.Application;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
 import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 
@@ -381,21 +383,20 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                                        manager.doDeleteOtherAddress();
                                        break;
 
-                       case '0': {
-                       try {
-                               // Program exit
-                               this.getApplication().doShutdown();
-                       } catch (final SQLException | IOException ex) {
-                               this.abortProgramWithException(ex);
-                       }
-               }
+                       case '0':
+                               try {
+                                       // Program exit
+                                       this.getApplication().doShutdown();
+                               } catch (final SQLException | IOException ex) {
+                                       this.abortProgramWithException(ex);
+                               }
                                break;
 
                                default:
                                        // @TODO throw own exception
                                        throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N
                        }
-               } catch (final IOException | BadTokenException ex) {
+               } catch (final IOException | BadTokenException | CorruptedDatabaseFileException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
                        // Something bad happened
                        this.abortProgramWithException(ex);
                }
index 4bdb6e98baecf355f982dea847539d6225b190ef..73dc71a1148e0bc85f2d1c7ca518975e0594d936 100644 (file)
@@ -25,6 +25,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import javax.swing.BorderFactory;
@@ -55,6 +56,7 @@ import org.mxchange.jcore.client.gui.ClientFrame;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
 import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
 import org.mxchange.jcore.model.swing.contact.ContactTableModel;
 
@@ -708,7 +710,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                                ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
                                try {
                                        manager.doChangeOwnData();
-                               } catch (final IOException | BadTokenException ex) {
+                               } catch (final IOException | BadTokenException | CorruptedDatabaseFileException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
                                        self.logException(ex);
                                }
                        }
index e51b94209566dae5ae8a970e23fade28283e57c1..25f84964d533664467cedb2ec25bd4644e31def0 100644 (file)
@@ -175,31 +175,43 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
                return AddressbookContactDatabaseConstants.COLUMN_ID;
        }
 
-       /**
-        * Some "getter" for own contact instance
-        *
-        * @return Own contact instance
-        */
        @Override
-       public Contact getOwnContact () {
+       public Contact getOwnContact () throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
-               // Get row index back from backend
-               int rowIndex = this.getBackend().getRowIndexFromColumn(AddressbookContactDatabaseConstants.COLUMN_OWN_CONTACT, true);
+               // Prepare search instance
+               SearchableCriteria criteria = new SearchCriteria();
+
+               // Add criteria and limit
+               criteria.addCriteria(AddressbookContactDatabaseConstants.COLUMN_OWN_CONTACT, true);
+               criteria.setLimit(1);
+
+               // Then search for it
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("rowIndex={0}", rowIndex));
+               this.getLogger().debug(MessageFormat.format("result={0}", result));
 
                // Init instance
                Contact contact = null;
 
-               try {
-                       // Now simply read the row
-                       contact = (Contact) this.getBackend().readRow(rowIndex);
-               } catch (final BadTokenException ex) {
-                       // Bad token found
-                       this.abortProgramWithException(ex);
+               // Is there one row at least?
+               if (result.hasNext()) {
+                       // Then get it
+                       Storeable storeable = result.next();
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("storeable={0}", storeable));
+
+                       // Is it same instance?
+                       if (!(storeable instanceof Contact)) {
+                               // Not same instance
+                               throw new IllegalArgumentException(MessageFormat.format("storeable={0} is not implementing Contact", storeable));
+                       }
+
+                       // Cast it securely
+                       contact = (Contact) storeable;
                }
 
                // Trace message
@@ -209,6 +221,11 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
                return contact;
        }
 
+       @Override
+       public Storeable getStoreableAtRow (final int rowIndex) {
+               throw new UnsupportedOperationException("Not supported yet: rowIndex=" + rowIndex);
+       }
+
        /**
         * Checks if given Contact is found
         * 
@@ -280,26 +297,6 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
                return result.hasNext();
        }
 
-       /**
-        * Reads a single row and parses it to a contact instance
-        *
-        * @param rowIndex Row index (also how much to skip)
-        * @return Contact instance
-        */
-       @Override
-       public Contact readSingleContact (final int rowIndex) {
-               try {
-                       // Deligate this to backend instance
-                       return (Contact) this.getBackend().readRow(rowIndex);
-               } catch (final BadTokenException ex) {
-                       // Bad token found
-                       this.abortProgramWithException(ex);
-               }
-
-               // Bad state, should not be reached
-               throw new IllegalStateException("This should not be reached");
-       }
-
        @Override
        public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                throw new UnsupportedOperationException("Not supported yet: map=" + map);
index d1c46b7a96d6269f4e8da4491ecb89a1629790fb..b06940a2fee4423e92fbbec1de2231def57e42a0 100644 (file)
@@ -68,8 +68,15 @@ public interface AddressbookContactFrontend extends DatabaseFrontend {
         * Some "getter" for own contact instance
         *
         * @return Own contact instance
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.io.IOException If an IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException Continued throw
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws java.lang.NoSuchMethodException If a method cannot be found
+        * @throws java.lang.IllegalAccessException If a method is not accessible
+        * @throws java.lang.reflect.InvocationTargetException Any other problems?
         */
-       public Contact getOwnContact ();
+       public Contact getOwnContact () throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Checks whether own contact is found
@@ -84,12 +91,4 @@ public interface AddressbookContactFrontend extends DatabaseFrontend {
         * @throws java.lang.reflect.InvocationTargetException Any other problems?
         */
        public boolean isOwnContactFound () throws SQLException, IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
-
-       /**
-        * Reads a single row and parses it to a contact instance
-        *
-        * @param rowIndex Row index (also how much to skip)
-        * @return Contact instance
-        */
-       public Contact readSingleContact (final int rowIndex);
 }
index d928695d982cd359ed03d69f63e59f0849a98c70..fd2a5388e5aad3a7776f3693d546cd2a3013097d 100644 (file)
@@ -31,6 +31,8 @@ import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcore.client.Client;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.database.frontend.DatabaseFrontend;
+import org.mxchange.jcore.database.storage.Storeable;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
@@ -50,11 +52,6 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         */
        private final List<String> columnNames;
 
-       /**
-        * A AddressbookContactFrontend instance
-        */
-       private final AddressbookContactFrontend contactDatabase;
-
        /**
         * Translated column name list
         */
@@ -82,7 +79,8 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                this.setClient(client);
 
                // Init database connection
-               this.contactDatabase = new AddressbookContactDatabaseFrontend(this);
+               DatabaseFrontend frontend = new AddressbookContactDatabaseFrontend(this);
+               this.setFrontend(frontend);
 
                // Initialize list
                this.columnNames = new ArrayList<>(15);
@@ -112,7 +110,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Add it
-               this.getContactDatabase().addContact(contact);
+               ((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
 
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
@@ -244,7 +242,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         * Allows the user to change his/her own data
         */
        @Override
-       public void doChangeOwnData () throws IOException , BadTokenException{
+       public void doChangeOwnData () throws IOException , BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -343,7 +341,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                this.getLogger().trace("CALLED!"); //NOI18N
 
                // Shut down the database layer
-               this.getContactDatabase().doShutdown();
+               ((AddressbookContactFrontend) this.getFrontend()).doShutdown();
 
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
@@ -477,6 +475,22 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                return client.enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
        }
 
+       /**
+        * Asks the user for surname
+        *
+        * @return Surname of the user
+        */
+       @Override
+       public String enterOwnFirstName () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+               
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+               
+               return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
+       }
+
        /**
         * Asks the user for gender, until a valid has been entered
         *
@@ -525,22 +539,6 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                return client.enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
        }
 
-       /**
-        * Asks the user for surname
-        *
-        * @return Surname of the user
-        */
-       @Override
-       public String enterOwnFirstName () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
-       }
-
        /**
         * Asks the user for own ZIP code
         *
@@ -605,13 +603,13 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                this.getLogger().trace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex));
 
                // Then get specific row from database which is a Contact instance
-               Contact contact = this.getContactDatabase().readSingleContact(rowIndex);
+               Storeable storeable = this.getFrontend().getStoreableAtRow(rowIndex);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
+               this.getLogger().debug(MessageFormat.format("storeable={0}", storeable));
 
                // It may return null
-               if (contact == null) {
+               if (storeable == null) {
                        // Nothing found
                        this.getLogger().warn("contact is null - returning null ...");
                        return null;
@@ -626,7 +624,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                // Now get that column
                Object value = null;
                try {
-                       value = contact.getValueFromColumn(columnName);
+                       value = storeable.getValueFromColumn(columnName);
                } catch (final IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
                        this.abortProgramWithException(ex);
                }
@@ -654,7 +652,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
 
                try {
                        // Deligate this call to frontend
-                       isAdded = this.getContactDatabase().isOwnContactFound();
+                       isAdded = ((AddressbookContactFrontend) this.getFrontend()).isOwnContactFound();
                } catch (final SQLException | IOException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
                        // Something bad happened
                        this.abortProgramWithException(ex);
@@ -688,7 +686,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                        /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getFirstName(), contact.getFamilyName(), this.size())); //NOI18N
 
                // Check if contact is found
-                       if (this.getContactDatabase().isContactFound(contact)) {
+                       if (((AddressbookContactFrontend) this.getFrontend()).isContactFound(contact)) {
                                // Contact already added
                                // @todo Do something here
                        } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
@@ -713,7 +711,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                int size = -1;
 
                try {
-                       size = this.getContactDatabase().getContactsCount();
+                       size = ((AddressbookContactFrontend) this.getFrontend()).getContactsCount();
                } catch (final SQLException ex) {
                        // Something happened
                        this.abortProgramWithException(ex);
@@ -768,26 +766,24 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
        }
 
-       /**
-        * A AddressbookContactFrontend instance
-        *
-        * @return the database
-        */
-       private AddressbookContactFrontend getContactDatabase () {
-               return this.contactDatabase;
-       }
-
        /**
         * "Getter" for own contact instance or null if not found
         *
         * @return Contact instance or null
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.io.IOException If an IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException Continued throw
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws java.lang.NoSuchMethodException If a method cannot be found
+        * @throws java.lang.IllegalAccessException If a method is not accessible
+        * @throws java.lang.reflect.InvocationTargetException Any other problems?
         */
-       private Contact getOwnContact () {
+       private Contact getOwnContact () throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
                // Deligate this call to database frontend
-               Contact contact = this.getContactDatabase().getOwnContact();
+               Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact();
 
                // Trace message
                this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
index be13daa29141517f09377228711d0aa857e8d941..6a9bb1e828d73e0b94f2e9303a07268e89f29dbb 100644 (file)
 package org.mxchange.addressbook.manager.contact;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
 import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.manager.database.ManageableDatabase;
 
 /**
@@ -175,10 +178,15 @@ public interface ManageableAddressbookContact extends ManageableDatabase {
 
        /**
         * Let the user change own data
-        * @throws java.io.IOException If an IO error was found
-        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.io.IOException If an IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException Continued throw
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws java.lang.NoSuchMethodException If a method cannot be found
+        * @throws java.lang.IllegalAccessException If a method is not accessible
+        * @throws java.lang.reflect.InvocationTargetException Any other problems?
         */
-       public void doChangeOwnData () throws IOException , BadTokenException;
+       public void doChangeOwnData () throws IOException , BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Let the user delete other address