示例#1
0
 public Constraints constraints() {
   synchronized (streamLock()) {
     Constraint[] constraints = new Constraint[i_constraints.size()];
     i_constraints.toArray(constraints);
     return new QConstraints(_trans, constraints);
   }
 }
示例#2
0
  public void run(STClass[] classes, STEngine[] engines, boolean a_quiet) {
    begin();
    setSodaTestOn(classes);

    for (int i = 0; i < engines.length; i++) {
      engine = engines[i];
      engine.reset();
      engine.open();
      store(classes);
      engine.commit();
      engine.close();
      engine.open();
      test(classes);
      engine.close();
      engine.reset();
    }

    if (failedTestClasses.size() > 0) {
      System.err.println("\nFailed test classes:\n");
      Iterator4 i = failedTestClasses.iterator();
      while (i.moveNext()) {
        System.err.println(i.current().getClass().getName());
      }
      System.err.println("\n");
    }
  }
 private static Collection4 collectNames(Class[] classes) {
   Collection4 names = new Collection4();
   for (int classIdx = 0; classIdx < classes.length; classIdx++) {
     names.add(classes[classIdx].getName());
   }
   return names;
 }
 public void run() {
   dontRemove = true;
   Collection4 copy = new Collection4(_containers);
   Iterator4 i = copy.iterator();
   while (i.moveNext()) {
     ((ObjectContainerBase) i.current()).shutdownHook();
   }
 }
示例#5
0
 private void writeCachedDirty() {
   Iterator4 i = _dirtyClassMetadata.iterator();
   while (i.moveNext()) {
     PersistentBase dirty = (PersistentBase) i.current();
     dirty.write(systemTransaction());
     dirty.notCachedDirty();
   }
   _dirtyClassMetadata.clear();
 }
示例#6
0
 private Collection4 fieldPathFromTop() {
   QQueryBase q = this;
   final Collection4 fieldPath = new Collection4();
   while (q.i_parent != null) {
     fieldPath.prepend(q.i_field);
     q = q.i_parent;
   }
   return fieldPath;
 }
示例#7
0
 Constraint toConstraint(final Collection4 constraints) {
   if (constraints.size() == 1) {
     return (Constraint) constraints.singleElement();
   } else if (constraints.size() > 0) {
     Constraint[] constraintArray = new Constraint[constraints.size()];
     constraints.toArray(constraintArray);
     return new QConstraints(_trans, constraintArray);
   }
   return null;
 }
示例#8
0
 public void error(String msg) {
   if (!failedTestClasses.contains(currentTestClass)) {
     failedTestClasses.add(currentTestClass);
   }
   if (!quiet) {
     System.err.println(msg);
     new ExpectationFailed().printStackTrace();
     System.err.println();
   }
 }
 private boolean expect(ObjectContainer container, String[] names) {
   Collection4 expected = new Collection4(names);
   ObjectSet actual = container.query(CrashData.class);
   while (actual.hasNext()) {
     CrashData current = (CrashData) actual.next();
     if (!expected.remove(current._name)) {
       return false;
     }
   }
   return expected.isEmpty();
 }
 public static void main(String[] args) throws Exception {
   ClassLoader parent = ExcludingClassLoader.class.getClassLoader();
   String excName = ExcludingClassLoader.class.getName();
   Collection4 excluded = new Collection4();
   ClassLoader incLoader = new ExcludingClassLoader(parent, excluded);
   System.out.println(incLoader.loadClass(excName));
   excluded.add(excName);
   try {
     System.out.println(incLoader.loadClass(excName));
   } catch (ClassNotFoundException exc) {
     System.out.println("Ok, not found.");
   }
 }
示例#11
0
 public static void sameContent(Iterator expected, Iterator actual) {
   final Collection4 allExpected = new Collection4();
   while (expected.hasNext()) {
     allExpected.add(expected.next());
   }
   while (actual.hasNext()) {
     final Object current = actual.next();
     final boolean removed = allExpected.remove(current);
     if (!removed) {
       unexpected(current);
     }
   }
   Assert.isTrue(allExpected.isEmpty(), allExpected.toString());
 }
