types.add(values.get(j).toString()); constraint = new PathConstraintMultitype(path, constraintOp, types); } else { if (constraintObj.has("loopPath")) {
/** * Construct a new multi-type constraint. * @param model The model to look for types within. * @param field The subject of the constraint. * @param pcmt The constraint itself. * @return A constraint. * @throws ObjectStoreException if the constraint names types that are not in the model. */ protected static Constraint makeMultiTypeConstraint( Model model, QueryNode field, PathConstraintMultitype pcmt) throws ObjectStoreException { QueryField typeClass = new QueryField((QueryClass) field, "class"); ConstraintOp op = (pcmt.getOp() == ConstraintOp.ISA) ? ConstraintOp.IN : ConstraintOp.NOT_IN; Set<Class<?>> classes = new TreeSet<Class<?>>(new ClassNameComparator()); for (String name: pcmt.getValues()) { ClassDescriptor cd = model.getClassDescriptorByName(name); if (cd == null) { // PathQueries should take care of this, but you know. throw new ObjectStoreException( String.format("%s is not a class in the %s model", name, model.getName())); } classes.add(cd.getType()); } return new BagConstraint(typeClass, op, classes); }
continue; for (String typeName: ((PathConstraintMultitype) constraint).getValues()) { ClassDescriptor cd = model.getClassDescriptorByName(typeName); if (cd == null) {
continue; for (String typeName: ((PathConstraintMultitype) constraint).getValues()) { ClassDescriptor cd = model.getClassDescriptorByName(typeName); if (cd == null) {
typesCollection.add(value.trim()); return new PathConstraintMultitype(path, constraintOp, typesCollection); } else if (PathConstraintAttribute.VALID_OPS.contains(constraintOp)) {
/** * Construct a new multi-type constraint. * @param model The model to look for types within. * @param field The subject of the constraint. * @param pcmt The constraint itself. * @return A constraint. * @throws ObjectStoreException if the constraint names types that are not in the model. */ protected static Constraint makeMultiTypeConstraint( Model model, QueryNode field, PathConstraintMultitype pcmt) throws ObjectStoreException { QueryField typeClass = new QueryField((QueryClass) field, "class"); ConstraintOp op = (pcmt.getOp() == ConstraintOp.ISA) ? ConstraintOp.IN : ConstraintOp.NOT_IN; Set<Class<?>> classes = new TreeSet<Class<?>>(new ClassNameComparator()); for (String name: pcmt.getValues()) { ClassDescriptor cd = model.getClassDescriptorByName(name); if (cd == null) { // PathQueries should take care of this, but you know. throw new ObjectStoreException( String.format("%s is not a class in the %s model", name, model.getName())); } classes.add(cd.getType()); } return new BagConstraint(typeClass, op, classes); }
types.add(values.get(j).toString()); constraint = new PathConstraintMultitype(path, constraintOp, types); } else { if (constraintObj.has("loopPath")) {
typesCollection.add(value.trim()); return new PathConstraintMultitype(path, constraintOp, typesCollection); } else if (PathConstraintAttribute.VALID_OPS.contains(constraintOp)) {
private int runQuery(ConstraintOp op, Collection<String> types) throws ObjectStoreException { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Employable.name"); pq.addConstraint(new PathConstraintMultitype("Employable", op, types)); Query q = MainHelper.makeQuery( pq, new HashMap(), new HashMap(), null, new HashMap()); Results res = osw.execute(q, 50000, true, false, true); return res.size(); }
public void testMultiTypeQuery() throws Exception { PathQuery pq = new PathQuery(Model.getInstanceByName("testmodel")); pq.addViews("Employable.name"); pq.addConstraint(new PathConstraintMultitype("Employable", ConstraintOp.ISA, Arrays.asList("Contractor", "Manager"))); assertEquals(pq.toString(), savedQueries.get("multitype").toString()); }
@Test public void isntOnRef() throws ObjectStoreException { Collection<String> types = Arrays.asList("CEO", "Contractor"); PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.employees.name"); pq.addConstraint(Constraints.eq("Department.name", tempDepartment.getName())); PathQuery all = pq.clone(); pq.addConstraint(new PathConstraintMultitype("Department.employees", ConstraintOp.ISNT, Arrays.asList("Manager", "CEO"))); Query q = MainHelper.makeQuery( pq, new HashMap(), new HashMap(), null, new HashMap()); Query qall = MainHelper.makeQuery( all, new HashMap(), new HashMap(), null, new HashMap()); Results res = osw.execute(q, 50000, true, false, true); Results resall = osw.execute(qall, 50000, true, false, true); assertEquals(res.size(), resall.size() - (types.size() * SET_SIZE)); } }
public void testMultiTypeConstraint() throws Exception { Model model = Model.getInstanceByName("testmodel"); PathQuery q = new PathQuery(model); q.addView("Employable.name"); assertNotNull(q.addConstraint(new PathConstraintMultitype( "Employable", ConstraintOp.ISA, Arrays.asList("Contractor", "Manager")))); assertEquals(Collections.EMPTY_LIST, q.verifyQuery()); q.clearConstraints(); assertTrue(q.isValid()); q.addConstraint(new PathConstraintMultitype( // Bank cannot be an Employable "Employable", ConstraintOp.ISA, Arrays.asList("Contractor", "Bank"))); assertTrue(!q.isValid()); q.clearConstraints(); assertTrue(q.isValid()); q.addConstraint(new PathConstraintMultitype( // Contractors are not Employees "Employee", ConstraintOp.ISA, Arrays.asList("Contractor", "Manager"))); assertTrue(!q.isValid()); q.clearConstraints(); assertTrue(q.isValid()); q.addConstraint(new PathConstraintMultitype( // No such classes Foo and Bar "Employee", ConstraintOp.ISA, Arrays.asList("Foo", "Bar"))); assertTrue(!q.isValid()); q.clearConstraints(); assertTrue(q.isValid()); q.addConstraint(new PathConstraintMultitype( // Path is an attribute. "Employee.name", ConstraintOp.ISA, Arrays.asList("Contractor", "Manager"))); assertTrue(!q.isValid()); }