use of org.hibernate.criterion.Disjunction in project opennms by OpenNMS.
the class DefaultNodeListService method addCriteriaForMaclike.
private static void addCriteriaForMaclike(final OnmsCriteria criteria, final String macLike) {
final String macLikeStripped = macLike.replaceAll("[:-]", "");
criteria.createAlias("node.snmpInterfaces", "snmpInterface", OnmsCriteria.LEFT_JOIN);
final Disjunction physAddrDisjunction = Restrictions.disjunction();
physAddrDisjunction.add(Restrictions.ilike("snmpInterface.physAddr", macLikeStripped, MatchMode.ANYWHERE));
criteria.add(physAddrDisjunction);
// This is an alternative to the above code if we need to use the out-of-the-box DetachedCriteria which doesn't let us specify the join type
/*
String propertyName = "nodeId";
String value = "%" + macLikeStripped + "%";
Disjunction physAddrDisjuction = Restrictions.disjunction();
physAddrDisjuction.add(Restrictions.sqlRestriction("{alias}." + propertyName + " IN (SELECT nodeid FROM snmpinterface WHERE snmpphysaddr LIKE ? )", value, new StringType()));
criteria.add(physAddrDisjuction);
*/
}
use of org.hibernate.criterion.Disjunction in project opennms by OpenNMS.
the class DefaultRtcService method getNodeListForCriteria.
/** {@inheritDoc} */
@Override
public RtcNodeModel getNodeListForCriteria(OnmsCriteria serviceCriteria, OnmsCriteria outageCriteria) {
serviceCriteria.addOrder(Order.asc("node.label"));
serviceCriteria.addOrder(Order.asc("node.id"));
serviceCriteria.addOrder(Order.asc("ipInterface.ipAddress"));
serviceCriteria.addOrder(Order.asc("serviceType.name"));
Date periodEnd = new Date(System.currentTimeMillis());
Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.isNull("ifRegainedService"));
disjunction.add(Restrictions.ge("ifLostService", periodStart));
disjunction.add(Restrictions.ge("ifRegainedService", periodStart));
outageCriteria.add(disjunction);
outageCriteria.addOrder(Order.asc("monitoredService"));
outageCriteria.addOrder(Order.asc("ifLostService"));
List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
RtcNodeModel model = new RtcNodeModel();
OnmsNode lastNode = null;
int serviceCount = 0;
int serviceDownCount = 0;
long downMillisCount = 0;
for (OnmsMonitoredService service : services) {
if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
serviceCount = 0;
serviceDownCount = 0;
downMillisCount = 0;
}
serviceCount++;
if (service.isDown()) {
serviceDownCount++;
}
Long downMillis = serviceDownTime.get(service);
if (downMillis == null) {
// This service had 100% availability over the period, no downtime
} else {
downMillisCount += downMillis;
}
lastNode = service.getIpInterface().getNode();
}
if (lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
}
return model;
}
use of org.hibernate.criterion.Disjunction in project hibernate-orm by hibernate.
the class CompositeIdTest method testQueryInAndComposite.
@Test
public void testQueryInAndComposite() {
Session s = openSession();
Transaction transaction = s.beginTransaction();
createData(s);
s.flush();
List ids = new ArrayList<SomeEntityId>(2);
ids.add(new SomeEntityId(1, 12));
ids.add(new SomeEntityId(10, 23));
Criteria criteria = s.createCriteria(SomeEntity.class);
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.in("id", ids));
criteria.add(disjunction);
List list = criteria.list();
assertEquals(2, list.size());
transaction.rollback();
s.close();
}
use of org.hibernate.criterion.Disjunction in project dhis2-core by dhis2.
the class HibernateGenericStore method getSharingDetachedCriteria.
private DetachedCriteria getSharingDetachedCriteria(UserInfo user, String access) {
DetachedCriteria criteria = DetachedCriteria.forClass(getClazz(), "c");
preProcessDetachedCriteria(criteria);
if (!sharingEnabled(user) || user == null) {
return criteria;
}
Assert.notNull(user, "User argument can't be null.");
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.like("c.publicAccess", access));
disjunction.add(Restrictions.isNull("c.publicAccess"));
disjunction.add(Restrictions.isNull("c.user.id"));
disjunction.add(Restrictions.eq("c.user.id", user.getId()));
DetachedCriteria userGroupDetachedCriteria = DetachedCriteria.forClass(getClazz(), "ugdc");
userGroupDetachedCriteria.createCriteria("ugdc.userGroupAccesses", "uga");
userGroupDetachedCriteria.createCriteria("uga.userGroup", "ug");
userGroupDetachedCriteria.createCriteria("ug.members", "ugm");
userGroupDetachedCriteria.add(Restrictions.eqProperty("ugdc.id", "c.id"));
userGroupDetachedCriteria.add(Restrictions.eq("ugm.id", user.getId()));
userGroupDetachedCriteria.add(Restrictions.like("uga.access", access));
userGroupDetachedCriteria.setProjection(Property.forName("uga.id"));
disjunction.add(Subqueries.exists(userGroupDetachedCriteria));
DetachedCriteria userDetachedCriteria = DetachedCriteria.forClass(getClazz(), "udc");
userDetachedCriteria.createCriteria("udc.userAccesses", "ua");
userDetachedCriteria.createCriteria("ua.user", "u");
userDetachedCriteria.add(Restrictions.eqProperty("udc.id", "c.id"));
userDetachedCriteria.add(Restrictions.eq("u.id", user.getId()));
userDetachedCriteria.add(Restrictions.like("ua.access", access));
userDetachedCriteria.setProjection(Property.forName("ua.id"));
disjunction.add(Subqueries.exists(userDetachedCriteria));
criteria.add(disjunction);
return criteria;
}
use of org.hibernate.criterion.Disjunction in project dhis2-core by dhis2.
the class HibernateDeletedObjectStore method query.
@Override
@SuppressWarnings("unchecked")
public List<DeletedObject> query(DeletedObjectQuery query) {
Criteria criteria = getCurrentSession().createCriteria(DeletedObject.class);
if (query.getKlass().isEmpty()) {
Disjunction disjunction = Restrictions.disjunction();
if (!query.getUid().isEmpty()) {
disjunction.add(Restrictions.in("uid", query.getUid()));
}
if (!query.getCode().isEmpty()) {
disjunction.add(Restrictions.in("code", query.getCode()));
}
criteria.add(disjunction);
} else if (query.getUid().isEmpty() && query.getCode().isEmpty()) {
criteria.add(Restrictions.in("klass", query.getKlass()));
} else {
Disjunction disjunction = Restrictions.disjunction();
if (!query.getUid().isEmpty()) {
Conjunction conjunction = Restrictions.conjunction();
conjunction.add(Restrictions.in("klass", query.getKlass()));
conjunction.add(Restrictions.in("uid", query.getUid()));
disjunction.add(conjunction);
}
if (!query.getCode().isEmpty()) {
Conjunction conjunction = Restrictions.conjunction();
conjunction.add(Restrictions.in("klass", query.getKlass()));
conjunction.add(Restrictions.in("code", query.getCode()));
disjunction.add(conjunction);
}
criteria.add(disjunction);
}
if (query.getDeletedAt() != null) {
criteria.add(Restrictions.ge("deletedAt", query.getDeletedAt()));
}
if (!query.isSkipPaging()) {
Pager pager = query.getPager();
criteria.setFirstResult(pager.getOffset());
criteria.setMaxResults(pager.getPageSize());
}
return criteria.list();
}
Aggregations