use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.
the class CustomerDaoImpl method readCustomersByIds.
@Override
public List<Customer> readCustomersByIds(List<Long> ids) {
if (ids == null || ids.size() == 0) {
return null;
}
if (ids.size() > 100) {
LOG.warn("Not recommended to use the readCustomersByIds method for long lists of customerIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "customer ids was (" + ids.size() + ") in length.");
}
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
criteria.select(customer);
// We only want results that match the customer IDs
criteria.where(customer.get("id").as(Long.class).in(ids));
TypedQuery<Customer> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
return query.getResultList();
}
use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.
the class CustomerDaoImpl method readBatchCustomers.
@Override
public List<Customer> readBatchCustomers(int start, int pageSize) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
criteria.select(customer);
TypedQuery<Customer> query = em.createQuery(criteria);
query.setFirstResult(start);
query.setMaxResults(pageSize);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Customer");
return query.getResultList();
}
use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.
the class ResourcePurgeDaoImpl method buildCustomerQuery.
protected <T> TypedQuery<T> buildCustomerQuery(Date dateCreatedMinThreshold, Boolean registered, Boolean deactivated, Boolean isPreview, Class<T> returnType, List<Long> excludedIds) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(returnType);
Root<CustomerImpl> root = criteria.from(CustomerImpl.class);
if (Long.class.equals(returnType)) {
criteria.select((Selection<? extends T>) builder.count(root));
} else {
criteria.select((Selection<? extends T>) root);
}
// find only customers that do not have any orders, otherwise a purge would fail because of referential integrity
Subquery<Long> subquery = criteria.subquery(Long.class);
Root orderRoot = subquery.from(OrderImpl.class);
subquery.select(builder.count(orderRoot));
subquery.where(builder.equal(orderRoot.get("customer"), root));
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(subquery, 0L));
if (registered != null) {
if (registered) {
restrictions.add(builder.isTrue(root.get("registered").as(Boolean.class)));
} else {
restrictions.add(builder.or(builder.isNull(root.get("registered")), builder.isFalse(root.get("registered").as(Boolean.class))));
}
}
if (deactivated != null) {
if (deactivated) {
restrictions.add(builder.isTrue(root.get("deactivated").as(Boolean.class)));
} else {
restrictions.add(builder.or(builder.isNull(root.get("deactivated")), builder.isFalse(root.get("deactivated").as(Boolean.class))));
}
}
if (dateCreatedMinThreshold != null) {
restrictions.add(builder.lessThan(root.get("auditable").get("dateCreated").as(Date.class), dateCreatedMinThreshold));
}
if (isPreview != null) {
if (isPreview) {
restrictions.add(builder.isTrue(root.get("previewable").get("isPreview").as(Boolean.class)));
} else {
restrictions.add(builder.or(builder.isNull(root.get("previewable").get("isPreview")), builder.isFalse(root.get("previewable").get("isPreview").as(Boolean.class))));
}
}
if (excludedIds != null && excludedIds.size() > 0) {
applyLimitedInClause(excludedIds, builder, root, restrictions);
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return em.createQuery(criteria);
}
use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.
the class RegisterCustomerDataProvider method createCustomer.
@DataProvider(name = "setupCustomerControllerData")
public static Object[][] createCustomer() {
Customer customer = new CustomerImpl();
customer.setEmailAddress("testCase@test.com");
customer.setFirstName("TestFirstName");
customer.setLastName("TestLastName");
customer.setUsername("TestCase");
ChallengeQuestion question = new ChallengeQuestionImpl();
question.setId(1L);
customer.setChallengeQuestion(question);
customer.setChallengeAnswer("Challenge CandidateItemOfferAnswer");
RegisterCustomerForm registerCustomer = new RegisterCustomerForm();
registerCustomer.setCustomer(customer);
registerCustomer.setPassword("TestPassword");
registerCustomer.setPasswordConfirm("TestPassword");
return new Object[][] { new Object[] { registerCustomer } };
}
use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.
the class CustomerDataProvider method createCustomers.
@DataProvider(name = "setupCustomers")
public static Object[][] createCustomers() {
Customer customer1 = new CustomerImpl();
customer1.setPassword("customer1Password");
customer1.setUsername("customer1");
Customer customer2 = new CustomerImpl();
customer2.setPassword("customer2Password");
customer2.setUsername("customer2");
return new Object[][] { new Object[] { customer1 }, new Object[] { customer2 } };
}
Aggregations