]> git.mxchange.org Git - jfinancials-swing.git/blobdiff - src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java
Updated jcore + added more thrown exceptions + catched them
[jfinancials-swing.git] / src / org / mxchange / addressbook / database / frontend / contact / AddressbookContactDatabaseFrontend.java
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);