public Object unmarshall(Resource resource, MarshallingContext context) throws CompassException {
   ResourceMapping resourceMapping = mapping.getRootMappingByAlias(resource.getAlias());
   if (resourceMapping == null) {
     throw new MarshallingException(
         "No mapping is defined for alias [ " + resource.getAlias() + "]");
   }
   return resourceMapping.getConverter().unmarshall(resource, resourceMapping, context);
 }
 public Resource marshall(String alias, Object root) {
   ResourceMapping resourceMapping = mapping.getRootMappingByAlias(alias);
   if (resourceMapping == null) {
     return null;
   }
   Resource resource = resourceFactory.createResource(alias);
   resourceMapping.getConverter().marshall(resource, root, resourceMapping, createContext());
   return resource;
 }
 public Resource marshall(Object root) {
   if (root instanceof AliasedObject) {
     return marshall(((AliasedObject) root).getAlias(), root);
   }
   ResourceMapping resourceMapping = mapping.getRootMappingByClass(root.getClass());
   if (resourceMapping == null) {
     return null;
   }
   Resource resource = resourceFactory.createResource(resourceMapping.getAlias());
   resourceMapping.getConverter().marshall(resource, root, resourceMapping, createContext());
   return resource;
 }
 /**
  * Get the identifier of the given domain class instance
  *
  * @param compass Compass
  * @param alias Compass alias
  * @param instance object instance
  * @return identifier
  */
 public static Serializable getIdent(Compass compass, String alias, Object instance) {
   Assert.notNull(alias, "alias cannot be null");
   ResourceMapping resourceMapping =
       ((InternalCompass) compass).getMapping().getMappingByAlias(alias);
   Mapping[] ids = resourceMapping.getIdMappings();
   if (ids == null || ids.length == 0) {
     throw new IllegalArgumentException("Null or empty id mappings for alias [" + alias + "]");
   }
   if (ids.length > 1) {
     throw new IllegalArgumentException(
         "Too many id mappings for alias [" + alias + "]: expected only 1");
   }
   return (Serializable) ((ObjectMapping) ids[0]).getGetter().get(instance);
 }
 public void marshallIds(Object root, Object id) {
   ResourceMapping resourceMapping = mapping.getMappingByClass(root.getClass());
   if (resourceMapping == null) {
     throw new MarshallingException(
         "No resource mapping is defined for class [" + root.getClass() + "]");
   }
   Mapping[] ids = resourceMapping.getIdMappings();
   if (ids == null || ids.length == 0) {
     return;
   }
   Object[] idsValues = unmarshallIds(resourceMapping, id, createContext());
   for (int i = 0; i < idsValues.length; i++) {
     setId(root, idsValues[i], (ObjectMapping) ids[i]);
   }
 }
 public void marshallIds(ResourceMapping resourceMapping, Object root, Object id) {
   Mapping[] ids = resourceMapping.getIdMappings();
   if (ids.length == 0) {
     return;
   }
   Object[] idsValues = unmarshallIds(resourceMapping, id, createContext());
   for (int i = 0; i < idsValues.length; i++) {
     setId(root, idsValues[i], (ObjectMapping) ids[i]);
   }
 }
  public EntityInformation[] locate(EntityManagerFactory entityManagerFactory, JpaGpsDevice device)
      throws JpaGpsDeviceException {

    CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps();

    HibernateEntityManagerFactory hibernateEntityManagerFactory =
        (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = hibernateEntityManagerFactory.getSessionFactory();

    ArrayList<EntityInformation> entitiesList = new ArrayList<EntityInformation>();

    Map allClassMetaData = sessionFactory.getAllClassMetadata();
    for (Object o : allClassMetaData.keySet()) {
      String entityname = (String) o;
      if (!gps.hasMappingForEntityForIndex((entityname))) {
        if (log.isDebugEnabled()) {
          log.debug("Entity [" + entityname + "] does not have compass mapping, filtering it out");
        }
        continue;
      }

      ClassMetadata classMetadata = (ClassMetadata) allClassMetaData.get(entityname);
      if (shouldFilter(entityname, classMetadata, allClassMetaData, device)) {
        continue;
      }
      Class<?> clazz = classMetadata.getMappedClass();
      ResourceMapping resourceMapping = gps.getMappingForEntityForIndex(entityname);
      EntityInformation entityInformation =
          new EntityInformation(
              clazz,
              entityname,
              new HibernateJpaQueryProvider(clazz, entityname),
              resourceMapping.getSubIndexHash().getSubIndexes());
      entitiesList.add(entityInformation);
      if (log.isDebugEnabled()) {
        log.debug("Entity [" + entityname + "] will be indexed");
      }
    }
    return entitiesList.toArray(new EntityInformation[entitiesList.size()]);
  }
Exemple #8
0
 public AllTermsCache(CompassSettings settings, CompassMapping mapping) {
   for (ResourceMapping resourceMapping : mapping.getRootMappings()) {
     if (resourceMapping.getAllMapping().isExcludeAlias()) {
       aliasTokensPerRootAlias.put(resourceMapping.getAlias(), new Token[0]);
     } else {
       List<Token> aliasTokens = new ArrayList<Token>();
       aliasTokens.add(
           new Token(
               resourceMapping.getAlias().toLowerCase(), 0, resourceMapping.getAlias().length()));
       for (String extendedAlias : resourceMapping.getExtendedAliases()) {
         aliasTokens.add(new Token(extendedAlias.toLowerCase(), 0, extendedAlias.length()));
       }
       aliasTokensPerRootAlias.put(
           resourceMapping.getAlias(), aliasTokens.toArray(new Token[aliasTokens.size()]));
     }
   }
 }
Exemple #9
0
 public ResourceKey(ResourceMapping resourceMapping, Property[] ids) {
   this.resourceMapping = resourceMapping;
   this.ids = ids;
   this.alias = resourceMapping.getAlias();
 }
 public boolean marshallIds(
     Resource resource, ResourceMapping resourceMapping, Object id, MarshallingContext context) {
   return ((ResourceMappingConverter) resourceMapping.getConverter())
       .marshallIds(resource, id, resourceMapping, context);
 }
 public Resource marshallIds(ResourceMapping resourceMapping, Object id) {
   Resource idResource = resourceFactory.createResource(resourceMapping.getAlias());
   marshallIds(idResource, resourceMapping, id, createContext());
   return idResource;
 }
 public Object[] unmarshallIds(
     ResourceMapping resourceMapping, Object id, MarshallingContext context) {
   return ((ResourceMappingConverter) resourceMapping.getConverter())
       .unmarshallIds(id, resourceMapping, context);
 }