facebook

Preserve CamelCase class names with SQL Server

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #318623 Reply

    cangel
    Member

    When we scaffold a Spring CRUD application based on tables in a SQL Server 2008 database, the classnames lose their camelcase. For example, a table named AccountAlert becomes Accountalert.java and AccountalertDAO.java.

    It turns out this is because SQL Server is case insensitive and I believe it is returning lowercased table names when the schema info is fetched. One option I know of is to reinstall the database with case sensitive collation turned on, however this is not an option for us since we do not control the db at that level.

    I looked into customizing the JET templates however it doesn’t appear that I can control the model names in these templates. Can someone point me to where I can edit the code that defines the model name that is used for class generation etc.?

    thanks!

    #318644 Reply

    jayperkins
    Member

    You can manually change the name of the java classes that will be created on the “Database Scaffolding Options” wizard page in the scaffolding wizard. Just click in the column labeled “Java Object” and type the name that you would like. The “Table” column on this page will show you how the database is reporting the table name. If it is all lower case, then there may not be much you can do, even if there was a mechanism to customize this behavior. Of course, this may not be feasible if you have alot of tables and/or are scaffolding often.

    Can you manually change the names or is that not feasible? If not, we can explore other options.

    Thanks,

    Jay

    #318650 Reply

    cangel
    Member

    Thanks for your reply, Jay!

    Unfortunately we have a lot of tables and they’re going to undergo changes (out of our control) over the coming year and we were hoping to be able to keep in sync by regenerating on a regular basis. Manually entering the class names isn’t feasible unless we hire some cheap labor 🙂

    The table name actually appears with the correct camelcase, but the generated Java classname does not. (See image below).

    This leads me to assume that we could customize it. I noticed that JET has functions like uppercaseFirst which it looks like it might be using instead of the function camelcase. Just guessing at this point.

    Where is the variable $model defined?

    thanks for any help!” alt=””>

    #318652 Reply

    jayperkins
    Member

    That is good news that the table names appear in camel case.

    Changing the jet templates will not work because at that point the data type name has already been altered (ie, lowercased and then capitalized).

    I am attaching a customization project that overrides the default behavior. Basically, I added custom code that uses the name of the table as reported by the database as the name of the data type. So now your data types will have the exact same name as the database table.

    First, import the attached project.
    To customize a specific project, right click on the project that you will be scaffolding into. Navigate to MyEclipse -> Customization. Click on the Add… button and select the customization project that you imported.
    To customize all projects that you will be scaffolding into, select the Window -> Preferences menu item. Navigate to MyEclipse -> Spring Code Generation -> Customization. Click on the Add… button and select the customization project that you imported.
    Now try to scaffold and see if the Data Object column has the values that you expect.

    Please note that I didn’t test it extensively.

    Let me know if you have any questions.

    Thanks,

    Jay

    Attachments:
    You must be logged in to view attached files.
    #318653 Reply

    cangel
    Member

    Many thanks Jay, that worked perfectly!

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Preserve CamelCase class names with SQL Server

You must be logged in to post in the forum log in