Adding Columns for the Database and Using them in the UI

Through out this recipe I will use the example of adding the attribute Number to a Sample, the data type of Number will be a string, so in reality it is a Sample Number.

Adding it to the Database

  • In the directory mpdb-server/schema all of the .sql files are stored
  • Since we are adding it to a Sample we put it in metpetdb-core.sql, if it was for images it would go in metpetdb-image.sql
  • Use the proper sql syntax to add the column to the sample table (column name will be number)

Making Hibernate Aware of It

  • Modify the file Sample.hbm.xml in mpdb-server/src/edu/rpi/metpetdb/dao/
  • Add the property to the file, specifying the name (number) and column (number)

Updating the Java Beans

  • Since the property was added to a Sample modify Sample.java in mpdb-common/src/edu/rpi/metpetdb/client/model/

Using it in the UI for Forms

This is if you want to do something like new TextAttribute(MpDb.doc.Sample_number)

  • Create a new Database Object Constraint for it in mpdb-common/src/edu/rpi/metpetdb/client/model/validation/DatabaseObjectConstraints.java
  • The data type is the type of the property, since number is a string it will be StringConstraint
  • StringConstraint takes min/max values from the database column itself
  • The format of how the variable should be name is in the JavaDocs
  • Add the property to SampleProperty.java in mpdb-common/src/edu/rpi/metpetdb/client/model/properties