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;
*/
private final List<String> columnNames;
+ /**
+ * Entity manager
+ */
+ @PersistenceContext
+ private EntityManager entityManager;
+
/**
* Logger instance
*/
// 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);
}
// Add it
- ((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
+ this.entityManager.persist(contact);
// Trace message
this.getLogger().logTrace("EXIT!"); //NOI18N
this.getLogger().logTrace("CALLED!"); //NOI18N
// Shut down the database layer
- ((AddressbookContactFrontend) this.getFrontend()).doShutdown();
+ this.entityManager.close();
// Trace message
this.getLogger().logTrace("EXIT!"); //NOI18N
// 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
}
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())) {
// 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);
}
/**
* Logs given exception and exits program
- *
+ * <p>
* @param throwable Throwable
*/
private void abortProgramWithException (Throwable throwable) {
/**
* Getter for logger instance
- *
+ * <p>
* @return Logger instance
*/
private LoggerBeanLocal getLogger () {
* "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