Managing database configuration properties

In the previous recipe, we saw how we can view the database configuration properties defined in the database.properties file using the database properties list command. In this recipe, we'll look at how we can add, modify, or remove properties from the database.properties file using the database properties set and database properties remove commands.

The following table shows the properties that we'll add, modify, and remove from the database.properties file:

Property

Action

database.username

Modified to database.username = root

database.password

Modified to database.password = asarin

database.url = jdbc:mysql://localhost:3306/myFlightAppDB

Removed from database.properties

database.modified.url = jdbc:mysql://localhost:3406/myFlightAppDB

Added to database.properties

database.initialPoolSize=10

Added to database.properties

Getting ready

Refer to the Setting up a JPA provider for your project recipe to create the flight-app Roo project and to set up a persistence provider using the persistence setup command.

Start the Roo shell from the C: oo-cookbookch02-recipes directory.

Note

You won't need this recipe if you're using JNDI-bound data source in your Roo project.

How to do it...

The following steps will show you how to add, modify, or remove properties:

  1. The database properties set command is useful if you want to modify properties defined in the database.properties file, as shown here:
    roo> database properties set --key database.username --value root
    roo> database properties set --key database.password --value asarin
    
  2. The database properties set command can also be used to add new properties to the database.properties file, as shown here:
    roo> database properties set --key database.modified.url --value jdbc:mysql://localhost:3406/myFlightAppDB
    roo> database properties set --key database.initialPoolSize --value 10
    
  3. The database properties remove command is for removing an existing property from the database.properties file, as shown here:
    roo> database properties remove --key database.url
    

How it works...

The database properties set and database properties remove commands are processed by JPA add-on. Instead of using these commands you can use the properties set and properties remove command also, as shown in the Managing properties defined in a properties file recipe in Chapter 1, Getting Started with Spring Roo

It is important to note that if you modify the names of properties in the database.properties file, then these modifications must be reflected in the dataSource bean defined in the applicationContext.xml file of your Roo project.

There's more...

Instead of using Spring Roo, you can also modify the database.properties file using an IDE like Eclipse or STS. Using Roo commands to modify the database.properties file allows developers to replay the actions taken from the Roo shell using the script command.

See also

  • Refer to the Viewing database configuration properties recipe, described earlier in this chapter, to see how you can view properties defined in the database.properties file using the Roo command
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.119