return AddressbookContactDatabaseConstants.COLUMN_ID;
}
- /**
- * Some "getter" for own contact instance
- *
- * @return Own contact instance
- */
@Override
- public Contact getOwnContact () {
+ public Contact getOwnContact () throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- // Get row index back from backend
- int rowIndex = this.getBackend().getRowIndexFromColumn(AddressbookContactDatabaseConstants.COLUMN_OWN_CONTACT, true);
+ // Prepare search instance
+ SearchableCriteria criteria = new SearchCriteria();
+
+ // Add criteria and limit
+ criteria.addCriteria(AddressbookContactDatabaseConstants.COLUMN_OWN_CONTACT, true);
+ criteria.setLimit(1);
+
+ // Then search for it
+ Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
// Debug message
- this.getLogger().debug(MessageFormat.format("rowIndex={0}", rowIndex));
+ this.getLogger().debug(MessageFormat.format("result={0}", result));
// Init instance
Contact contact = null;
- try {
- // Now simply read the row
- contact = (Contact) this.getBackend().readRow(rowIndex);
- } catch (final BadTokenException ex) {
- // Bad token found
- this.abortProgramWithException(ex);
+ // Is there one row at least?
+ if (result.hasNext()) {
+ // Then get it
+ Storeable storeable = result.next();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("storeable={0}", storeable));
+
+ // Is it same instance?
+ if (!(storeable instanceof Contact)) {
+ // Not same instance
+ throw new IllegalArgumentException(MessageFormat.format("storeable={0} is not implementing Contact", storeable));
+ }
+
+ // Cast it securely
+ contact = (Contact) storeable;
}
// Trace message
return contact;
}
+ @Override
+ public Storeable getStoreableAtRow (final int rowIndex) {
+ throw new UnsupportedOperationException("Not supported yet: rowIndex=" + rowIndex);
+ }
+
/**
* Checks if given Contact is found
*
return result.hasNext();
}
- /**
- * Reads a single row and parses it to a contact instance
- *
- * @param rowIndex Row index (also how much to skip)
- * @return Contact instance
- */
- @Override
- public Contact readSingleContact (final int rowIndex) {
- try {
- // Deligate this to backend instance
- return (Contact) this.getBackend().readRow(rowIndex);
- } catch (final BadTokenException ex) {
- // Bad token found
- this.abortProgramWithException(ex);
- }
-
- // Bad state, should not be reached
- throw new IllegalStateException("This should not be reached");
- }
-
@Override
public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
throw new UnsupportedOperationException("Not supported yet: map=" + map);