XDR
XDR

Reputation: 4490

Determine if a value can be used for a Field / DataType in jOOQ

In jOOQ, is there any way to determine if a value can be used for a Field / DataType?

e.g.:

Field f = <a non-nullable varchar(2)>;

assert f.accepts("");
assert f.accepts("a");
assert f.accepts("ab");

assert ! f.accepts("abc");
assert ! f.accepts(null);
assert ! f.accepts();

Field g = <a nullable unsigned byte>;

assert g.accepts(null);
assert g.accepts(0);
assert g.accepts(1);

assert ! g.accepts("");
assert ! g.accepts("a");
assert ! g.accepts(-1);
assert ! g.accepts(999999);

If something like this exists, is it strict, or converting?

e.g.:

Also, is it possible for UpdateSetStep#set(Field field, T value) (and similar methods) to throw an exception if the field cannot accept the value? (for any reason, like nullability, data type, length, precision, scale, etc.)

Upvotes: 1

Views: 262

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221145

In jOOQ, is there any way to determine if a value can be used for a Field / DataType?

No such feature exists as of jOOQ 3.6. There's a new feature request for this, now: #4543.

Also, is it possible for UpdateSetStep#set(Field field, T value) (and similar methods) to throw an exception if the field cannot accept the value?

You won't be able to override the behaviour of set(). But you could add your own data type Binding implementations to all data types, and implement your validation when binding variables to the underlying JDBC statement.

For more info about data type bindings, see:
http://www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-bindings/

Upvotes: 1

Related Questions