+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<Addressbook> getUsersList (final User loggedInUser) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N
+
+ // Is the user instance null?
+ if (null == loggedInUser) {
+ // Abort here
+ throw new NullPointerException("loggedInUser is null"); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("param", loggedInUser); //NOI18N
+
+ // Get full list from JPA
+ List<Addressbook> addressbooks = query.getResultList();
+
+ // Return it
+ return addressbooks;
+ }
+
+ @Override
+ public boolean isAddressbookIdUsed (final Long addressbookId) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
+
+ // Is it null or zero?
+ if (null == addressbookId) {
+ // Throw NPE
+ throw new NullPointerException("addressbookId is null"); //NOI18N
+ } else if (addressbookId < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("FindAddressbookById"); //NOI18N
+
+ // Set parameter
+ query.setParameter("id", addressbookId); //NOI18N
+
+ // Default is not valid
+ boolean isValid = false;
+
+ // Try it again, yes no other way
+ try {
+ // Get single result
+ Addressbook addressbook = (Addressbook) query.getSingleResult();
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbook={0} - FOUND!", addressbook)); //NOI18N
+
+ // Found one!
+ isValid = true;
+ } catch (final NoResultException ex) {
+ // Debug log only, maybe out-dated link followed
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} is not valid: {1}", addressbookId, ex)); //NOI18N
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: isValid={0} - EXIT!", isValid)); //NOI18N
+
+ // Return result
+ return isValid;
+ }