-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added command line support for generate-dkos
- Loading branch information
Showing
7 changed files
with
781 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
Fake Foreign Keys | ||
================= | ||
|
||
Usually DKOs use the automatically generated FK relationships extracted from the database. But sometimes | ||
those foreign keys aren't actually there. (Almost always for performance reasons.) Specifying this file lets | ||
you add FK relationships to the generated code regardless (for all the `with(FK)` goodness). The format is | ||
JSON, like the following: | ||
|
||
```json | ||
{ | ||
"fk_name_1":{ | ||
"reffing": ["my_schema","product"], | ||
"reffed": ["my_schema","manufacturer"], | ||
"columns": {"manufacturer_id": "id"} | ||
}, | ||
} | ||
``` | ||
|
||
This will create a FK relationship from the 'reffing' table's `product.manufacturer_id` to the 'reffed' | ||
table's `manufacturer.id`. Compound keys are additional entries in the "columns" map. | ||
|
||
The foreign key names (`fk_name_1`) don't matter, as long as they're unique in the file. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
Type Mappings | ||
============= | ||
|
||
DKOs have default Java types for each database column type known. But sometimes you don't want what's being | ||
offered. If you want to change the type of a generated field, you need to create a `type_mapping.json` file. | ||
|
||
for instance, if you want all `java.sql.TimeStamp`s changed to `java.util.Date` (because the time components | ||
are always ignored by your app), you need a `class_mappings` entry in your `type_mapping.json`. An example: | ||
|
||
```json | ||
{ | ||
"class_mappings": { | ||
"java.sql.Timestamp": "java.util.Date", | ||
}, | ||
"functions": { | ||
"java.sql.Timestamp java.util.Date" : | ||
"new java.util.Date((%s).getTime()", | ||
"java.util.Date java.sql.Timestamp" : | ||
"new java.sql.Timestamp((%s).getTime()", | ||
} | ||
} | ||
``` | ||
|
||
Note the required `functions` section which specifies Java code for conversions between the two. The first | ||
entry converts a `Timestamp` to a `Date`. The second does the reverse. This will work for your own custom | ||
classes as well. | ||
|
||
If you don't want all types to be mapped the same way for all classes, you can specify Java | ||
regex statements (matched against the schema.table.column names) to specify certain classes. | ||
For example, this will do the same as the previous example, but only for fields with names ending in "_date": | ||
|
||
```json | ||
{ | ||
"schema_mappings": { | ||
".*_date": "java.util.Date", | ||
}, | ||
"functions": { | ||
"java.sql.Timestamp java.util.Date" : | ||
"new java.util.Date((%s).getTime()", | ||
"java.util.Date java.sql.Timestamp" : | ||
"new java.sql.Timestamp((%s).getTime()", | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
java -jar ../../lib/dko.jar generate-dkos \ | ||
--schemas schemas.json \ | ||
--package com.mycompany.dko \ | ||
--java-output-dir gensrcdko |
Oops, something went wrong.