use of org.broadleafcommerce.common.persistence.Status in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Serializable instance = dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
if (instance instanceof Status) {
((Status) instance).setArchived('Y');
dynamicEntityDao.merge(instance);
return;
}
} catch (Exception ex) {
throw new ServiceException("Unable to perform remove for entity: " + entity.getType()[0], ex);
}
super.remove(persistencePackage, dynamicEntityDao, helper);
}
use of org.broadleafcommerce.common.persistence.Status in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method readOtherEntitiesWithPropertyValue.
@Override
public List<Long> readOtherEntitiesWithPropertyValue(Serializable instance, String propertyName, String value) {
Class clazz = DynamicDaoHelperImpl.getNonProxyImplementationClassIfNecessary(instance.getClass());
CriteriaBuilder builder = standardEntityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root root = criteria.from(clazz);
Path idField = root.get(getIdField(clazz).getName());
criteria.select(idField.as(Long.class));
List<Predicate> restrictions = new ArrayList<>();
restrictions.add(builder.equal(root.get(propertyName), value));
restrictions.add(builder.notEqual(idField, getIdentifier(instance)));
if (instance instanceof Status) {
restrictions.add(builder.or(builder.isNull(root.get("archiveStatus").get("archived")), builder.equal(root.get("archiveStatus").get("archived"), 'N')));
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return standardEntityManager.createQuery(criteria).getResultList();
}
Aggregations