diff options
Diffstat (limited to 'src/site/04_tools.mkd')
-rw-r--r-- | src/site/04_tools.mkd | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/site/04_tools.mkd b/src/site/04_tools.mkd new file mode 100644 index 0000000..6d8c348 --- /dev/null +++ b/src/site/04_tools.mkd @@ -0,0 +1,95 @@ +## Model Generation
+If you do not have or do not want to annotate your existing model classes, you can use the included model generation tool to create iciql model classes.
+
+ java -jar iciql.jar <parameters>
+
+### Parameters
+<table class="table">
+<tr><th>-url</th><td>JDBC url for the database</td><td><em>REQUIRED</em></td></tr>
+<tr><th>-username</th><td>username for JDBC connection</td><td><em>optional</em></td></tr>
+<tr><th>-password</th><td>password for JDBC connection</td><td><em>optional</em></td></tr>
+<tr><th>-schema</th><td>the target schema for model generation</td><td><em>default:</em> all schemas</td></tr>
+<tr><th>-table</th><td>the target table for model generation</td><td><em>default:</em> all tables</td></tr>
+<tr><th>-package</th><td>the destination package name for generated models</td><td><em>default:</em> default package</td></tr>
+<tr><th>-folder</th><td>the output folder for .java files</td><td><em>default:</em> current folder</td></tr>
+<tr><th>-annotateSchema</th><td>include the schema name in the class annotations</td><td><em>default:</em> true</td></tr>
+<tr><th>-trimStrings</th><td>annotate trimStrings=true for any VARCHAR string mappings </td><td><em>default:</em> false</td></tr>
+</table>
+
+## Model Validation
+Iciql can validate your model classes against your database to ensure that your models are optimally defined and are consistent with the current table and index definitions.
+
+Each `com.iciql.ValidationRemark` returned by the validation has an associated level from the following enum:
+%BEGINCODE%
+public static enum Level {
+ CONSIDER, WARN, ERROR;
+}
+%ENDCODE%
+
+A typical validation may output recommendations for adjusting a model field annotation such as setting the *maxLength* of a string to match the length of its linked VARCHAR column.
+
+### Sample Model Validation using JUnit 4
+%BEGINCODE%
+import static org.junit.Assert.assertTrue;
+
+import java.sql.SQLException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ErrorCollector;
+
+import com.iciql.Db;
+import com.iciql.DbInspector;
+import com.iciql.ValidationRemark;
+import com.iciql.test.models.Product;
+import com.iciql.test.models.ProductAnnotationOnly;
+import com.iciql.test.models.ProductMixedAnnotation;
+
+public class ValidateModels {
+
+ /*
+ * The ErrorCollector Rule allows execution of a test to continue after the
+ * first problem is found and report them all at once
+ */
+ @Rule
+ public ErrorCollector errorCollector = new ErrorCollector();
+
+ private Db db;
+
+ @Before
+ public void setUp() {
+ db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ }
+
+ @After
+ public void tearDown() {
+ db.close();
+ }
+
+ @Test
+ public void testValidateModels() {
+ DbInspector inspector = new DbInspector(db);
+ validateModel(inspector, new Product());
+ validateModel(inspector, new ProductAnnotationOnly());
+ validateModel(inspector, new ProductMixedAnnotation());
+ }
+
+ private void validateModel(DbInspector inspector, Object o) {
+ List<ValidationRemark> remarks = inspector.validateModel(o, false);
+ assertTrue("Validation remarks are null for " + o.getClass().getName(), remarks != null);
+ log("Validation remarks for " + o.getClass().getName());
+ for (ValidationRemark remark : remarks) {
+ log(remark.toString());
+ if (remark.isError()) {
+ errorCollector.addError(new SQLException(remark.toString()));
+ }
+ }
+ }
+
+ private void log(String message) {
+ System.out.println(message);
+ }
+}
+%ENDCODE%
\ No newline at end of file |