From: Roland Haeder Date: Mon, 24 Aug 2015 11:30:16 +0000 (+0200) Subject: Updated jcore + some more fixes for changed database backend (Table Data Gateway... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=348c8e86763808f2c03f62c5dc198cbc163ccb8b;p=addressbook-lib.git Updated jcore + some more fixes for changed database backend (Table Data Gateway Pattern) Signed-off-by:Roland Häder --- diff --git a/lib/jcore.jar b/lib/jcore.jar index 4ad2d9d..d426e0d 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/nbproject/project.properties b/nbproject/project.properties index d1a9fce..7d2fb23 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -78,6 +78,7 @@ run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 +source.reference.jcore.jar=../jcore/src/ source.reference.log4j-api-2.3.jar=/home/quix0r/MyProjects/JARs/log4j-api-2.3-sources.jar source.reference.log4j-core-2.3.jar=/home/quix0r/MyProjects/JARs/log4j-core-2.3-sources.jar src.dir=src diff --git a/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java b/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java index 89802a8..e51b942 100644 --- a/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java +++ b/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java @@ -17,19 +17,16 @@ package org.mxchange.addressbook.database.frontend.contact; import java.io.IOException; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; import java.util.Map; -import java.util.StringTokenizer; -import org.mxchange.addressbook.contact.book.BookContact; -import org.mxchange.addressbook.contact.user.UserContact; import org.mxchange.addressbook.database.contact.AddressbookContactDatabaseConstants; 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.SearchableCriteria; import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend; @@ -110,9 +107,27 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp throw new ContactAlreadyAddedException(contact); } + // Clear dataset from previous usage + this.clearDataSet(); + + // Get field iterator + Iterator> iterator = contact.iterator(); + + // Iterate over all + while (iterator.hasNext()) { + // Get next field + Map.Entry field = iterator.next(); + + // Add it to data set + this.addToDataSet(field.getKey().getName(), field.getValue()); + } + // Then add it - this.getBackend().store((Storeable) contact); - } catch (final IOException | BadTokenException ex) { + Result result = this.doInsertDataSet(); + + // Debug message + this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N + } catch (final IOException | BadTokenException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Abort here this.abortProgramWithException(ex); } @@ -123,6 +138,8 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp /** * Shuts down the database layer + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs */ @Override public void doShutdown () throws SQLException, IOException { @@ -147,9 +164,15 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp * @return Total contact count */ @Override - public int getContactsCount () throws SQLException { + public int getContactsCount () throws SQLException, IOException { // And deligate to backend - return this.getBackend().getTotalCount(); //NOI18N + return this.getBackend().getTotalRows(); //NOI18N + } + + @Override + public String getIdName () { + // Return id column + return AddressbookContactDatabaseConstants.COLUMN_ID; } /** @@ -281,10 +304,4 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp public Storeable toStoreable (final Map map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { throw new UnsupportedOperationException("Not supported yet: map=" + map); } - - @Override - public String getIdName () { - // Return id column - return AddressbookContactDatabaseConstants.COLUMN_ID; - } } diff --git a/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java b/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java index 213575e..d1c46b7 100644 --- a/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java +++ b/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java @@ -44,9 +44,10 @@ public interface AddressbookContactFrontend extends DatabaseFrontend { * Some "getter" for total contacts count * * @return Total contacts count - * @throws java.sql.SQLException If any SQL error occurs + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs */ - public int getContactsCount () throws SQLException; + public int getContactsCount () throws SQLException, IOException; /** * Checks if given Contact is found diff --git a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java index 3def29d..d928695 100644 --- a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java +++ b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java @@ -683,11 +683,11 @@ public class AddressbookContactManager extends BaseManager implements Manageable // Abort here throw new NullPointerException("contact is null"); //NOI18N } - - // Debug message - /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getFirstName(), contact.getFamilyName(), this.size())); //NOI18N try { - // Check if contact is found + // Debug message + /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getFirstName(), contact.getFamilyName(), this.size())); //NOI18N + + // Check if contact is found if (this.getContactDatabase().isContactFound(contact)) { // Contact already added // @todo Do something here @@ -707,13 +707,8 @@ public class AddressbookContactManager extends BaseManager implements Manageable this.getLogger().trace("EXIT!"); //NOI18N } - /** - * Getter for size - * - * @return size of contact "book" - */ @Override - public final int size () { + public final int size () throws IOException { // Init size int size = -1;