import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
+import org.mxchange.jcustomercore.exceptions.CustomerNotFoundException;
import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N
}
+ @Override
+ public Customer findCustomerById (final Long customerId) throws CustomerNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCustomerById: customerId={0} - CALLED!", customerId)); //NOI18N
+
+ // The parameter must be valid
+ if (null == customerId) {
+ // Throw NPE
+ throw new NullPointerException("customerId is null"); //NOI18N
+ } else if (customerId < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("customerId={0} - is not valid", customerId)); //NOI18N
+ }
+
+ // Init instance
+ Customer customer;
+
+ // Get named query
+ Query query = this.getEntityManager().createNamedQuery("SearchCustomerById", Customer.class); //NOI18N
+
+ // Set customer id
+ query.setParameter("customerId", customerId); //NOI18N
+
+ // Try to find it
+ try {
+ // Get single result
+ customer = (Customer) query.getSingleResult();
+
+ // Debug message (success)
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("findCustomerById: Found customer={0} with customerId={1}", customer, customerId)); //NOI18N
+ } catch (final NoResultException ex) {
+ // Not found, throw again
+ throw new CustomerNotFoundException(customerId, ex);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCustomerById; customer={0} - EXIT!", customer)); //NOI18N
+
+ // Return found instance
+ return customer;
+ }
+
@Override
public boolean isReqistered (final Customer customer) {
// Trace message