List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java
License:Open Source License
public void updateChannelsTableMap(String curl) { m_logger.info("clear_cache(curl): ChannelsTable1"); final String keyField = "Name"; final Class type = alma.TMCDB.maci.EventChannel.class; Map<String, Object> rootMap = (Map<String, Object>) rootNode; Channels channels = (Channels) ((Map<String, Object>) rootMap.get("MACI")).get("Channels"); m_logger.info("clear_cache(curl): ChannelsTable2"); try {//from w w w .ja v a 2 s . com Session session = hibernateUtil.getSession(); Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField); Field field = null; if (accessor == null) { try { field = type.getField(keyField); } catch (Throwable th) { throw new IllegalStateException("failed to obtain key "); } } if (channels == null) channels = new Channels(); Map<String, EventChannelNode> map; map = channels._; m_logger.info("clear_cache(curl): ChannelsTable3"); alma.TMCDB.maci.NotificationServiceMapping mapping = (alma.TMCDB.maci.NotificationServiceMapping) session .createCriteria(alma.TMCDB.maci.NotificationServiceMapping.class) .add(Restrictions.eq("ConfigurationId", configId)).uniqueResult(); m_logger.info("clear_cache(curl): ChannelsTable4"); if (mapping != null) { channels.setNotificationServiceMapping(mapping); } m_logger.info("clear_cache(curl): ChannelsTable5"); String els[] = curl.split("/"); String rpath = "^/*"; String rsubpath = "^/*"; String rcpath = "^/*"; String rcname = els[els.length - 1]; for (int i = 0; i < els.length; i++) { rpath += els[i]; rsubpath += els[i]; if (i < els.length - 1) { rpath += "/+"; rsubpath += "/+"; rcpath += els[i]; if (i < els.length - 2) rcpath += "/+"; } } rpath += "/*$"; rsubpath += "/+.*"; rcpath += "/*$"; System.out.println(rpath); System.out.println(rsubpath); System.out.println(rcpath + "|" + rcname); m_logger.info("clear_cache(curl): ChannelsTable6"); //Consider the cases where the curl matches exactly the Path, where //it is part of the path and when it matches exactly the path and //the component name. Criterion cr = Restrictions.disjunction().add(getRegularExpressionRestriction("Path", rpath)) .add(getRegularExpressionRestriction("Path", rsubpath)).add(Restrictions .and(getRegularExpressionRestriction("Path", rcpath), Restrictions.eq("Name", rcname))); List list = getListForConfiguration(session, type, cr); m_logger.info("clear_cache(curl): ChannelsTable7"); System.out.println("\nFound the following Containers"); for (Object data : list) { System.out.println(((alma.TMCDB.maci.Container) data).Path + "/" + ((alma.TMCDB.maci.Container) data).getName()); } //Remove the entries from existing maps. System.out.println("\nChecking maps to remove"); m_logger.info("clear_cache(curl): ChannelsTable8"); Map<String, EventChannelNode> rParentMap = map; for (int i = 0; i < els.length; i++) { System.out.println("Checking path " + els[i] + "."); System.out.println("Parent keys: " + rParentMap.keySet().toString()); Object data = rParentMap.get(els[i]); if (data == null) { System.out.println("No element found with the given curl"); break; } else { if (data instanceof alma.TMCDB.maci.EventChannel) { System.out.println("Instance of EventChannel (EventChannel!)."); } else if (data instanceof alma.TMCDB.maci.EventChannelNode) { System.out.println("Instance of ContainerNode (Path!)."); } else { System.out.println("Unknown type! Details: " + data.toString()); } if (i < els.length - 1) { System.out.println("There are elements remaining, so we proceed to next element in path."); rParentMap = ((alma.TMCDB.maci.EventChannelNode) data)._; } else { System.out.println( "There are no elements remaining, we remove all entries from this element in path and on."); rParentMap.remove(els[i]); } } } m_logger.info("clear_cache(curl): ChannelsTable9"); for (Object data : list) { String baseKey; if (accessor != null) baseKey = accessor.invoke(data, (Object[]) null).toString(); else //if (field != null) baseKey = field.get(data).toString(); // baseKey should not be null Map parentMap = map; alma.TMCDB.maci.EventChannel channel = (alma.TMCDB.maci.EventChannel) data; // now find its map String path = getNormalizedPath(channel.Path); while (path != null && path.length() > 0) { // remove trailing slashes, to have unique curl (used for key) if (path.charAt(0) == '/') { path = path.substring(1); continue; } int pos = path.indexOf('/'); String parentPath = (pos > 0) ? path.substring(0, pos) : path; String subpath = (pos > 0) ? path.substring(pos + 1, path.length()) : null; alma.TMCDB.maci.EventChannelNode parentChannel = (alma.TMCDB.maci.EventChannelNode) parentMap .get(parentPath); if (parentChannel == null) { parentChannel = new alma.TMCDB.maci.EventChannelNode(); parentMap.put(parentPath, parentChannel); } parentMap = parentChannel._; path = subpath; } // unique key generation int count = 0; String key = baseKey; while (parentMap.containsKey(key)) key = baseKey + String.valueOf(++count); parentMap.put(key, data); m_logger.info("clear_cache(curl): ChannelsTable10"); } m_logger.info("clear_cache(curl): ChannelsTable11"); } catch (Throwable th) { th.printStackTrace(); } m_logger.info("clear_cache(curl): ChannelsTable12"); }
From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java
License:Open Source License
protected void updateAlmaBranch(String curl) { m_logger.info("clear_cache(curl): AlmaBranch1"); Map<String, Object> rootMap = (Map<String, Object>) rootNode; final Map<String, Object> almaRoot = (Map<String, Object>) rootMap.get(COMPONENT_TREE_NAME); m_logger.info("clear_cache(curl): AlmaBranch2"); try {//from ww w .j a va 2 s . c om Session session = hibernateUtil.getSession(); schemaResourceResolverLoader.setSession(session); String els[] = curl.split("/"); String rpath = "^/*"; String rsubpath = "^/*"; String rcpath = "^/*"; String rcname = els[els.length - 1]; for (int i = 0; i < els.length; i++) { rpath += els[i]; rsubpath += els[i]; if (i < els.length - 1) { rpath += "/+"; rsubpath += "/+"; rcpath += els[i]; if (i < els.length - 2) rcpath += "/+"; } } rpath += "/*$"; rsubpath += "/+.*"; rcpath += "/*$"; System.out.println(rpath); System.out.println(rsubpath); System.out.println(rcpath + "|" + rcname); m_logger.info("clear_cache(curl): AlmaBranch3"); //Consider the cases where the curl matches exactly the Path, where //it is part of the path and when it matches exactly the path and //the component name. Criterion cr = Restrictions.disjunction().add(getRegularExpressionRestriction("Path", rpath)) .add(getRegularExpressionRestriction("Path", rsubpath)).add(Restrictions .and(getRegularExpressionRestriction("Path", rcpath), Restrictions.eq("Name", rcname))); //Remove the entries from existing maps. System.out.println("\nChecking maps to remove"); m_logger.info("clear_cache(curl): AlmaBranch4"); Map rParentMap = almaRoot; for (int i = 0; i < els.length; i++) { System.out.println("Checking path " + els[i] + "."); System.out.println("Parent keys: " + rParentMap.keySet().toString()); Object data = rParentMap.get(els[i]); if (data == null) { System.out.println("No element found with the given curl"); break; } else { if (data instanceof ComponentDAOImplSaver) { System.out.println("Instance of ComponentDAOImplSaver (Component!)."); } else if (data instanceof ComponentData) { System.out.println("Instance of ComponentData (Path!)."); } else { System.out.println("Unknown type! Details: " + data.toString()); } if (i < els.length - 1) { System.out.println("There are elements remaining, so we proceed to next element in path."); rParentMap = ((ComponentData) data)._; } else { System.out.println( "There are no elements remaining, we remove all entries from this element in path and on."); rParentMap.remove(els[i]); } } } m_logger.info("clear_cache(curl): AlmaBranch5"); final Set<String> loadedComponents = new HashSet<String>(); // // add control devices // m_logger.info("clear_cache(curl): AlmaBranch6"); if (plugin != null) { final HibernateWDALPlugin.ControlDeviceBindCallback bindCallback = new HibernateWDALPlugin.ControlDeviceBindCallback() { public void bindToComponentBranch(String name, String path, Object objectToBind) { bindToAlmaBranch(almaRoot, name, path, objectToBind); if (!loadedComponents.contains(path + "/" + name)) loadedComponents.add(path + "/" + name); } public void bindNonExpandedXMLToComponentBranch(Session session, Component component) { alma.TMCDB.maci.Component comp = (alma.TMCDB.maci.Component) session .createCriteria(alma.TMCDB.maci.Component.class) .add(Restrictions.eq("ComponentId", component.getComponentId())).uniqueResult(); if (comp == null) throw new RuntimeException( "Component with ID " + component.getComponentId() + " does not exist."); bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, comp); } }; plugin.updateControlDevices(session, config, bindCallback, curl); } m_logger.info("clear_cache(curl): AlmaBranch7"); // // add devices // Iterator componentList = session.createCriteria(alma.TMCDB.maci.Component.class) .add(Restrictions.eq("Control", false)).add(Restrictions.eq("ConfigurationId", configId)) .add(cr).list().iterator(); System.out.println("\nFound the following Components"); m_logger.info("clear_cache(curl): AlmaBranch8"); //while(componentList.hasNext()) { // Object data = componentList.next(); // System.out.println(((alma.TMCDB.maci.Component)data).Path+"/"+((alma.TMCDB.maci.Component)data).getName()); //} while (componentList.hasNext()) { alma.TMCDB.maci.Component component = (alma.TMCDB.maci.Component) componentList.next(); System.out.println(component.Path + "/" + component.getName()); // already loaded by plugins, skip if (loadedComponents.contains(component.Path + "/" + component.getName())) continue; String query = "FROM alma.TMCDB.baci.BACIPropertyType WHERE ComponentId = " + component.ComponentId; List propertyList = session.createQuery(query).list(); System.out.println("Size: " + propertyList.size()); if (propertyList.size() > 0) { ComponentData componentData = new ComponentData(); try { componentData.setData(component.XMLDoc); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } // add properties for (Iterator iter = propertyList.iterator(); iter.hasNext();) { BACIPropertyType baciProperty = (BACIPropertyType) iter.next(); //componentData._.put(baciProperty.PropertyName, baciProperty); componentData._.put(baciProperty.PropertyName, new EmptyStringHandlerBACIPropertyType(baciProperty)); } // bind object to map tree bindToAlmaBranch(almaRoot, component.getName(), component.Path, componentData); } else if (component.XMLDoc != null) { bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, component); } m_logger.info("clear_cache(curl): AlmaBranch9"); } m_logger.info("clear_cache(curl): AlmaBranch10"); } catch (Throwable th) { th.printStackTrace(); } m_logger.info("clear_cache(curl): AlmaBranch11"); }
From source file:com.court.controller.CollectionSheetFxmlController.java
private List<Member> memberList() { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(Member.class); c.createAlias("branch", "b"); c.createAlias("payOffice", "po"); //=====================================REMOVED DUE TO UNNASSARY FILTER================================= // c.createAlias("memberLoans", "ml"); // c.add(Restrictions.eq("ml.isComplete", false)); // c.add(Restrictions.disjunction() // .add(Restrictions.le("ml.paidUntil", new java.util.Date())) // .add(Restrictions.isNull("ml.paidUntil")) // );/*from ww w.j av a 2s . co m*/ //=====================================REMOVED DUE TO UNNASSARY FILTER================================== int selected = search_typ_combo.getSelectionModel().getSelectedIndex(); switch (selected) { case 0: c.add(Restrictions.disjunction() //===================SEARCH CHANGED TO PAYMENT OFFICE INSTEAD OF USER BRANCH=================== // .add(Restrictions.eq("b.branchName", search_txt.getText()))); .add(Restrictions.eq("po.branchCode", search_txt.getText().split("-")[0]))); break; case 1: c.add(Restrictions.disjunction().add(Restrictions.eq("memberId", search_txt.getText()))); break; case 2: c.add(Restrictions.disjunction().add(Restrictions.eq("nameWithIns", search_txt.getText()))); break; } c.add(Restrictions.eq("status", true)); c.add(Restrictions.eq("b.status", true)); c.addOrder(Order.asc("b.branchCode")); List<Member> mList = c.list(); List<Member> filteredList = mList.stream().filter(FxUtilsHandler.distinctByKey(p -> p.getMemberId())) .collect(Collectors.toList()); session.close(); return filteredList; }
From source file:com.court.controller.GuarantorsFxmlController.java
@FXML private void onSearchBtnAction(ActionEvent event) { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(Member.class); if (!gur_name_txt.getText().isEmpty()) { c.add(Restrictions.disjunction().add(Restrictions.eq("fullName", gur_name_txt.getText()))); } else {/* ww w. ja va 2 s . co m*/ c.add(Restrictions.disjunction().add(Restrictions.eq("memberId", gur_id_txt.getText()))); } List<Member> list = c.list(); initGTable(list); }
From source file:com.court.controller.MemberfxmlController.java
private List<MemberLoan> getAllMemberLoans(String mCode) { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class); c.createAlias("member", "m").add(Restrictions.disjunction().add(Restrictions.eq("m.memberId", mCode))); List<MemberLoan> mList = c.list(); session.close();// w w w . j a v a 2 s . c om return mList; }
From source file:com.court.controller.MemberfxmlController.java
private ObservableList<MemChild> getChildrenOfMember(String memberCode) { Session session = HibernateUtil.getSessionFactory().openSession(); List<MemChild> children = session.createCriteria(MemChild.class).createAlias("member", "m") .add(Restrictions.disjunction().add(Restrictions.eq("m.memberId", memberCode))).list(); session.close();/*ww w. j a v a 2 s. c o m*/ return FXCollections.observableArrayList(children); }
From source file:com.cubeia.backoffice.users.dao.UserDAOImpl.java
License:Open Source License
private Criteria createFindUserCriteria(Long userId, Long operatorId, String name, Collection<UserStatus> includeStatuses, int offset, int limit, UserOrder order, boolean ascending) { Session hbSession = getHibernateSession(); Criteria c = hbSession.createCriteria(User.class); c.createAlias("information", "information", JoinType.LEFT_OUTER_JOIN); c.setFetchMode("attributes", FetchMode.SELECT); if (userId != null) { c.add(eq("id", userId)); }//from w w w . j a va 2 s .c o m if (operatorId != null) { c.add(eq("operatorId", operatorId)); } if (name != null && !name.isEmpty()) { c.add(Restrictions.disjunction().add(like("userName", name)).add(like("information.firstName", name)) .add(like("information.lastName", name))); } if (includeStatuses != null) { c.add(Restrictions.in("status", includeStatuses)); } if (order != null) { if (ascending) { c.addOrder(Order.asc(order.getColumnName())); } else { c.addOrder(Order.desc(order.getColumnName())); } } c.setFirstResult(offset); c.setMaxResults(limit); return c; }
From source file:com.db4o.drs.hibernate.impl.HibernateReplicationProvider.java
License:Open Source License
private Collection getChangedObjectsSinceLastReplication(PersistentClass persistentClass) { Criteria criteria = getSession().createCriteria(ObjectReference.class); long lastReplicationVersion = getLastReplicationVersion(); criteria.add(Restrictions.gt(ObjectReference.Fields.VERSION, lastReplicationVersion)); criteria.add(Restrictions.lt(ObjectReference.Fields.VERSION, _commitTimestamp)); Disjunction disjunction = Restrictions.disjunction(); List<String> names = new ArrayList<String>(); names.add(persistentClass.getClassName()); if (persistentClass.hasSubclasses()) { final Iterator it = persistentClass.getSubclassClosureIterator(); while (it.hasNext()) { PersistentClass subC = (PersistentClass) it.next(); names.add(subC.getClassName()); }/* w w w. j av a2 s .c o m*/ } for (String s : names) disjunction.add(Restrictions.eq(ObjectReference.Fields.CLASS_NAME, s)); criteria.add(disjunction); Set out = new HashSet(); for (Object o : criteria.list()) { ObjectReference ref = (ObjectReference) o; out.add(getSession().load(persistentClass.getRootClass().getClassName(), ref.getTypedId())); } return out; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityFilterDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override/*from www . j a v a 2 s . c o m*/ public List<VulnerabilityFilter> retrieveAllEffective(int orgId) { return getBaseCriteria() .add(Restrictions.disjunction().add(eq("organization.id", orgId)).add(eq("global", true))).list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityFilterDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override/*from ww w.j a v a2 s . c om*/ public List<VulnerabilityFilter> retrieveAllEffective(int orgId, int appId) { return getBaseCriteria().add(Restrictions.disjunction().add(eq("application.id", appId)) .add(eq("organization.id", orgId)).add(eq("global", true))).list(); }