]> git.mxchange.org Git - addressbook-swing.git/blobdiff - Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java
Fixes for missing throws statements (because jcore has changed).
[addressbook-swing.git] / Addressbook / src / org / mxchange / addressbook / database / frontend / contact / AddressbookContactDatabaseFrontend.java
index 7442ef72dac20a88cf966e4fc99c4ff33cadd09d..25e2bf87b52a5607f8e320beca802a7b9baaef6b 100644 (file)
@@ -28,7 +28,10 @@ import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
 import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.criteria.searchable.SearchCriteria;
+import org.mxchange.jcore.criteria.searchable.SearchableCritera;
 import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.jcore.database.result.Result;
 import org.mxchange.jcore.database.storage.Storeable;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
@@ -44,8 +47,10 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
         * Constructor which accepts a contact manager
         *
         * @param manager Manager instance
+        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported
+        * @throws java.sql.SQLException If any SQL error occurs
         */
-       public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) {
+       public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) throws UnsupportedDatabaseBackendException, SQLException {
                // Call own constructor
                this();
 
@@ -63,25 +68,19 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
        }
 
        /**
-        * Basic constrcutor
+        * Default but protected constructor
+        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported
+        * @throws java.sql.SQLException Any SQL exception from e.g. MySQL connector
         */
-       protected AddressbookContactDatabaseFrontend () {
+       protected AddressbookContactDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
                // Set "table" name
                this.setTableName("contacts"); //NOI18N
 
-               try {
-                       // Initalize backend
-                       this.initBackend();
-               } catch (final UnsupportedDatabaseBackendException ex) {
-                       // Abort program
-                       this.abortProgramWithException(ex);
-               } catch (final SQLException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               }
+               // Initalize backend
+               this.initBackend();
        }
 
        /**
@@ -110,10 +109,7 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
 
                        // Then add it
                        this.getBackend().store((Storeable) contact);
-               } catch (final IOException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               } catch (final BadTokenException ex) {
+               } catch (final IOException | BadTokenException ex) {
                        // Abort here
                        this.abortProgramWithException(ex);
                }
@@ -232,11 +228,22 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
         * Checks whether own contact is found in database
         *
         * @return Whether own contact is found
+        * @throws java.io.IOException If any IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
         */
        @Override
-       public boolean isOwnContactFound () throws SQLException {
+       public boolean isOwnContactFound () throws SQLException, IOException, BadTokenException {
+               // Get search criteria instance
+               SearchableCritera critera = new SearchCriteria();
+
+               // Add condition
+               critera.addCriteria(AddressbookContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
+
+               // Get result
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(critera);
+
                // Deligate this call to backend
-               return this.getBackend().isRowFound(AddressbookContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
+               return result.hasNext();
        }
 
        /**
@@ -376,9 +383,9 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp
                        this.getLogger().debug(MessageFormat.format("strippedToken={0},num={1},bool={2}", strippedToken, num, bool)); //NOI18N
 
                        // Now, let's try a gender check, if no null
-                       if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) { //NOI18N
+                       if ((strippedToken != null) && (num == null) && (bool == null) && (Gender.valueOf(strippedToken) instanceof Gender)) { //NOI18N
                                // Get first character
-                               gender = Gender.fromChar(strippedToken.charAt(0));
+                               gender = Gender.valueOf(strippedToken);
 
                                // Debug message
                                this.getLogger().debug(MessageFormat.format("strippedToken={0},gender={1}", strippedToken, gender)); //NOI18N