示例#12
0
  private Constraint addEvaluationToAllConstraints(QConEvaluation eval) {

    if (i_constraints.size() == 0) {
      _trans
          .container()
          .classCollection()
          .iterateTopLevelClasses(
              new Visitor4() {
                public void visit(Object obj) {
                  ClassMetadata classMetadata = (ClassMetadata) obj;
                  QConClass qcc = new QConClass(_trans, classMetadata.classReflector());
                  addConstraint(qcc);
                  toConstraint(i_constraints).or(qcc);
                }
              });
    }

    Iterator4 i = iterateConstraints();
    while (i.moveNext()) {
      ((QCon) i.current()).addConstraint(eval);
    }

    // FIXME: should return valid Constraint object
    return null;
  }
示例#13
0
 private Collection4 introduceClassConstrain(ReflectClass claxx) {
   final Collection4 newConstraints = new Collection4();
   final Iterator4 existingConstraints = iterateConstraints();
   while (existingConstraints.moveNext()) {
     final QCon existingConstraint = (QConObject) existingConstraints.current();
     final BooleanByRef removeExisting = new BooleanByRef(false);
     final QCon newConstraint = existingConstraint.shareParentForClass(claxx, removeExisting);
     if (newConstraint != null) {
       newConstraints.add(newConstraint);
       addConstraint(newConstraint);
       if (removeExisting.value) {
         removeConstraint(existingConstraint);
       }
     }
   }
   return newConstraints;
 }
示例#14
0
  private Constraint addClassConstraint(ReflectClass claxx) {
    if (isTheObjectClass(claxx)) {
      return null;
    }

    if (claxx.isInterface()) {
      return addInterfaceConstraint(claxx);
    }

    final Collection4 newConstraints = introduceClassConstrain(claxx);
    if (newConstraints.isEmpty()) {
      QConClass qcc = new QConClass(_trans, claxx);
      addConstraint(qcc);
      return qcc;
    }

    return toConstraint(newConstraints);
  }
示例#15
0
 private QConClass classConstraint() {
   if (i_constraints.size() != 1) {
     return null;
   }
   Constraint constr = singleConstraint();
   if (constr.getClass() != QConClass.class) {
     return null;
   }
   return (QConClass) constr;
 }
示例#16
0
 private void addConstraint(Collection4 col, Object obj) {
   if (attachToExistingConstraints(col, obj, true)) {
     return;
   }
   if (attachToExistingConstraints(col, obj, false)) {
     return;
   }
   QConObject newConstraint = new QConObject(_trans, null, null, obj);
   addConstraint(newConstraint);
   col.add(newConstraint);
 }
  public void test() {

    final Collection4 expected =
        new Collection4(new Object[] {"PING", Boolean.TRUE, new Integer(42)});
    final MessageCollector recipient = new MessageCollector();
    final ObjectServer server = openServerWith(recipient);
    try {
      final ObjectContainer client = openClient("client", server);
      try {
        final MessageSender sender = messageSender(client);
        sendAll(expected, sender);
      } finally {
        client.close();
      }
    } finally {
      server.close();
    }

    Assert.areEqual(expected.toString(), recipient.messages.toString());
  }
示例#18
0
 public QueryResult getQueryResult() {
   synchronized (streamLock()) {
     if (i_constraints.size() == 0) {
       return executeAllObjectsQuery();
     }
     QueryResult result = executeClassOnlyQuery();
     if (result != null) {
       return result;
     }
     optimizeJoins();
     return executeQuery();
   }
 }
示例#19
0
  public Iterator4 executeSnapshot() {
    final CreateCandidateCollectionResult r = createCandidateCollection();

    final Collection4 executionPath = executionPath(r);

    Iterator4 candidatesIterator = new Iterator4Impl(r.candidateCollection);

    Collection4 snapshots = new Collection4();
    while (candidatesIterator.moveNext()) {
      QCandidates candidates = (QCandidates) candidatesIterator.current();
      snapshots.add(candidates.executeSnapshot(executionPath));
    }

    Iterator4 snapshotsIterator = snapshots.iterator();
    final CompositeIterator4 resultingIDs = new CompositeIterator4(snapshotsIterator);

    if (!r.checkDuplicates) {
      return resultingIDs;
    }

    return checkDuplicates(resultingIDs);
  }
