Java Reference
In-Depth Information
if
(rs.next()) t
#
new
Transaction(rs);
else throw new
Exception(
"Transaction non existent");
Item item;
rs
#
select("SELECT * FROM ITEM WHERE ID
#
"
!
code);
if
(rs.next()) item
#
new
Item(rs);
else throw new
Exception("Item non existent");
item.quantity -
#
quantity;
rs
#
stmt.executeQuery(
"SELECT MAX(ID) AS M FROM ACQUISITION");
long
acq_code;
if
(rs.next())
acq_code
#
rs.getLong("M")
!
1;
else
acq_code
#
1;
rs.close();
stmt.executeUpdate(
"INSERT INTO ACQUISITION (ID,TRANS,ITEM,QUANTITY)"
!
" VALUES ( "
!
acq_code
!
", "
!
transaction
!
", "
!
item.code
!
", "
!
quantity
!
")");
stmt.executeUpdate("UPDATE ITEM SET QUANTITY
#
"
!
item.quantity
!
" WHERE ID
#
"
!
code);
}
catch
(Exception e){
throw
e; }
}
}
14.7.4
Test
To test the introduction of the database, we can conduct a test in a local
context, i.e. by instantiating all the components of the system in a single
process.
import
CounterUI.*;
import
Market.BasicServer;
import
Market.MarketServer;
import
Counter.SocketProxy;
import
MarketDB.PersistentDB;
public class
TestPersistent {
public static void
main(String [] args) {
// instantiate the server components
try
{
Class.forName("COM.cloudscape.core.RmiJdbcDriver");
}
catch
(Exception e){e.printStackTrace();}
String connection
#
"jdbc:rmi:jdbc:cloudscape:Supermarket;create
#
true";