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;
throw new ContactAlreadyAddedException(contact);
}
+ // Clear dataset from previous usage
+ this.clearDataSet();
+
+ // Get field iterator
+ Iterator<Map.Entry<Field, Object>> iterator = contact.iterator();
+
+ // Iterate over all
+ while (iterator.hasNext()) {
+ // Get next field
+ Map.Entry<Field, Object> 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<? extends Storeable> 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);
}
/**
* 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 {
* @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;
}
/**
public Storeable toStoreable (final Map<String, String> 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;
- }
}
// 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
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;