This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

DBRE Custom field names

Nov 15th, 2011, 04:54 AM

Is it possible to override the naming strategy that Roo dbre uses when creating Roo_DbManaged ITDs?

For example, we have a database which uses 2 char prefixes on column names to indicate the datatype, e.g. TX_EMPLOYEE_NAME, which by default maps to txEmployeeName - I would like it to map to employeeName.

Also, ID_EMPLOYEE maps to idEmployee, whereas I would rather it was employeeId.

The particular use cases and issues I had to deal with are:
1) plural tablenames (which results in plural entity names and then weird double-pluralization of subsquent bits)
3) prefixes on table names that have no meaning to the domain model (eg MV_ for materialized views)
4) legacy schema with mixed and inconsitent naming conventions (but difficult to change)
5) problems renaming entities if the ui tier has already been generated and modified so would like to get them right the first time

Dealing with plural table names is by arbitrarily singularizing all table names on the assumption that it's harmless if the name is already singular or that there's not already a table with a clashing name (the dbre code then suffixes one of them to resolve the clash but it could be confusing) .

Schema and site-specific configuration is through an extra arg --tableNameMapper <file> for dbre reverse engineer
This can be a property file in classic or xml format with mapping rules of the form oldname=newname
eg

Code:

# clean up a specific materialized view
MV_EMPLOYEES=EMPLOYEE
# or a regex to clean them all up
(?\:MV_)(.*)=$1

or a groovy script that implements whatever logic is neccessary in a method of the for String getName(String)
eg

The groovy script option obviously has the most potential and I was a bit surprised that it worked (as it conflicts with aspectj in the generated application) but as roo itself doesn't use aspects it seems to be ok.

Comment

Hi - I downloaded the snapshot build and pointed Spring Tool Suite to it. After opening the Roo shell, it updated my POM file (as expected). I then had to manually add the annotations jar into my maven repository and then no compile errors. I then tried to run the reverse engineer with the new tableNameMapper option but the roo shell just returns to the prompt with no action and no errors.
Any ideas?

Comment

Can you give some background - Are you using Roo within Spring Tool Suite or from Command Prompt? What database are you trying to reverse engineer? What commands have you tried? Did you create your project from Roo?

Comment

Can you give some background - Are you using Roo within Spring Tool Suite or from Command Prompt? What database are you trying to reverse engineer? What commands have you tried? Did you create your project from Roo?

I hope you were replying to my post... Here's a little background like you asked for...

Roo from the command line... It's a MYSQL - HIBERNATE database. And I've tried the standard commands for the reverse engineering process. I continually get a response that there is no driver available to do perform the reverse engineer process. And there is no download or plugin install options available either.

Comment

Yes I was replying.
Have you run the following commands in Roo:
--> persistence setup --provider HIBERNATE --database MYSQL

This will create a database.properties file and you then need to edit this to add the connection/driver details to get to your MYSQL database.

Then you should be able to do the reverse engineer command.

One other note is that I am connecting to SQL Server and I had to add the JTDS driver to the roo shell by downloading jtds-1.2.4.jar and then running the following command in Roo:
--> osgi start --url file:///C:\[path]\jtds-1.2.4.jar