From: Roland Haeder Date: Fri, 2 Oct 2015 10:03:38 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b3fed99b3377cfb385500abf41decea7bf507aca;p=addressbook-lib.git Continued: - added jcontacts-business-core.jar (model/POJO/POJI for business contacts) - renamed jcontacts -> jcontacts-core - added persistence as the facade will do it (maybe this will be moved to EJB?) - moved exception to jcontacts-core - fixed imports Signed-off-by:Roland Häder --- diff --git a/lib/jcontacts-business-core.jar b/lib/jcontacts-business-core.jar new file mode 100644 index 0000000..6a1d4ef Binary files /dev/null and b/lib/jcontacts-business-core.jar differ diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar new file mode 100644 index 0000000..13b4e24 Binary files /dev/null and b/lib/jcontacts-core.jar differ diff --git a/lib/jcontacts.jar b/lib/jcontacts.jar deleted file mode 100644 index b2e362b..0000000 Binary files a/lib/jcontacts.jar and /dev/null differ diff --git a/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip new file mode 100644 index 0000000..fd55e6e Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip differ diff --git a/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar new file mode 100644 index 0000000..841d2e1 Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar differ diff --git a/nbproject/project.properties b/nbproject/project.properties index 8eb5de3..7e0ac8e 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,7 +30,8 @@ dist.jar=${dist.dir}/addressbook-lib.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.jcontacts.jar=lib/jcontacts.jar +file.reference.jcontacts-business-core.jar=lib\\jcontacts-business-core.jar +file.reference.jcontacts-core.jar=lib\\jcontacts-core.jar file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar file.reference.jcore-swing.jar=lib/jcore-swing.jar file.reference.jcore.jar=lib/jcore.jar @@ -42,7 +43,9 @@ javac.classpath=\ ${file.reference.jcore.jar}:\ ${file.reference.jcore-swing.jar}:\ ${file.reference.jcore-logger-lib.jar}:\ - ${file.reference.jcontacts.jar} + ${file.reference.jcontacts-core.jar}:\ + ${file.reference.jcontacts-business-core.jar}:\ + ${libs.jpa20-persistence.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:deprecation -Xlint:unchecked javac.deprecation=true @@ -91,7 +94,8 @@ run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 -source.reference.jcontacts.jar=../jcontacts/src/ +source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ +source.reference.jcontacts-core.jar=../jcontacts-core/src/ source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/ source.reference.jcore-swing.jar=../jcore-swing/src source.reference.jcore.jar=../jcore/src diff --git a/src/org/mxchange/addressbook/exceptions/ContactAlreadyAddedException.java b/src/org/mxchange/addressbook/exceptions/ContactAlreadyAddedException.java deleted file mode 100644 index 53e3ac0..0000000 --- a/src/org/mxchange/addressbook/exceptions/ContactAlreadyAddedException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.exceptions; - -import java.text.MessageFormat; -import org.mxchange.jcontacts.contact.Contact; - -/** - * Thrown if the given Contact instance is already added - *

- * @author Roland Haeder - */ -public class ContactAlreadyAddedException extends Exception { - - /** - * Serial number - */ - private static final long serialVersionUID = 75844851467L; - - /** - * Constructor with a Contact instance - *

- * @param contact Contact that is already added - */ - public ContactAlreadyAddedException (final Contact contact) { - super(MessageFormat.format("Contact with gender={0}, firstName={1} and familyName={2} already added.", contact.getGender(), contact.getFirstName(), contact.getFamilyName())); - } - - /** - * Default constructor, may be used if no contact instance is available - */ - public ContactAlreadyAddedException () { - super("Contact already added"); - } - -} diff --git a/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java b/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java index ce6d43a..105bec4 100644 --- a/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java +++ b/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java @@ -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 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 - * + *

* @param throwable Throwable */ private void abortProgramWithException (Throwable throwable) { @@ -628,7 +632,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad /** * Getter for logger instance - * + *

* @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 *

* @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 diff --git a/src/org/mxchange/addressbook/facade/contact/ContactFacade.java b/src/org/mxchange/addressbook/facade/contact/ContactFacade.java index 889ba78..7b206e8 100644 --- a/src/org/mxchange/addressbook/facade/contact/ContactFacade.java +++ b/src/org/mxchange/addressbook/facade/contact/ContactFacade.java @@ -19,9 +19,9 @@ package org.mxchange.addressbook.facade.contact; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; -import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcore.facade.Facade; /** @@ -35,7 +35,7 @@ public interface ContactFacade extends Facade { * Adds given Contact instance to list *

* @param contact Contact instance to add - * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact is already added + * @throws org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException If the contact is already added */ public void addContact (final Contact contact) throws ContactAlreadyAddedException; @@ -91,8 +91,7 @@ public interface ContactFacade extends Facade { /** * Asks user for own data *

- * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException - * If own contact is already added + * @throws org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException If own contact is already added * @throws java.io.IOException If an IO error was found */ public void doEnterOwnData () throws ContactAlreadyAddedException, IOException;