/** API: Return specification. */
 @Override
 public ObjectSpecification loadSpecification(final Class<?> type) {
   final ObjectSpecification spec = internalLoadSpecification(type);
   if (spec == null) {
     return null;
   }
   if (getCache().isInitialized() && getCache().getByObjectType(spec.getSpecId()) == null) {
     getCache().recache(spec.getSpecId(), spec);
   }
   return spec;
 }
 private ObjectAdapterMemento(final ObjectAdapter adapter) {
   if (adapter == null) {
     throw new IllegalArgumentException("adapter cannot be null");
   }
   final ObjectSpecification specification = adapter.getSpecification();
   objectSpecId = specification.getSpecId();
   init(adapter);
 }
  private void cacheBySpecId() {
    final Map<ObjectSpecId, ObjectSpecification> specById = Maps.newHashMap();
    for (final ObjectSpecification objSpec : allSpecifications()) {
      final ObjectSpecId objectSpecId = objSpec.getSpecId();
      if (objectSpecId == null) {
        continue;
      }
      specById.put(objectSpecId, objSpec);
    }

    getCache().setCacheBySpecId(specById);
  }
Example #4
0
  private void findInstances(
      final ObjectSpecification spec,
      final PersistenceQueryBuiltIn persistenceQuery,
      final List<ObjectAdapter> foundInstances) {

    instancesFor(spec.getSpecId()).findInstancesAndAdd(persistenceQuery, foundInstances);

    // include subclasses
    final List<ObjectSpecification> subclasses = spec.subclasses();
    for (int i = 0; i < subclasses.size(); i++) {
      findInstances(subclasses.get(i), persistenceQuery, foundInstances);
    }
  }
 /**
  * Determines if this class represents the same class, or a subclass, of the specified class.
  *
  * <p>cf {@link Class#isAssignableFrom(Class)}, though target and parameter are the opposite way
  * around, ie:
  *
  * <pre>
  * cls1.isAssignableFrom(cls2);
  * </pre>
  *
  * <p>is equivalent to:
  *
  * <pre>
  * spec2.isOfType(spec1);
  * </pre>
  *
  * <p>Callable after {@link #introspectTypeHierarchyAndMembers()} has been called.
  */
 @Override
 public boolean isOfType(final ObjectSpecification specification) {
   // do the comparison using value types because of a possible aliasing/race condition
   // in matchesParameterOf when building up contributed associations
   if (specification.getSpecId().equals(this.getSpecId())) {
     return true;
   }
   for (final ObjectSpecification interfaceSpec : interfaces()) {
     if (interfaceSpec.isOfType(specification)) {
       return true;
     }
   }
   final ObjectSpecification superclassSpec = superclass();
   return superclassSpec != null ? superclassSpec.isOfType(specification) : false;
 }
Example #6
0
 @Override
 public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid)
     throws ObjectNotFoundException, ObjectPersistenceException {
   if (LOG.isDebugEnabled()) {
     LOG.debug("getObject " + oid);
   }
   final ObjectSpecification objectSpec =
       getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
   final ObjectStoreInstances ins = instancesFor(objectSpec.getSpecId());
   final ObjectAdapter adapter = ins.getObjectAndMapIfRequired(oid);
   if (adapter == null) {
     throw new ObjectNotFoundException(oid);
   }
   return adapter;
 }
Example #7
0
  @Override
  public boolean hasInstances(final ObjectSpecification spec) {
    if (instancesFor(spec.getSpecId()).hasInstances()) {
      return true;
    }

    // includeSubclasses
    final List<ObjectSpecification> subclasses = spec.subclasses();
    for (int i = 0; i < subclasses.size(); i++) {
      if (hasInstances(subclasses.get(i))) {
        return true;
      }
    }

    return false;
  }
 @Override
 public void validateSpecifications(ValidationFailures validationFailures) {
   final Map<ObjectSpecId, ObjectSpecification> specById = Maps.newHashMap();
   for (final ObjectSpecification objSpec : allSpecifications()) {
     final ObjectSpecId objectSpecId = objSpec.getSpecId();
     if (objectSpecId == null) {
       continue;
     }
     final ObjectSpecification existingSpec = specById.put(objectSpecId, objSpec);
     if (existingSpec == null) {
       continue;
     }
     validationFailures.add(
         "Cannot have two entities with same object type (@ObjectType facet or equivalent) Value; "
             + "both %s and %s are annotated with value of ''%s''.",
         existingSpec.getFullIdentifier(), objSpec.getFullIdentifier(), objectSpecId);
   }
 }
 @Override
 public RootOid getOidForService(ObjectSpecification serviceSpec) {
   ensureOpened();
   return this.registeredServices.get(serviceSpec.getSpecId());
 }
 private void recache(final ObjectSpecification newSpec) {
   getCache().recache(newSpec.getSpecId(), newSpec);
 }
Example #11
0
 @Override
 public RootOid getOidForService(ObjectSpecification serviceSpec) {
   return (RootOid) persistedObjects.getService(serviceSpec.getSpecId());
 }