You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ri...@apache.org on 2006/09/22 12:05:30 UTC

svn commit: r448884 - in /incubator/tuscany/java/sampleapps/bigbank/account/src/main: java/bigbank/account/services/accountdb/AccountDBInit.java resources/DasAccountConfiguration.xml resources/wsdl/AccountService.wsdl webapp/WEB-INF/web.xml

Author: rineholt
Date: Fri Sep 22 03:05:29 2006
New Revision: 448884

URL: http://svn.apache.org/viewvc?view=rev&rev=448884
Log:
updates to BigBank DAS/Derby by Luciano Resende
http://www.mail-archive.com/tuscany-dev%40ws.apache.org/msg08241.html


Modified:
    incubator/tuscany/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java
    incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml
    incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
    incubator/tuscany/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml

Modified: incubator/tuscany/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java?view=diff&rev=448884&r1=448883&r2=448884
==============================================================================
--- incubator/tuscany/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java (original)
+++ incubator/tuscany/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java Fri Sep 22 03:05:29 2006
@@ -18,8 +18,10 @@
  */
 package bigbank.account.services.accountdb;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
@@ -36,6 +38,8 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tuscany.das.rdb.Command;
 import org.apache.tuscany.das.rdb.Converter;
@@ -57,18 +61,19 @@
 
 public class AccountDBInit extends HttpServlet {
 
-    /**
-     * 
-     */
     private static final long serialVersionUID = -4795999792460944805L;
 
     protected static final String driver = "org.apache.derby.jdbc.EmbeddedDriver";
 
     protected static final String protocol = "jdbc:derby:";
 
-    boolean deleteExisting = false;
-
     protected String dbDirectory = null;
+    
+    protected String dasConfigFile = null;
+    
+    boolean deleteExisting = false;
+    
+    
 
 
     @Override
@@ -79,6 +84,7 @@
             ServletConfig servletConfig = getServletConfig();
             ServletContext servletContext = servletConfig.getServletContext();
             this.dbDirectory = servletContext.getRealPath("WEB-INF/bigbankdb/accounts");
+            this.dasConfigFile = servletContext.getRealPath("WEB-INF/classes/DasAccountConfiguration.xml");
             this.deleteExisting = false;
 
             createDB(dbDirectory);
@@ -92,13 +98,43 @@
         }
     }
 
+    /*
+     * (non-Java-doc)
+     * 
+     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1)
+     */
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        response.setContentType("text/html");
+
+        PrintWriter out = response.getWriter();
+        
+        out.println();
+        out.println("<center><h2>BigBank database initialization servlet !<h2></center>");
+        out.println();        
+    }
+    
     public AccountDBInit() {
     }
 
-    public AccountDBInit(String dbDirectory, Boolean deleteExisting) {
+    public AccountDBInit(String dbDirectory, String dasConfigFile, Boolean deleteExisting) {
         this.dbDirectory = dbDirectory;
+        this.dasConfigFile = dasConfigFile;
         this.deleteExisting = deleteExisting;
     }
+    
+    private Connection createConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+        return createConnection(dbDirectory);
+    }
+
+    private static Connection createConnection(final String location) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+        Connection conn;
+        Class.forName(driver).newInstance();
+        Properties props = new Properties();
+        conn = DriverManager.getConnection(protocol + location + ";create=true", props);
+
+        conn.setAutoCommit(false);
+        return conn;
+    }
 
     public static void  createDB(final String location) throws Exception {
         Connection conn = null;
@@ -158,26 +194,11 @@
 
     }
 
-    private Connection createConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
-        return createConnection(dbDirectory);
-    }
 
-    private static Connection createConnection(final String location) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
-            SQLException {
-        Connection conn;
-        Class.forName(driver).newInstance();
-        Properties props = new Properties();
-        conn = DriverManager.getConnection(protocol + location + ";create=true", props);
-
-        conn.setAutoCommit(false);
-        return conn;
-    }
 
     protected static void creatTables(Connection conn) throws Exception {
-        
-        
-        
         Statement s = conn.createStatement();
+
         s.execute("create table customers(firstName varchar(80) NOT NULL, lastName varchar(80), address varchar(180),email varchar(40),loginID varchar(80) NOT NULL UNIQUE, password varchar(80), id int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY)");
 
         s.execute("create table accounts(id int NOT NULL, accountNumber varchar(80) NOT NULL UNIQUE, accountType varchar(80), balance real )");
@@ -191,12 +212,11 @@
         s.close();
     }
 
