import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
import org.mxchange.addressbook.exceptions.AddressbookNotFoundException;
import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
import org.mxchange.jcoreee.database.BaseDatabaseBean;
import org.mxchange.jusercore.model.user.User;
return query.getResultList();
}
+ @Override
+ @SuppressWarnings ("unchecked")
+ public Integer countAllUserSharedAddressbooks (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N
+
+ // user should be valid
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+ }
+
+ // Get named query
+ Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks"); //NOI18N
+
+ // Set parameter
+ query.setParameter("user", user); //NOI18N
+
+ // Default is zero
+ Integer count = 0;
+
+ // Try it
+ try {
+ // Get whole list
+ List<ShareableAddressbook> dummy = query.getResultList();
+
+ // Set size
+ count = dummy.size();
+ } catch (final NoResultException ex) {
+ // Need to catch this, so log it
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("countAllUserSharedAddressbooks: getResultList() failed: {0}", ex)); //NOI18N
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: count={0} - EXIT!", count)); //NOI18N
+
+ // Return count
+ return count;
+ }
+
@Override
public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException {
// Is it not null?