|
easyom
EasyOM - Easy Object Mapping
AboutEasyOM - and not EasyORM - because it's not an ORM. This class allows you to persist single objects to the database by adding persistence methods to entity classes. It also adds methods that allow you to execute "StringQueries". EasyOM only works with Firebird and MySQL database. However, since it's just 1 groovy script, it should be pretty easy to make it work with other databases.
Download EasyOM HereConfigurationTo use, extract the zip, findEasyOM.groovy, add it to your project. Either put it in a "util" package or change the package name in the groovy file. Use the following methods to configure EasyOM. public static void init(java.lang.Properties propertiesFile, ServletContext app)This method will call the init(Properties) method and the injectMethod (java.lang.Class) method for each class in the package specified by the "model.package" key in the properties files.
public static void init(java.lang.Properties propFile)Initializes the internal properties and datbase properties used for database operations public static void injectMethods(java.lang.Class clazz)Adds methods to the specified class for persistence and querying. To manually initialize EasyOM and to add the persistence methods to an application's entity classes, invoke the methods like so: // or some other type of bootstrap method
def onApplicationStart(app){
EasyOM.init(loadPropertiesFile("db.properties"))
EasyOM.injectMethods(model.EntityObject1.class)
EasyOM.injectMethods(model.EntityObject2.class)
EasyOM.injectMethods(model.EntityObject3.class)
}or The properties file expected by EasyOM.init() must have the follow name value pairs
Configuring Entity ObjectsTo persist an entity object, the entity has to have 2 additional attributes in addition to its properties.
There 2 additional optional configuration options:
Persistable Entity Object class User {
private def dynamicProperties = []
private static primaryKeys = ['username']
String username
String lastName
String firstName
}
Persistable Entity Object, where entity name does name table name, and an explicit column to property map class User {
def dynamicProperties = []
static primaryKeys = ['username']
static tableName = 'tblProfile' // the table name is tblProfile, not User
static columns = [address: 'address_line_1']
String username
String lastName
String firstName
String address // address is not a real column name, address_line_1 is the column name
}
| |||||||||||||||||||||||||||||||||