-    protected static int createCustomer(Connection conn, final String firstName, final String lastName, final String address, final String email,  final String logonID, final String password)
-            throws SQLException, Exception {
+    protected static int createCustomer(Connection conn, final String firstName, final String lastName, final String address, final String email,  final String logonID, final String password) throws SQLException, Exception {
         Statement s = conn.createStatement();
 
-        s.execute("insert into customers (firstName,lastName,address,email, loginID, password  ) values ('" + firstName + "', '" + lastName + "', '"+ address + "', '" + email + "', '"  + logonID
-                + "', '" + password + "')");
+        s.execute("insert into customers (firstName,lastName,address,email, loginID, password  ) " +
+                  "values ('" + firstName + "', '" + lastName + "', '"+ address + "', '" + email + "', '"  + logonID + "', '" + password + "')");
 
         ResultSet rs = s.executeQuery("SELECT loginID, id FROM customers where loginID='" + logonID + "'");
         if (!rs.next()) {
@@ -208,20 +228,17 @@
         return id;
     }
 
-    protected static void createAccount(Connection conn, int customerID, final String accountNumber, final String accountType, final float balance)
-            throws SQLException, Exception {
+    protected static void createAccount(Connection conn, int customerID, final String accountNumber, final String accountType, final float balance) throws SQLException, Exception {
         Statement s = conn.createStatement();
 
-        s.execute("insert into accounts (id,accountNumber, accountType, balance  ) values (" + customerID + ", '" + accountNumber + "', '"
-                + accountType + "', " + balance + ")");
+        s.execute("insert into accounts (id,accountNumber, accountType, balance  ) " +
+                  "values (" + customerID + ", '" + accountNumber + "', '" + accountType + "', " + balance + ")");
 
         s.close();
-
-
     }
 
     protected InputStream createConfigStream() {
-        InputStream mapping = getClass().getClassLoader().getResourceAsStream("basicStaticCustomer.xml");
+        InputStream mapping = getClass().getClassLoader().getResourceAsStream("DasAccountConfiguration.xml");
         return mapping;
     }
 
@@ -243,51 +260,32 @@
 
     }
 
-    /**
-     * @param args
-     */
-    public static void main(String[] args) throws Exception {
-        registerTypes();
-        String dbDirectory = null; // "c:/derbydbtest/foo";
-        Boolean deleteExisting = false;
-        for (String x : args) {
-            if ("-d".equals(x)) {
-                deleteExisting = true;
-            }
-            if (!x.startsWith("-")) {
-                dbDirectory = x;
-            }
-
-        }
-        AccountDBInit accountDBInit = new AccountDBInit(dbDirectory, deleteExisting);
-
-        createDB(dbDirectory);
-        accountDBInit.readDBstdout(System.out);
-
+    public void testWithdrawThroughDAS(withdraw wd) throws Exception {
 
-        // Test withdrawl
-        withdraw wd = AccountFactory.INSTANCE.createwithdraw();
-        wd.setAccountNumber("134-43-39438");
-        wd.setAmount(1.00F);
-        // accountDBInit.testWithdrawThroughDAS(wd);
+        Connection conn = createConnection();
+        DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);
+        Command select = das.getCommand("get account");
+              
+        select.setParameter(1, wd.getAccountNumber()); 
 
-        // test stock purchase.
+        DataObject root = select.executeQuery();
 
-        purchaseStock sp = AccountFactory.INSTANCE.createpurchaseStock();
-        StockSummary stock= AccountFactory.INSTANCE.createStockSummary();
-        sp.setStock(stock);
-        stock.setSymbol("GOOG");
-        sp.setId(1);
-        stock.setQuantity(10);
-        accountDBInit.testStrockPurchaseThroughDAS(sp);
+        Collection accounts = root.getList("AccountSummary");
+        AccountSummary account = (AccountSummary) accounts.iterator().next();
+        float newbalance = account.getBalance() - wd.getAmount();
+        account.setBalance(newbalance);
+        // update department set companyid = ? where department.name = ?
 
-        accountDBInit.readDBstdout(System.out);
+       
+        Command update = das.getCommand("update balance");
+        update.setParameter(1, new Float(newbalance));
+        update.setParameter(2, wd.getAccountNumber());
 
-        System.out.flush();
+        update.execute();
+        conn.close();
     }
 
-    protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
-            SQLException {
+    protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
 
         DAS das = DAS.FACTORY.createDAS(createConfigStream(), createConnection());      
         Command read = das.getCommand("all stocks");
@@ -295,21 +293,18 @@
         DataObject root = read.executeQuery();
 
         // Create a new stockPurchase
-        DataObject stockPurchase = root.createDataObject("STOCKS");
-        stockPurchase.set("ID", new Integer(sp.getId()));
-        stockPurchase.set("SYMBOL", sp.getStock().getSymbol());
-        stockPurchase.set("QUANTITY", new Integer(sp.getStock().getQuantity()));
-        stockPurchase.set("PURCHASEPRICE", new Float(11.00));
-        stockPurchase.set("PURCHASEDATE", new Date());
+        DataObject stockPurchase = root.createDataObject("StockSummary");
+        stockPurchase.set("id", new Integer(sp.getId()));
+        stockPurchase.set("symbol", sp.getStock().getSymbol());
+        stockPurchase.set("quantity", new Integer(sp.getStock().getQuantity()));
+        stockPurchase.set("purchasePrice", new Float(11.00));
+        //String type = stockPurchase.getType().getProperty("purchaseDate").getType().toString();
+        stockPurchase.setDate("purchaseDate", new Date());
 
         das.applyChanges(root);
-
-
-
     }
 
     public CustomerProfileData testgetCustomerByLoginIDThroughDASRead(final String logonID) throws Exception {
-
         InputStream mapping = createConfigStream();
         Connection conn = createConnection();
         DAS das = DAS.FACTORY.createDAS(mapping, conn);
@@ -348,6 +343,7 @@
                 int id = rs.getInt(5);
                 Statement s1 = conn.createStatement();
                 ResultSet rs1 = s1.executeQuery("SELECT accountNumber, accountType, balance FROM accounts where id=" + id);
+                stream.println("====Customers accounts");
                 while (rs1.next()) {
                     stream.print("\t");
                     stream.print(rs1.getString(1));
@@ -359,6 +355,7 @@
                 }
                 rs1.close();
                 rs1 = s1.executeQuery("SELECT symbol, quantity, purchasePrice, purchaseDate,  purchaseLotNumber FROM stocks where id=" + id);
+                stream.println("====Customers Stocks");
                 while (rs1.next()) {
                     stream.print("\t");
                     stream.print(rs1.getString(1));
@@ -388,32 +385,6 @@
 
     }
 
-    public void testWithdrawThroughDAS(withdraw wd) throws Exception {
-
-    	Connection conn = createConnection();
-    	DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);
-        Command select = das.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = ?");
-              
-        select.setParameter(1, wd.getAccountNumber()); 
-
-        DataObject root = select.executeQuery();
-
-        Collection accounts = root.getList("AccountSummary");
-        AccountSummary account = (AccountSummary) accounts.iterator().next();
-        float newbalance = account.getBalance() - wd.getAmount();
-        account.setBalance(newbalance);
-        // update department set companyid = ? where department.name = ?
-
-       
-        Command update = das.getCommand("update balance");
-        update.setParameter(1, new Float(newbalance));
-        update.setParameter(2, wd.getAccountNumber());
-
-        update.execute();
-        conn.close();
-
-    }
-
     public static class MyDateConverter implements Converter {
 
         private static DateFormat tsformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
@@ -441,4 +412,54 @@
 
     }
 
+    
+    /**
+     * @param args
+     */
+    public static void main(String[] args) throws Exception {
+        registerTypes();
+        String dbDirectory = null; // "c:/derbydbtest/foo";
+        String dasConfigFile = null;
+        Boolean deleteExisting = false;
+        for (String x : args) {
+            if ("-d".equals(x)) {
+                deleteExisting = true;
+            }
+            if(x.startsWith("-db:")){
+                dbDirectory = x.substring("-db:".length());
+            }
+            if(x.startsWith("-config:")) {
+                dasConfigFile = x.substring("-config:".length());;
+            }
+
+        }
+        AccountDBInit accountDBInit = new AccountDBInit(dbDirectory, dasConfigFile, deleteExisting);
+
+        createDB(dbDirectory);
+        
+        accountDBInit.readDBstdout(System.out);
+
+        // Test withdrawl
+        withdraw wd = AccountFactory.INSTANCE.createwithdraw();
+        wd.setAccountNumber("134-43-3942");
+        wd.setAmount(1.00F);
+        accountDBInit.testWithdrawThroughDAS(wd);
+
+        accountDBInit.readDBstdout(System.out);
+        
+        // test stock purchase.
+        purchaseStock sp = AccountFactory.INSTANCE.createpurchaseStock();
+        StockSummary stock= AccountFactory.INSTANCE.createStockSummary();
+        stock.setSymbol("GOOG");
+        stock.setQuantity(10);
+        stock.setPurchasePrice(25.00F);
+        sp.setId(1);
+        sp.setStock(stock);
+        
+        accountDBInit.testStrockPurchaseThroughDAS(sp);
+
+        accountDBInit.readDBstdout(System.out);
+
+        System.out.flush();
+    }
 }

Modified: incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml?view=diff&rev=448884&r1=448883&r2=448884
==============================================================================
--- incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml (original)
+++ incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml Fri Sep 22 03:05:29 2006
@@ -40,11 +40,11 @@
 
 
   <Table tableName="STOCKS" typeName="StockSummary" >
-    <Column columnName="ID"/>
-    <Column columnName="Symbol"/>
-    <Column columnName="quantity"/>
-    <Column columnName="purchasePrice"/>
-    <Column columnName="PURCHASEDATE" converterClassName="bigbank.account.services.accountdata.AccountDataServiceDASImpl$DateConverter"/>
+    <Column columnName="ID" propertyName="id"/>
+    <Column columnName="Symbol" propertyName="symbol"/>
+    <Column columnName="quantity" propertyName="quantity"/>
+    <Column columnName="purchasePrice" propertyName="purchasePrice"/>
+    <Column columnName="PURCHASEDATE"  propertyName="purchaseDate" converterClassName="bigbank.account.services.accountdata.AccountDataServiceDASImpl$DateConverter"/>
   </Table>
 
 	
@@ -67,19 +67,14 @@
     <Column columnName="purchaseLotNumber"/>
   </Table>
 
-	
-  <Command name="update balance"
-        SQL="update ACCOUNTS set BALANCE = ? where ACCOUNTNUMBER = ?"
-        kind="Update">
-   </Command>
-    
-    
-    <Command name="all stocks" SQL="select * from stocks"  kind="Select"/>
-    <Command name="all customers" SQL="select  from CUSTOMERS"  kind="Select"/>
-    <Command name="stockbylotSelect" SQL="select quantity  from STOCKS  WHERE purchaseLotNumber = ?"  kind="Select" >
-    	<Parameter name=":PURCHASELOTNUMBER"/>
-    </Command>
-    <Command name="stockbylot" SQL="update STOCKS set quantity = ? WHERE purchaseLotNumber = ?"  kind="Update" >
-    </Command>
+
+  <Command name="get account" SQL="SELECT accountNumber, accountType, balance FROM accounts where accountNumber = ?" kind="Select" />    	
+  <Command name="update balance" SQL="update ACCOUNTS set BALANCE = ? where ACCOUNTNUMBER = ?" kind="Update" />    
+
+  <Command name="all customers" SQL="select * from CUSTOMERS"  kind="Select"/>
+
+  <Command name="all stocks" SQL="select symbol, quantity, purchaseprice, purchasedate from stocks"  kind="Select"/>
+  <Command name="stockbylotSelect" SQL="select quantity  from STOCKS  WHERE purchaseLotNumber = ?"  kind="Select" />
+  <Command name="stockbylot" SQL="update STOCKS set quantity = ? WHERE purchaseLotNumber = ?"  kind="Update" />
 	
 </Config>

Modified: incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl?view=diff&rev=448884&r1=448883&r2=448884
==============================================================================
--- incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl (original)
+++ incubator/tuscany/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl Fri Sep 22 03:05:29 2006
@@ -76,6 +76,7 @@
 			</xsd:complexType>
 
 			<xsd:complexType name="StockSummary">
+			    <xsd:attribute name="id" type="xsd:int" />
 				<xsd:attribute name="purchaseLotNumber" type="xsd:int" />
 				<!-- unique id for this purchase -->
 				<xsd:attribute name="symbol" type="xsd:string" />

Modified: incubator/tuscany/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml?view=diff&rev=448884&r1=448883&r2=448884
==============================================================================
--- incubator/tuscany/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/tuscany/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml Fri Sep 22 03:05:29 2006
@@ -26,6 +26,10 @@
 	    <servlet-class>bigbank.account.services.accountdb.AccountDBInit</servlet-class>
 	    <load-on-startup>2</load-on-startup>
   </servlet>
+  <servlet-mapping>
+		<servlet-name>AccountDBInit</servlet-name>
+		<url-pattern>/AccountDBInit</url-pattern>
+	</servlet-mapping>
     
 
 </web-app>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org