X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Addressbook%2Fsrc%2Forg%2Fmxchange%2Faddressbook%2Fdatabase%2Ffrontend%2Fcontact%2FContactDatabaseFrontend.java;h=30535fd231b3490861fa08166f22f9f5572eddd2;hb=9ad193b51551b58af5a9eef70810933f0f6033ee;hp=4065c25521af951080337fef39cdd6ddcc52a764;hpb=e06df9f02fa3fc03c21d5b2c3e2c8cb476be4ea3;p=addressbook-lib.git
diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
index 4065c25..30535fd 100644
--- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
+++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
@@ -1,120 +1,162 @@
-/*
- * 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.database.frontend.contact;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import org.mxchange.addressbook.BadTokenException;
-import org.mxchange.addressbook.contact.Contact;
-import org.mxchange.addressbook.database.backend.csv.CsvBackend;
-import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;
-import org.mxchange.addressbook.database.storage.Storeable;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
-
-/**
- * Stores and retrieves Contact instances
- *
- * @author Roland Haeder
- */
-public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {
- /**
- * Basic constrcutor
- */
- public ContactDatabaseFrontend () {
- super();
-
- // Set "table" name
- this.setTableName("contacts");
-
- // Initalize backend
- this.initBackend();
- }
-
- /**
- * Shuts down the database layer
- */
- @Override
- public void doShutdown () {
- // Shutdown backend
- this.getBackend().doShutdown();
- }
-
- /**
- * Flushes all contact entries to database
- * @param contactManager An instance of a MangeableContact class
- */
- @Override
- public void flushAllContacts (final ManageableContact contactManager) {
- // Get full list
- List contacts = contactManager.getList();
-
- // Get iterator
- Iterator iterator = contacts.iterator();
-
- // Rewind backend
- this.getBackend().rewind();
-
- // Get all entries
- while (iterator.hasNext()) {
- // Get next entry
- Contact contact = iterator.next();
-
- try {
- // Store this entry
- this.getBackend().store((Storeable) contact);
- } catch (final IOException ex) {
- // Should not happen?
- this.getLogger().catching(ex);
- System.exit(1);
- }
- }
- }
-
- /**
- * Reads all contacts from database backend and handles them over to the
- * contact manager
- *
- * @param contactManager Contact manager to handle loaded contacts
- */
- @Override
- public void readAllContacts (final ManageableContact contactManager) {
- // Get iterator and case it
- CsvBackend backend = (CsvBackend) this.getBackend();
-
- // First rewind to beginning
- this.getBackend().rewind();
-
- // Get backend iterator
- Iterator iterator = null;
- try {
- iterator = backend.contactIterator();
- } catch (final BadTokenException ex) {
- this.getLogger().catching(ex);
- System.exit(1);
- }
-
- // Read all entries
- while (iterator.hasNext()) {
- // Get next entry
- Contact contact = iterator.next();
-
- // Add contact instance to manager
- contactManager.addContact(contact);
- }
- }
-}
+/*
+ * 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.database.frontend.contact;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.database.backend.csv.CsvBackend;
+import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.addressbook.database.storage.Storeable;
+import org.mxchange.addressbook.exceptions.BadTokenException;
+import org.mxchange.addressbook.manager.contact.ContactManager;
+
+/**
+ * Stores and retrieves Contact instances
+ *
+ * @author Roland Haeder
+ */
+public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {
+
+ /**
+ * Constructor which accepts a contact manager
+ *
+ * @param manager
+ */
+ public ContactDatabaseFrontend (final ContactManager manager) {
+ // Call own constructor
+ this();
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("manager={0} - CALLED!", manager)); //NOI18N
+
+ // Manager instance must not be null
+ if (manager == null) {
+ // Abort here
+ throw new NullPointerException("manager is null"); //NOI18N
+ }
+
+ // Set contact manager
+ this.setContactManager(manager);
+ }
+
+ /**
+ * Basic constrcutor
+ */
+ protected ContactDatabaseFrontend () {
+ super();
+
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Set "table" name
+ this.setTableName("contacts"); //NOI18N
+
+ // Initalize backend
+ this.initBackend();
+ }
+
+ /**
+ * Shuts down the database layer
+ */
+ @Override
+ public void doShutdown () {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Shutdown backend
+ this.getBackend().doShutdown();
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Flushes all contact entries to database
+ */
+ @Override
+ public void flushAllContacts () {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Get full list
+ List contacts = this.getContactManager().getList();
+
+ // Get iterator
+ Iterator iterator = contacts.iterator();
+
+ // Rewind backend
+ this.getBackend().rewind();
+
+ // Get all entries
+ while (iterator.hasNext()) {
+ // Get next entry
+ Contact contact = iterator.next();
+
+ try {
+ // Store this entry
+ this.getBackend().store((Storeable) contact);
+ } catch (final IOException ex) {
+ // Should not happen?
+ this.getLogger().catching(ex);
+ System.exit(1);
+ }
+ }
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Reads all contacts from database backend and handles them over to the
+ * contact manager
+ */
+ @Override
+ public void readAllContacts () {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Get iterator and case it
+ CsvBackend backend = (CsvBackend) this.getBackend();
+
+ // First rewind to beginning
+ this.getBackend().rewind();
+
+ // Get backend iterator
+ Iterator iterator = null;
+ try {
+ iterator = backend.contactIterator();
+ } catch (final BadTokenException ex) {
+ this.getLogger().catching(ex);
+ System.exit(1);
+ }
+
+ // Read all entries
+ while (iterator.hasNext()) {
+ // Get next entry
+ Contact contact = iterator.next();
+
+ // Add contact instance to manager
+ this.getContactManager().addContact(contact);
+ }
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+}