Here we present some advanced topics about TMS Aurelius.
TMS Aurelius has a single global class that has some properties for
setting global configuration. This class is declared in unit
Aurelius.Global.Config, and to access the global configuration object,
uses Aurelius.Global.Config; ... Configs := TGlobalConfigs.GetInstance;
The following properties are available in the TGlobalConfigs object:
If true, all statements are not executed on the DBMS, but appear in the listeners.
Indicates the maximum depth to load objects in eager loading associations. Beyond this depth, the objects still load in lazy mode.
If true, all classes declared in your application with [Entity] attribute are automatically added to the framework's MappedClasses. Removed in version 2.0: Use TMappingSetup.MappedClasses property instead.
If true, in enumerations mapped to string columns with no length specified in the Column attribute will generate the column length equal to the largest possible value of the enumeration. Otherwise, the length is DefaultStringColWidth by default (when not specified in Column attribute).
Defines the automapping mode. Valid values are:
- Off: No automatic mapping. Only elements with attributes are mapped.
- ByClass: Automapping is done for classes marked with Automapping attribute.
- Full: Full automapping over every registered class and Enumerations.
If AutoMapping is enabled, defines the default cascade type for all automapped associations (AutoMappingDefaultCascade) and many-valued associations (AutoMappingDefaultCascadeManyValued).
Default values are:
AutoMappingDefaultCascade := CascadeTypeAll - [TCascadeType.Remove]; AutoMappingDefaultCascadeManyValued := CascadeTypeAll;
Defines the width for string (usually varchar) columns when the width was not particularly specified in Column attribute.
Defines the default value for the TObjectManager.UseTransactions. Default is true, meaning all internal manager operations will be performed with transactions. If you want to disable this (mostly for backward compatibility) for the whole application instead of setting the property for each manager, you can set this property to false.
Defines the default value for the TDatabaseManager.UseTransactions. Default is false, meaning no transactions will be used to execute SQL statements for creating/updating tables, columns, foreign keys, etc. If you want to enable this for the whole application instead of setting the property for each database manager, you can set this property to true.
In several conditions, Aurelius needs to create entity instances. For example, when retrieving entities from the database, Aurelius needs to create instances of those entities. To do that, Aurelius uses an internal object factory. By default, this factory just creates entities by calling a parameter-less constructor named "Create".
Such mechanism works in most cases. But in the case you want to create your entities yourself (for example all your entities have a Create constructor that need to receive a parameter), you can change the object factory and implement it yourself.
To do that, all you need is to implement an IObjectFactory interface
(declared in unit
IObjectFactory = interface function CreateInstance(AClass: TClass): TObject; end;
It has a single method CreateInstance which receives the TClass and must return a TObject which is a new instance of that class.
Once you have created such instance, you can replace the default one used by Aurelius. You can do it at the TMappingExplorer level, thus changing the factory for everything in Aurelius that is related to that explorer:
TMappingExplorer.Default.ObjectFactory := MyObjectFactory;
Or you can change it for a TObjectManager object specifically. This gives you more fine-grained control, for example in case your entities need to be created under a specific context:
Manager.ObjectFactory := MyObjectFactory;