+ @Override
+ public Category getCategory (final Product product) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
+
+ // product must not be null
+ if (product == null) {
+ // Abort here
+ throw new NullPointerException("product is null"); //NOI18N
+ }
+
+ // Get category id from it
+ Long id = product.getCategory();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("id={0}", id)); //NOI18N
+
+ // It should be >0 here
+ assert(id > 0) : MessageFormat.format("id={0} must be larger zero", id); //NOI18N
+
+ // Then construct a search instance
+ SearchableCriteria criteria = new SearchCriteria();
+
+ // Add id to it
+ criteria.addCriteria(PizzaCategoryDatabaseConstants.COLUMN_ID, id);
+
+ // Only one entry is find
+ criteria.setLimit(1);
+
+ // Run it on backend
+ Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+ // Debug log
+ this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size())); //NOI18N
+
+ // Init category instance
+ Category category = null;
+
+ // Is there one entry?
+ if (result.hasNext()) {
+ // Read result from it
+ Storeable storeable = result.next();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); //NOI18N
+
+ // Is it instance of Category?
+ if (storeable instanceof Category) {
+ // Then cast it
+ category = (Category) storeable;
+ }
+ }
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N
+
+ // Return it
+ return category;
+ }
+
+ @Override
+ public String getIdName () {
+ // Return column id
+ return PizzaCategoryDatabaseConstants.COLUMN_ID;
+ }
+