示例#20
0
 private Constraint addInterfaceConstraint(ReflectClass claxx) {
   Collection4 classes = stream().classCollection().forInterface(claxx);
   if (classes.size() == 0) {
     QConClass qcc = new QConClass(_trans, null, null, claxx);
     addConstraint(qcc);
     return qcc;
   }
   Iterator4 i = classes.iterator();
   Constraint constr = null;
   while (i.moveNext()) {
     ClassMetadata classMetadata = (ClassMetadata) i.current();
     ReflectClass classMetadataClaxx = classMetadata.classReflector();
     if (classMetadataClaxx != null) {
       if (!classMetadataClaxx.isInterface()) {
         if (constr == null) {
           constr = constrain(classMetadataClaxx);
         } else {
           constr = constr.or(constrain(classMetadata.classReflector()));
         }
       }
     }
   }
   return constr;
 }
 protected synchronized Class loadClass(String name, boolean resolve)
     throws ClassNotFoundException {
   if (_excludedNames.contains(name)) {
     print("EXCLUDED: " + name);
     throw new ClassNotFoundException(name);
   }
   if (_cache.containsKey(name)) {
     print("CACHED: " + name);
     return (Class) _cache.get(name);
   }
   if (mustDelegate(name)) {
     print("NATIVE: " + name);
     return super.loadClass(name, resolve);
   }
   Class clazz = findRawClass(name);
   if (resolve) {
     resolveClass(clazz);
   }
   _cache.put(clazz.getName(), clazz);
   print("LOADED: " + name);
   return clazz;
 }
示例#22
0
 private boolean attachToExistingConstraints(
     Collection4 newConstraintsCollector, Object obj, boolean onlyForPaths) {
   boolean found = false;
   final Iterator4 j = iterateConstraints();
   while (j.moveNext()) {
     QCon existingConstraint = (QCon) j.current();
     final BooleanByRef removeExisting = new BooleanByRef(false);
     if (!onlyForPaths || (existingConstraint instanceof QConPath)) {
       QCon newConstraint = existingConstraint.shareParent(obj, removeExisting);
       if (newConstraint != null) {
         newConstraintsCollector.add(newConstraint);
         addConstraint(newConstraint);
         if (removeExisting.value) {
           removeConstraint(existingConstraint);
         }
         found = true;
         if (!onlyForPaths) {
           break;
         }
       }
     }
   }
   return found;
 }
示例#23
0
  private boolean descend1(final QQuery query, final String fieldName, IntByRef run) {
    if (run.value == 2 || i_constraints.size() == 0) {

      // On the second run we are really creating a second independant
      // query network that is not joined to other higher level
      // constraints.
      // Let's see how this works out. We may need to join networks.

      run.value = 0; // prevent a double run of this code

      stream()
          .classCollection()
          .attachQueryNode(
              fieldName,
              new Visitor4() {

                boolean untypedFieldConstraintCollected = false;

                public void visit(Object obj) {

                  Object[] pair = ((Object[]) obj);
                  ClassMetadata containingClass = (ClassMetadata) pair[0];
                  FieldMetadata field = (FieldMetadata) pair[1];

                  if (isTyped(field)) {
                    addFieldConstraint(containingClass, field);
                    return;
                  }

                  if (untypedFieldConstraintCollected) return;

                  addFieldConstraint(containingClass, field);
                  untypedFieldConstraintCollected = true;
                }

                private boolean isTyped(FieldMetadata field) {
                  return !Handlers4.isUntyped(field.getHandler());
                }

                private void addFieldConstraint(
                    ClassMetadata containingClass, FieldMetadata field) {
                  QConClass qcc =
                      new QConClass(
                          _trans, null, field.qField(_trans), containingClass.classReflector());
                  addConstraint(qcc);
                  toConstraint(i_constraints).or(qcc);
                }
              });
    }

    checkConstraintsEvaluationMode();

    final BooleanByRef foundClass = new BooleanByRef(false);
    Iterator4 i = iterateConstraints();
    while (i.moveNext()) {
      if (((QCon) i.current()).attach(query, fieldName)) {
        foundClass.value = true;
      }
    }
    return foundClass.value;
  }
示例#24
0
 public static int failedClassesSize() {
   return failedTestClasses.size();
 }
示例#25
0
 private Constraint singleConstraint() {
   return (Constraint) i_constraints.singleElement();
 }
 public void add(TestFailure failure) {
   _failures.add(failure);
 }
 /** @sharpen.property Count */
 public int size() {
   return _failures.size();
 }
示例#28
0
 void removeConstraint(QCon a_constraint) {
   i_constraints.remove(a_constraint);
 }
示例#29
0
 void addConstraint(QCon a_constraint) {
   i_constraints.add(a_constraint);
 }
 public Iterator4 iterator() {
   return _failures.iterator();
 }