]> git.mxchange.org Git - jaddressbook-lib.git/blobdiff - src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java
Continued:
[jaddressbook-lib.git] / src / org / mxchange / addressbook / facade / contact / AddressbookContactFacade.java
index ce6d43ac3fc0832a1e4c6a4a02cea0cac781836c..105bec45ffb3919b4d7b0d8e66039b39f645db8d 100644 (file)
@@ -24,6 +24,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
 import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcontacts.contact.Contact;
@@ -47,6 +49,12 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         */
        private final List<String> columnNames;
 
+       /**
+        * Entity manager
+        */
+       @PersistenceContext
+       private EntityManager entityManager;
+
        /**
         * Logger instance
         */
@@ -78,10 +86,6 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                // Set client instance
                this.setClient(client);
 
-               // Init database connection
-               DatabaseFrontend frontend = new AddressbookContactDatabaseFrontend(this);
-               this.setFrontend(frontend);
-
                // Initialize list
                this.columnNames = new ArrayList<>(15);
                this.translatedColumnNames = new ArrayList<>(15);
@@ -105,7 +109,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Add it
-               ((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
+               this.entityManager.persist(contact);
 
                // Trace message
                this.getLogger().logTrace("EXIT!"); //NOI18N
@@ -303,7 +307,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Shut down the database layer
-               ((AddressbookContactFrontend) this.getFrontend()).doShutdown();
+               this.entityManager.close();
 
                // Trace message
                this.getLogger().logTrace("EXIT!"); //NOI18N
@@ -328,7 +332,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
 
-               return client.enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
+               return client.enterString(3, 50, "Bitte geben Sie Ihren Wohnort ein: ", false);
        }
 
        @Override
@@ -549,7 +553,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
                try {
                        // Check if contact is found
-                       if (((AddressbookContactFrontend) this.getFrontend()).isContactFound(contact)) {
+                       if (this.entityManager.contains(contact)) {
                                // Contact already added
                                // TODO Do something here
                        } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
@@ -559,7 +563,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
 
                        // Add contact to internal list
                        this.addContact(contact);
-               } catch (final ContactAlreadyAddedException | SQLException | IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+               } catch (final ContactAlreadyAddedException | IOException ex) {
                        // Abort here
                        this.abortProgramWithException(ex);
                }
@@ -570,7 +574,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
 
        /**
         * Logs given exception and exits program
-        *
+        * <p>
         * @param throwable Throwable
         */
        private void abortProgramWithException (Throwable throwable) {
@@ -628,7 +632,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
 
        /**
         * Getter for logger instance
-        *
+        * <p>
         * @return Logger instance
         */
        private LoggerBeanLocal getLogger () {
@@ -639,18 +643,14 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         * "Getter" for own contact instance or null if not found
         * <p>
         * @return Contact instance or null
-        * @throws java.sql.SQLException If an SQL error occurs
-        * @throws java.io.IOException If an IO error occurs
-        * @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 () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+       private Contact getOwnContact () {
                // Trace message
                this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Deligate this call to database frontend
-               Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact();
+               Contact contact = null;
+               //Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact();
 
                // Trace message
                this.getLogger().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N