import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
import org.mxchange.jcoreee.database.BaseDatabaseBean;
import org.mxchange.jusercore.model.user.User;
*/
private static final long serialVersionUID = 129_857_871_287_691L;
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<AddressbookEntry> allEntries (final Addressbook addressbook) {
+ // Generate query
+ Query query = this.getEntityManager().createNamedQuery("AllAddressbookEntries"); //NOI18N
+
+ // Set parameters
+ query.setParameter("addressbook", addressbook); //NOI18N
+ query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N
+ query.setParameter("sharer", addressbook.getAddressbookUser()); //NOI18N
+
+ // Return it
+ return query.getResultList();
+ }
+
@Override
@SuppressWarnings ("unchecked")
public List<Addressbook> getUsersList (final User loggedInUser) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser));
+ 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");
+ throw new NullPointerException("loggedInUser is null"); //NOI18N
}
// Get query instance
}
// Get query instance
- Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class);
+ Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N
// Set parameter
- query.setParameter("user", addressbook.getAddressbookUser());
- query.setParameter("name", addressbook.getAddressbookName());
+ query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N
+ query.setParameter("name", addressbook.getAddressbookName()); //NOI18N
// Default is not found
boolean isUsed = false;
Addressbook dummy = (Addressbook) query.getSingleResult();
// Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy));
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N
// Found one
isUsed = true;
} catch (final NoResultException ex) {
// No result found, so log it away
- this.getLoggerBeanLocal().logDebug("isAddressbookNameUsed: getSingleResult() did not return a result: " + ex);
+ this.getLoggerBeanLocal().logDebug("isAddressbookNameUsed: getSingleResult() did not return a result: " + ex); //NOI18N
}
// Return result