You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Map file name for databse types that should not be mapped by the default type map. Resource bundle file in src/main/resources without file extension, e.g: replacement-type
303
+
304
+
If you want to use a custom type instead of the built in one for one or a set of database types, put it into the file as <typenameregexpattern> = <fullyqualifiedclassnameofthetype>, <fullyqualifiedclassnameofthetypeconverter>, e.g:
Defines database sequence naming convention with **SEQ** string, optional, default value is SUFFIXED_TABLE_NAME.
301
312
@@ -417,6 +428,85 @@ public enum MyFieldIrregularEnum {
417
428
}
418
429
```
419
430
431
+
# Using custom types
432
+
433
+
EasyDAO maps database types to the most sensible Java types, but sometimes it's not appropriate. In these cases you can
434
+
override the default type mapping via a properties file. Overriding it consists of the following:
435
+
436
+
* implementation of the custom type class, see the example below.
437
+
* implementation of a type converter class that converts the custom type to a type that is recognized by the database driver and/or spring JDBC, see the example below
438
+
* registering the custom type in the replacement-type.properties and specifying the file name in the maven plugin configuration
439
+
440
+
441
+
Let's assume we have an Oracle database and the default DATE -> java.sql.Timestamp mapping is not appropriate for some reason.
442
+
In this case we need to implement the MyCustomDateType class and the corresponding MyCustomDateTypeConverter as seen below.
443
+
In addition you have to register the new custom type in the replacement type map file (replacement-type.properties):
> Note the `date.*` expression on the left hand side. It means that *any* field with a type that starts with the string `date` will be mapped to the given custom type.
448
+
449
+
### Example custom type class
450
+
451
+
452
+
```java
453
+
packagehu.vanio.myapp.model;
454
+
455
+
publicclassMyCustomDateType {
456
+
457
+
// properties...
458
+
459
+
// methods...
460
+
461
+
/** Constructor */
462
+
publicMyCustomDateType(String) {
463
+
// ...
464
+
}
465
+
466
+
publicjava.sql.DatetoSqlDate() {
467
+
java.sql.Date dateValue =....
468
+
return dateValue;
469
+
}
470
+
471
+
}
472
+
```
473
+
474
+
### Example type converter implementation
475
+
476
+
Type converters are convention based so it's not necessary to extend any base class or implement any interface.
477
+
The only requirement is to implement two public static methods: extractValue and convertValue.
478
+
479
+
> WARNING: This class must be thread safe, so don't use any instance fields!
480
+
481
+
```java
482
+
packagehu.vanio.myapp.converter;
483
+
484
+
importhu.vanio.myapp.model.MyCustomDateType;
485
+
486
+
/** Converter class. */
487
+
publicclassMyCustomDateTypeConverter {
488
+
489
+
/**
490
+
* Extracts the value of the field with the specified name as a custom type from the specified resultset.
491
+
* is of type DATE you have to return either java.util.Date, java.sql.Date or java.sql.Timestamp.
> If you just want **to use** this easy model and dao generator, then use the maven plugin at https://github.com/vanioinformatika/easydao-maven-plugin and a small dependeny in your project: https://github.com/vanioinformatika/easydao-core
* @param databaseName database name: generated Dao DataSource name in @Qualifier annotation
@@ -177,6 +189,9 @@ static public enum SEQUENCE_NAME_CONVENTION {
177
189
* @param enumFieldFilename Map of Java enum names and database field names. Names included in this list will be generated with the specified enum type.
178
190
* The key is the table name and field name, the value is the fully qualified name of the enum.
0 commit comments