Hi Dave,
CHECK constraints are currently not exposed by jOOQ-meta, and thus not
leveraged by the code generator. I had previously thought about mapping
CHECK (COL IN ('A', 'B', 'C')) constraints to generated Java enums. Getting
this right and reliable would probably involve creating an actual SQL
parser to evaluate the CHECK constraint.
Your use-case is another good one, where these things might be leveraged. I
have created a feature request to expose CHECK constraints in jOOQ-meta:
https://github.com/jOOQ/jOOQ/issues/2509
Note that this will not be a column-property. DDL allowing to specify CHECK
constraints on single columns is just syntactic sugar as the
INFORMATION_SCHEMA only exposes constraints on a schema-level. They can
still be mapped to tables by joining CHECK_CONSTRAINTS to
TABLE_CONSTRAINTS. More info can be found in the PostgreSQL manual [1] and
in the SQL-92 Standard [2]. An example of such a query:
*select *
tc.table_schema,
tc.table_name,
cc.check_clause
*from *
information_schema.table_constraints tc
*join*
information_schema.check_constraints cc
*using *(constraint_catalog, constraint_schema, constraint_name);
Cheers
Lukas
[1]: http://www.postgresql.org/docs/9.2/static/ddl-constraints.html
[2]: http://www.andrew.cmu.edu/user/shadow/sql/sql1992.txt
2013/6/7 David Fox <[email protected]>
> I am loving JOOQ! I have a question regarding code generation. I was
> trying to write a generator which would add the rest of the JSR-303
> validation annotations based on common patterns in my table definitions.
>
> For example, in one column (I'm using PostgreSQL):
>
> name varchar(32) NOT NULL CHECK (name ~* '^[a-zA-Z0-9_]+$'),
>
> would result in:
>
> @javax.validation.constraints.NotNull
> @javax.validation.constraints.Size(max = 32)
> @javax.validation.constraints.Pattern(regex="^[a-zA-Z0-9_]+$")
> public java.lang.String getName() {
> return (java.lang.String) getValue(1);
> }
>
> for the property. However, I cannot see how to access the constraints from
> the ColumnDefinition. Is it possible to access this information?
>
> Thanks in Advance,
> Dave
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.