Пример #1
0
 private TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> getEffectiveTypes(
     Class<?> type, Class<?>... types) {
   MetadataProvider<EntityMetadata, EntityDiscriminator, RelationMetadata, RelationDiscriminator>
       metadataProvider = sessionContext.getMetadataProvider();
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> effectiveTypes = new TypeMetadataSet<>();
   effectiveTypes.add(metadataProvider.getEntityMetadata(type));
   for (Class<?> otherType : types) {
     effectiveTypes.add(metadataProvider.getEntityMetadata(otherType));
   }
   return effectiveTypes;
 }
Пример #2
0
 private <S, R, T> R createByExample(
     S from,
     Class<R> relationType,
     T to,
     Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> example) {
   MetadataProvider<EntityMetadata, EntityDiscriminator, RelationMetadata, RelationDiscriminator>
       metadataProvider = sessionContext.getMetadataProvider();
   AbstractRelationPropertyMethodMetadata<?> fromProperty =
       metadataProvider.getPropertyMetadata(from.getClass(), relationType, FROM);
   AbstractRelationPropertyMethodMetadata<?> toProperty =
       metadataProvider.getPropertyMetadata(to.getClass(), relationType, TO);
   Entity entity = sessionContext.getEntityInstanceManager().getDatastoreType(from);
   R instance =
       sessionContext
           .getEntityPropertyManager()
           .createRelationReference(entity, fromProperty, to, toProperty, example);
   sessionContext.getInstanceListenerService().postCreate(instance);
   return instance;
 }
Пример #3
0
 @Override
 public <T, M> CompositeObject migrate(
     T instance,
     MigrationStrategy<T, M> migrationStrategy,
     Class<M> targetType,
     Class<?>... targetTypes) {
   AbstractInstanceManager<EntityId, Entity> entityInstanceManager =
       sessionContext.getEntityInstanceManager();
   Entity entity = entityInstanceManager.getDatastoreType(instance);
   DatastoreSession<
           EntityId,
           Entity,
           EntityMetadata,
           EntityDiscriminator,
           RelationId,
           Relation,
           RelationMetadata,
           RelationDiscriminator,
           PropertyMetadata>
       datastoreSession = sessionContext.getDatastoreSession();
   Set<EntityDiscriminator> entityDiscriminators =
       datastoreSession.getDatastoreEntityManager().getEntityDiscriminators(entity);
   MetadataProvider<EntityMetadata, EntityDiscriminator, RelationMetadata, RelationDiscriminator>
       metadataProvider = sessionContext.getMetadataProvider();
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> types =
       metadataProvider.getTypes(entityDiscriminators);
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> effectiveTargetTypes =
       getEffectiveTypes(targetType, targetTypes);
   Set<EntityDiscriminator> targetEntityDiscriminators =
       metadataProvider.getEntityDiscriminators(effectiveTargetTypes);
   datastoreSession
       .getDatastoreEntityManager()
       .migrateEntity(
           entity, types, entityDiscriminators, effectiveTargetTypes, targetEntityDiscriminators);
   entityInstanceManager.removeInstance(instance);
   CompositeObject migratedInstance = entityInstanceManager.updateInstance(entity);
   if (migrationStrategy != null) {
     migrationStrategy.migrate(instance, migratedInstance.as(targetType));
   }
   entityInstanceManager.closeInstance(instance);
   return migratedInstance;
 }