/** * Adds a PersistentEntity instance * * @param javaClass The Java class representing the entity * @param override Whether to override an existing entity * @return The PersistentEntity instance */ public PersistentEntity addPersistentEntity(Class javaClass, boolean override) { Assert.notNull(javaClass, "PersistentEntity class cannot be null"); if (override) { return addPersistentEntityInternal(javaClass, false, canInitializeEntities); } return addPersistentEntity(javaClass); }
protected PersistentEntity createPersistentEntity(Class javaClass, boolean external) { return createPersistentEntity(javaClass); }
public boolean isPersistentEntity(Class type) { return type != null && getPersistentEntity(type.getName()) != null; }
public Collection<PersistentEntity> addPersistentEntities(Class... javaClasses) { Collection<PersistentEntity> entities = new ArrayList<>(); for (Class javaClass : javaClasses) { PersistentEntity entity = createPersistentEntity(javaClass); if(entity == null) continue; registerEntityWithContext(entity); entities.add(entity); } if(canInitializeEntities) { for (PersistentEntity entity : entities) { initializePersistentEntity(entity); } } for (Listener eventListener : eventListeners) { for (PersistentEntity entity : entities) { eventListener.persistentEntityAdded(entity); } } ClassPropertyFetcher.clearCache(); return entities; }
@Override public EntityAccess createEntityAccess(PersistentEntity entity, Object instance) { final ProxyFactory proxyFactory = getProxyFactory(); instance = proxyFactory.unwrap(instance); if(entity != null) { if (entity.getJavaClass() != instance.getClass()) { // try subclass final PersistentEntity subEntity = getPersistentEntity(instance.getClass().getName()); if (subEntity != null) { entity = subEntity; } } return new FieldEntityAccess(entity, instance, getConversionService()); } else { EntityReflector reflector = FieldEntityAccess.getReflector(instance.getClass().getName()); if(reflector != null) { return new FieldEntityAccess(reflector.getPersitentEntity(), instance, conversionService); } else { return new BeanEntityAccess(null, instance); } } } }
public AbstractMappingContext(ConnectionSourceSettings settings) { FieldEntityAccess.clearReflectors(); initialize(settings); }
/** * Adds an external PersistentEntity instance, one that is not managed and persisted by this context * * @param javaClass The Java class representing the entity * @return The PersistentEntity instance */ public PersistentEntity addExternalPersistentEntity(Class javaClass) { Assert.notNull(javaClass, "PersistentEntity class cannot be null"); PersistentEntity entity = persistentEntitiesByName.get(javaClass.getName()); if (entity == null) { entity = addPersistentEntityInternal(javaClass, true, canInitializeEntities); } return entity; }
public void configure(PropertyResolver configuration) { if(configuration == null) { return; } String simpleName = Introspector.decapitalize(getClass().getSimpleName()); String suffix = "MappingContext"; if(simpleName.endsWith(suffix)) { simpleName = simpleName.substring(0, simpleName.length() - suffix.length()); } String prefix = CONFIGURATION_PREFIX + simpleName; String configurationKey = prefix + ".custom.types"; Iterable<CustomTypeMarshaller> customTypeMarshallers = ConfigurationUtils.findServices(configuration, configurationKey, CustomTypeMarshaller.class); for (CustomTypeMarshaller customTypeMarshaller : customTypeMarshallers) { if(customTypeMarshaller.supports(this)) { getMappingFactory().registerCustomType(customTypeMarshaller); } } }
@Override public ProxyHandler getProxyHandler() { return getProxyFactory(); }
public boolean isPersistentEntity(Object value) { return value != null && isPersistentEntity(value.getClass()); }
public void initialize() { for(PersistentEntity entity : persistentEntities) { initializePersistentEntity(entity); FieldEntityAccess.getOrIntializeReflector(entity); } this.initialized = true; }
private PersistentEntity addPersistentEntityInternal(Class javaClass, boolean isExternal, boolean isInitialize) { PersistentEntity entity = createPersistentEntity(javaClass, isExternal); if (entity == null) { return null; } entity.setExternal(isExternal); registerEntityWithContext(entity); if(isInitialize) { initializePersistentEntity(entity); } for (Listener eventListener : eventListeners) { eventListener.persistentEntityAdded(entity); } ClassPropertyFetcher.clearCache(); return entity; }
/** * Constructs a context using the given keyspace * * @param keyspace The keyspace, this is typically the application name */ public KeyValueMappingContext(String keyspace, ConnectionSourceSettings settings) { Assert.notNull(keyspace, "Argument [keyspace] cannot be null"); this.keyspace = keyspace; initializeDefaultMappingFactory(keyspace); syntaxStrategy = new JpaMappingConfigurationStrategy(this.mappingFactory); super.initialize(settings); }
/** * Adds a PersistentEntity instance * * @param javaClass The Java class representing the entity * @return The PersistentEntity instance */ public PersistentEntity addPersistentEntity(Class javaClass) { Assert.notNull(javaClass, "PersistentEntity class cannot be null"); PersistentEntity entity = persistentEntitiesByName.get(javaClass.getName()); if (entity == null) { entity = addPersistentEntityInternal(javaClass, false, canInitializeEntities); } return entity; }
protected void initialize(ConnectionSourceSettings settings) { this.multiTenancyMode = settings.getMultiTenancy().getMode(); // initialize custom type marshallers MappingFactory mappingFactory = getMappingFactory(); Iterable<CustomTypeMarshaller> customTypeMarshallers = ConfigurationUtils.findServices(settings.getCustom().getTypes(), CustomTypeMarshaller.class); for (CustomTypeMarshaller customTypeMarshaller : customTypeMarshallers) { if(customTypeMarshaller.supports(this)) { mappingFactory.registerCustomType(customTypeMarshaller); } } // default constraints and mapping if(mappingFactory instanceof AbstractGormMappingFactory) { AbstractGormMappingFactory gormMappingFactory = (AbstractGormMappingFactory) mappingFactory; gormMappingFactory.setDefaultConstraints(settings.getDefault().getConstraints()); gormMappingFactory.setDefaultMapping(settings.getDefault().getMapping()); } }
/** * Constructs a context using the given keyspace * * @param keyspace The keyspace, this is typically the application name */ public KeyValueMappingContext(String keyspace) { Assert.notNull(keyspace, "Argument [keyspace] cannot be null"); this.keyspace = keyspace; initializeDefaultMappingFactory(keyspace); syntaxStrategy = new JpaMappingConfigurationStrategy(mappingFactory); super.initialize(new ConnectionSourceSettings()); }
@Override protected void initialize(ConnectionSourceSettings settings) { this.defaultMapping = settings.getDefault().getMapping(); AbstractGormMappingFactory documentMappingFactory = (AbstractGormMappingFactory)createDocumentMappingFactory(defaultMapping); documentMappingFactory.setDefaultConstraints(settings.getDefault().getConstraints()); mappingFactory = documentMappingFactory; syntaxStrategy = new JpaMappingConfigurationStrategy(mappingFactory); super.initialize(settings); }