When the user drag and drops a Table, View or Stored Procedure from the database connection on to one of the consumer (Ex. VWP designer or JSP editor), it must know the contents of DnD transferable. Similarly, after receving the DnD, the consumer must have some API to talk to the producer (database connections manager), to get information about the connection. So, Database Connections Node (or its manager), must publish two public contracts (API's) for consuming the
public final class DatabaseMetaDataTransfer
// For view drag and drop
public static DataFlavor TABLE_FLAVOR;
public static final class TableInfo{
private final DatabaseConnection dbconn;
...
}
// For view drag and drop
public static DataFlavor VIEW_FLAVOR;
public static final class ViewInfo{
private final DatabaseConnection dbconn;
...
}
}
The Database Service Consumer can now obtain the TableInfo from the DataFlavor as follows.
DataFlavor supportedFlavor = DatabaseMetaDataTransfer.TABLE_FLAVOR;
if (transferable.isDataFlavorSupported(supportedFlavor)){
transferData = transferable.getTransferData(supportedFlavor);
DatabaseMetaDataTransfer.TableInfo tableInfo =
(DatabaseMetaDataTransfer.TableInfo) transferData;
// Obtain the database connection from the
DatabaseConnection dbConnection =
(DatabaseConnection)tableInfo.getDatabaseConnection();
// Now use DatabaseConnection as needed
}
}
The DatabaseConnection is one of the Service Meta-data Contract APIs published by the Database Connections Manager, for the consumer to interact with as explained below.
The Database Connections manager keeps information about the connections displayed in the module. So in order for consumer to get these information it must publish set of API. For example, after the consumer gets the TableInfo from the DnD transferable, it needs to get the connection information. So the Database Service module would publish the following public API, whose implementation could be reached via the DnD contract as explained above
public interface DatabaseConnection {
public String getDriverClass();
public String getDatabaseURL();
public String getPassword();
public String getUser();
}
The Service Consumer would create a DataSource object from the DatabaseConnection and add it to the project or inject the relevant source to the JSP. Once, the Table or View information is obtained from the transferable it is up to the consumer to consume the service.
For example, VWP designer might create a Data Source from the database connection and add the datasource info to a dataprovider and binds it to a component in the page.
On the other hand, the Matisse GUI designer might create a JPA entity using the database connection information obtained via above contract and binds it to the components using beans binding.