-
Notifications
You must be signed in to change notification settings - Fork 2
Functionality
This is the step by step to execute the mapping:
Step 1: Resolves the class to ClassTypeInfo, MethodTypeInfo, PropertyTypeInfo, and FieldTypeInfo via the etk-reflection.
Note: Before this mapping, the ORMBuilder uses the ServiceLoader to load the ORMBuilderImpl from the /resources/META-INF/services/org.etk.orm.api.ORMBuilder file and it contains the className refer to the ORMBuilderImpl. Here is code for that:
public static ORMBuilder create() {
ServiceLoader<ORMBuilder> loader = ServiceLoader.load(ORMBuilder.class);
Iterator<ORMBuilder> i = loader.iterator();
Throwable throwable = null;
while (i.hasNext()) {
try {
ORMBuilder builder = i.next();
log.debug("Found ORMBuilder implementation " + builder.getClass().getName());
return builder;
}
catch (ServiceConfigurationError error) {
if (throwable == null) {
throwable = error;
}
log.debug("Could not load ORMBuilder implementation, will use next provider", error);
}
}
throw new BuilderException("Could not instanciate builder", throwable);
}
Step 2: Executes the ORMBuilder to addClass(clazz) to prepare the Resolver.
Step 3: Executes the ORMBuilder.build() method, it 's very important to create the mapping, mapper and ObjectContext:
protected void init(Set<Class<?>> classes) throws BuilderException {
SimpleTypeResolver propertyTypeResolver = new SimpleTypeResolver();
TypeResolver<Type> typeResolver = TypeResolverImpl.create(JLReflectionMetadata.newInstance());
//Build mappings
Set<ClassTypeInfo> classTypes = new HashSet<ClassTypeInfo>();
//converts the classes to the set of ClassTypeInfo via the TypeResolver.
for (Class clazz : classes) {
ClassTypeInfo typeInfo = (ClassTypeInfo) typeResolver.resolve(clazz);
classTypes.add(typeInfo);
}
Map<ClassTypeInfo, BeanMapping> beanMappings = new BeanMappingBuilder().build(classTypes);
Collection<BeanMapping> mappings = beanMappings.values();
// Build mappers
MapperBuilder builder = new MapperBuilder(propertyTypeResolver);
Collection<ObjectMapper<?>> mappers = builder.build(mappings);
//
this.mappers = mappers;
}
Step 4: Using the BeanBuilderMapper to create BeanMapping which contains the PropertyMapping, MethodMapping, EntityTypeKind, EntityTypeName and EntityInfo.
Step 5: Creates the ObjectMapper to use the MapperBuilder. It contains to manipulate with the Entity such as MethodMapper, BeanMapping, PropertyMapper, MethodInvoker.
Step 6: Uses the EntitiSessionImpl.create(AClass.class, "aclass"); to make the ObjectContext which allows you to do with the Entity via these methods:
- invoke(object, method, args)
- setProperty()
- getProperty()