enums. SQL types in DbOom are actually implementations of
SqlType, that defines how to convert values between SQL and Java types.
SqlTypeimplementation is registered in
SqlTypeManager. Such SQL types are available all across the application.
@DbColumnannotation by setting
sqlTypeelement, this custom type applies only on annotated property.
JJ_FOO_BAR(prefix and uppercase) and column
value_data(lowercase), it may be mapped to class
FooBar(camel-case strategy) and property
valueData(again, camel-case). The opposite mapping also has to match: class
UserDatamay be resolved to e.g. table
EX_USER_DATA_N(uppercase with both prefix and suffix); property
valueDatamay be resolved to column
splitCamelCase- if camel case words should be split with
separatorChar- simple char used when
true, by default its
true(default) table or column names will be changed to upper or lowercase.
lowercase- defines it table or column name should be converted to upper case or lowercase.
suffix- table names may have prefix and/or a suffix.
DbOomconnects to the database and detects the vendor. Depending of the used database,
DbOomshould set correct naming conventions.
Stringvalues to integer columns - of course, it is assumed that string contains only digits. In this example you can see two explicit local mapping, when SQL type is defined in
boohas a custom type
Boo, and it is also mapped to database. Of course, this mapping can't be done automatically. We must provide custom
SqlTypethat explains how to convert database value to and from
Bootype. Since we want to use this mapping everywhere, we might register it globally:
BooSqlTypemay look like:
Boois stored as an integer in database; however, you can create a more complex SQL type and conversion.
FooColor) can be stored to database. Enumerations, by default, are stored as strings (varchars...).
SqlTypefor mapping conversion. One such implementation may look like:
SqlTypeis NOT needed if you design your enumeration like this:
toString()that returns int value as a
String. When you map such enum to a column of some int type, everything will work out of box! This is because of behavior of BeanUtil tool. Note that we have cached int value for better performances, to avoid string conversion on every access.
LocalDateTimeis stored as number of milliseconds (compatible with