throws VirtualMachineException
{
final int id = checkMethod( methodName, args );
if( id != -1 )
{
Database db = (Database)
target.getAttachment( "db" );
try
{
switch( id )
{
case CONNECT:
if( db == null )
{
db = Database.connect( Conversor.toString( args[0] ) );
target.setAttachment( "db", db );
}
return null;
case CREATE:
if( db == null )
{
db = Database.create( Conversor.toString( args[0] ) );
target.setAttachment( "db", db );
}
return null;
case GET_TABLE:
if( db != null )
{
final String tableName = Conversor.toString( args[0] );
final Table table = db.getTable(
tableName
);
if( table != null )
{
Hashtable tables = (Hashtable)
target.getAttachment( "tables" );
if( tables == null )
{
tables = new Hashtable( 10 );
target.setAttachment( "tables", tables );
}
Instance t = (Instance) tables.get( tableName );
if( t == null )
{
t = getVirtualMachine().newInstance( "Table" );
t.setAttachment( "table", table );
t.setAttachment( "parent", target );
tables.put( tableName, t );
}
return t;
}
else
{
return null;
}
}
else
{
return null;
}
case CREATE_TABLE:
if( db != null )
{
final Table table = (Table)
args[0].getAttachment( "table" );
db.createTable( table );
Hashtable tables = (Hashtable)
target.getAttachment( "tables" );
if( tables == null )
{
tables = new Hashtable( 10 );
target.setAttachment( "tables", tables );
}
Instance t = (Instance) tables.get( table.getName() );
if( t == null )
{
t = getVirtualMachine().newInstance( "Table" );
t.setAttachment( "table", table );
t.setAttachment( "parent", target );
tables.put( table.getName(), t );
}
return t;
}
else
{
return null;
}
case START:
if( db != null )
{
db.start();
}
else
{
return null;
}
case PACK:
if( db != null )
{
db.pack();
}
else
{
return null;
}
case DROP:
if( db != null )
{
db.drop();
}
else
{
return null;
}
case REPAIR:
if( db != null )
{
db.repair();
}
else
{
return null;
}
case IS_DAMAGED:
return db != null ?
Conversor.toInstance(
getVirtualMachine(),
new Boolean( db.isDamaged() )
) :
null;
case OPEN:
if( db != null )
{
db.open();
}
else
{
return null;
}
case CLOSE:
if( db != null )
{
db.close();
}
else
{
return null;
}
case SHUTDOWN:
if( db != null )
{
db.shutdown();
}
else
{
return null;
}
case SANITY_CHECK:
if( db != null )
{
db.sanityCheck();
}
else
{
return null;
}
case GET_NAME:
return db != null ?
Conversor.toInstance(
getVirtualMachine(),
db.getName()
) :
null;
case GET_VER_MAJOR:
return db != null ?
Conversor.toInstance(
getVirtualMachine(),
new Short( db.getVersionMajor() )
) :
null;
case GET_VER_MINOR:
return db != null ?
Conversor.toInstance(
getVirtualMachine(),
new Short( db.getVersionMinor() )
) :
null;
default:
return null;