Пример #1
0
 /**
  * Returns mapped domain name (*unprefixed*) for the specified @{link PersistentEntity}.
  *
  * @param entity
  * @return
  */
 public static String getMappedDomainName(PersistentEntity entity) {
   @SuppressWarnings("unchecked")
   ClassMapping<SimpleDBDomainClassMappedForm> classMapping = entity.getMapping();
   SimpleDBDomainClassMappedForm mappedForm = classMapping.getMappedForm();
   String entityFamily = getFamily(entity, mappedForm);
   return entityFamily;
 }
    @Override
    public IdentityMapping createIdentityMapping(final ClassMapping classMapping) {
      final Mapping mappedForm = createMappedForm(classMapping.getEntity());
      final Object identity = mappedForm.getIdentity();
      final ValueGenerator generator;
      if (identity instanceof Identity) {
        Identity id = (Identity) identity;
        String generatorName = id.getGenerator();
        if (generatorName != null) {
          try {
            generator = ValueGenerator.valueOf(generatorName.toUpperCase());
          } catch (IllegalArgumentException e) {
            throw new DatastoreConfigurationException(
                "Invalid id generation strategy for entity ["
                    + classMapping.getEntity().getName()
                    + "]: "
                    + generatorName);
          }
        } else {
          generator = ValueGenerator.AUTO;
        }
      } else {
        generator = ValueGenerator.AUTO;
      }
      return new IdentityMapping() {
        @Override
        public String[] getIdentifierName() {
          if (identity instanceof Identity) {
            final String name = ((Identity) identity).getName();
            if (name != null) {
              return new String[] {name};
            } else {
              return DEFAULT_IDENTITY_MAPPING;
            }
          } else if (identity instanceof CompositeIdentity) {
            return ((CompositeIdentity) identity).getPropertyNames();
          }
          return DEFAULT_IDENTITY_MAPPING;
        }

        @Override
        public ValueGenerator getGenerator() {

          return generator;
        }

        @Override
        public ClassMapping getClassMapping() {
          return classMapping;
        }

        @Override
        public Property getMappedForm() {
          return (Property) identity;
        }
      };
    }
 private PersistentEntity getPersistentEntity(
     Class javaClass, MappingContext context, ClassMapping classMapping) {
   PersistentEntity entity;
   if (classMapping != null) {
     entity = classMapping.getEntity();
   } else {
     entity = context.getPersistentEntity(javaClass.getName());
   }
   return entity;
 }