* @param source the source element
* @param model the model for the source element
*/
public void loadDatabase( XmlElement source, XModel model )
{
XmlElement connEle = source.elementAt( 0 );
String dbDriver = connEle.getAttribute( "driver" );
String dbUrl = connEle.getAttribute( "url" );
dbUrl = checkLocalHsqldb( dbDriver, dbUrl );
NamedConnectionManager connMgr = ( NamedConnectionManager )NamedConnectionManager.getInstance();
connMgr = ( NamedConnectionManager )connMgr.reset( connEle.getAttribute( "id" ),
dbDriver,
dbUrl,
connEle.getAttribute( "user" ),
connEle.getAttribute( "pwd" ) );
registerDatabaseNode( connEle );
Vector vRS = source.getChildren();
int rsCount = vRS.size();
int numChildren = model.getNumChildren();
numChildren += rsCount;
model.setNumChildren( numChildren );
for ( int i = 1; i < rsCount; i++ ) {
XmlElement rsEle = ( XmlElement )vRS.elementAt( i );
if ( rsEle.getName().compareTo( "Connection" ) == 0 ) {
String extraDbDriver = rsEle.getAttribute( "driver" );
String extraDbUrl = rsEle.getAttribute( "url" );
extraDbUrl = checkLocalHsqldb( extraDbDriver, extraDbUrl );
connMgr.addConnection( rsEle.getAttribute( "id" ),
extraDbDriver,
extraDbUrl,
rsEle.getAttribute( "user" ),
rsEle.getAttribute( "pwd" ) );
}
else {
DatabaseTableModel tableModel = new DatabaseTableModel( currentProject );
String escapeStr = rsEle.getAttribute( "escape" );
if ( escapeStr != null )
tableModel.setDoesEscapeProcessing( "true".equals( escapeStr ));
tableModel.setName( rsEle.getAttribute( "id" ) );
boolean updateDb = false;
String updateStr = rsEle.getAttribute( "update" );
if ( updateStr != null )
updateDb = updateStr.compareTo( "true" ) == 0;
String sqlStr = rsEle.getAttribute( "sql" );
if (( sqlStr != null ) && ( sqlStr.length() > 0 ))
tableModel.setSqlStatement( sqlStr, rsEle.getAttribute( "conn" ), updateDb );
else {
// We should probably change the name table to from as it equates to the FROM clause
tableModel.setupTable( rsEle.getAttribute( "from" ),
rsEle.getAttribute( "fields" ),
rsEle.getAttribute( "where" ),
rsEle.getAttribute( "conn" ),
updateDb );
String distinctStr = rsEle.getAttribute( "distinct" );
if ( distinctStr != null )
tableModel.setDistinct( distinctStr.equals( "true" ));
tableModel.setOrderField( rsEle.getAttribute( "order" ) );
}
model.append( tableModel );
}
registerDatabaseNode( rsEle );
}