A class that implements this interface can be used as a database table.
You may implement the Table interface on your model object and optionally use JQColumn annotations (which imposes a compile-time and runtime-dependency on JaQu), or may choose to use the JQTable and JQColumn annotations only (which imposes a compile-time and runtime-dependency on this file only).
If a class is annotated with JQTable and at the same time implements Table, the define() method is not called.
Supported data types:
java.lang.String | VARCHAR (maxLength > 0) / TEXT (maxLength == 0) |
java.lang.Boolean | BIT |
java.lang.Byte | TINYINT |
java.lang.Short | SMALLINT |
java.lang.Integer | INT |
java.lang.Long | BIGINT |
java.lang.Float | REAL |
java.lang.Double | DOUBLE |
java.math.BigDecimal | DECIMAL |
java.util.Date | TIMESTAMP |
java.sql.Date | DATE |
java.sql.Time | TIME |
java.sql.Timestamp | TIMESTAMP |
Unsupported data types: binary types (BLOB, etc), and custom types.
Table and field mapping: by default, the mapped table name is the class name and the public fields are reflectively mapped, by their name, to columns. As an alternative, you may specify both the table and column definition by annotations.
Table Interface: you may set additional parameters such as table name, primary key, and indexes in the define() method.
Annotations: you may use the annotations with or without implementing the Table interface. The annotations allow you to decouple your model completely from JaQu other than this file.
Automatic model generation: you may automatically generate model classes as strings with the Db and DbInspector objects:
Db db = Db.open("jdbc:h2:mem:", "sa", "sa"); DbInspector inspector = new DbInspector(db); List<String> models = inspector.generateModel(schema, table, packageName, annotateSchema, trimStrings)
Or you may use the GenerateModels tool to generate and save your classes to the file system:
java -cp h2jaqu.jar org.h2.jaqu.util.GenerateModels -url "jdbc:h2:mem:" -user sa -password sa -schema schemaName -table tableName -package packageName -folder destination -annotateSchema false -trimStrings true
Model validation: you may validate your model class with DbInspector object. The DbInspector will report errors, warnings, and suggestions:
Db db = Db.open("jdbc:h2:mem:", "sa", "sa"); DbInspector inspector = new DbInspector(db); List<Validation> remarks = inspector.validateModel(new MyModel(), throwOnError); for (Validation remark : remarks) { System.out.println(remark); }