You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/05/10 05:27:02 UTC

svn commit: r169407 - in /incubator/beehive/trunk/samples/petstoreWeb: ./ src/org/apache/beehive/samples/petstore/controls/ src/org/apache/beehive/samples/petstore/controls/data/

Author: ekoneil
Date: Mon May  9 20:27:00 2005
New Revision: 169407

URL: http://svn.apache.org/viewcvs?rev=169407&view=rev
Log:
Petstore changes -- add the DAO layer from Scott Semyan and Jeremiah Johnson.  This provides a level of abstraction between the business controls and the database controls.

Also add several build fixes to adjust for the control move and to implement some of Scott's suggestions.

BB: self
DRT: petstoreWeb pass (SVN and dist)


Added:
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java   (with props)
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java   (with props)
Removed:
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDBControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDBControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDBControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDBControl.java
Modified:
    incubator/beehive/trunk/samples/petstoreWeb/build-dist.properties
    incubator/beehive/trunk/samples/petstoreWeb/build-dist.xml
    incubator/beehive/trunk/samples/petstoreWeb/build.xml
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControlImpl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControlImpl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/CatalogControlImpl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControl.java
    incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControlImpl.java

Modified: incubator/beehive/trunk/samples/petstoreWeb/build-dist.properties
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/build-dist.properties?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/build-dist.properties (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/build-dist.properties Mon May  9 20:27:00 2005
@@ -8,7 +8,7 @@
 servlet-api.jar=${os.CATALINA_HOME}/common/lib/servlet-api.jar
 jsp-api.jar=${os.CATALINA_HOME}/common/lib/jsp-api.jar
 
-derby.jar=/path/to/derby
+derby.jar=/path/to/derby.jar
 
 # Set this path in order to run HTTPUnit tests against the webapp
 httpunit.dir=/fixme/to/run/tests

Modified: incubator/beehive/trunk/samples/petstoreWeb/build-dist.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/build-dist.xml?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/build-dist.xml (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/build-dist.xml Mon May  9 20:27:00 2005
@@ -51,9 +51,9 @@
         <fileset dir="${httpunit.dir}/jars" includes="*.jar"/>
     </path>    
 
-    <!-- ========================================= -->
-    <!-- build - build the webapp                  -->
-    <!-- ========================================= -->
+    <!-- ================================================ -->
+    <!-- deploy the Beehive runtime JARs into WEB-INF/lib -->
+    <!-- ================================================ -->
 
     <target name="deploy-beehive" description="Copy the Beehive rutime into the petstoreWeb webapp">
         <mkdir dir="${build.dir}"/>
@@ -62,7 +62,7 @@
         <fail unless="derby.present" 
               message="Unable to locate ${derby.jar}.  Please download Derby from http://incubator.apache.org/derby/derby_downloads.html and set the derby.jar property in build.properties"/>
 
-        <copy todir="${build.dir}/WEB-INF/lib" file="${beehive.home}/system-controls/build/jars/beehive-jdbc-control.jar"/>
+        <copy todir="${build.dir}/WEB-INF/lib" file="${beehive.home}/lib/controls/beehive-jdbc-control.jar"/>
         <copy todir="${build.dir}/WEB-INF/lib" file="${derby.jar}"/>
 
         <deploy-netui webappDir="${build.dir}"/>

Modified: incubator/beehive/trunk/samples/petstoreWeb/build.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/build.xml?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/build.xml (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/build.xml Mon May  9 20:27:00 2005
@@ -48,9 +48,9 @@
         <fileset dir="${httpunit.dir}/jars" includes="*.jar"/>
     </path>    
 
-    <!-- ========================================= -->
-    <!-- deploy the Beehive runtime JARs           -->
-    <!-- ========================================= -->
+    <!-- ================================================ -->
+    <!-- deploy the Beehive runtime JARs into WEB-INF/lib -->
+    <!-- ================================================ -->
 
     <target name="deploy-beehive" description="Copy the Beehive webapp rutime into the petstoreWeb webapp">
         <mkdir dir="${build.dir}"/>

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControl.java Mon May  9 20:27:00 2005
@@ -20,7 +20,6 @@
 import org.apache.beehive.controls.api.bean.ControlInterface;
 
 import org.apache.beehive.samples.petstore.model.Account;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
 import org.apache.beehive.samples.petstore.controls.exceptions.AccountAlreadyExistsException;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAccountException;
@@ -28,15 +27,8 @@
 @ControlInterface
     public interface AccountControl {
 
-    public Account getAccount(String userId) throws InvalidIdentifierException, DataStoreException;
-
-    public void insertAccount(Account account)
-        throws InvalidIdentifierException, AccountAlreadyExistsException, DataStoreException;
-
-    public void updateAccount(Account account)
-        throws InvalidIdentifierException, NoSuchAccountException, DataStoreException;
-
-    public boolean checkAccountExists(String userId) throws DataStoreException;
-
-    //public Account[] getAccounts();
+    public Account getAccount(String userId) throws InvalidIdentifierException;
+    public void insertAccount(Account account) throws InvalidIdentifierException, AccountAlreadyExistsException;
+    public void updateAccount(Account account) throws InvalidIdentifierException, NoSuchAccountException;
+    public boolean checkAccountExists(String userId);
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControlImpl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControlImpl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControlImpl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AccountControlImpl.java Mon May  9 20:27:00 2005
@@ -20,55 +20,37 @@
 import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.controls.api.bean.ControlImplementation;
 import org.apache.beehive.samples.petstore.controls.AccountControl;
-import org.apache.beehive.samples.petstore.controls.data.AccountDBControl;
+import org.apache.beehive.samples.petstore.controls.data.AccountDao;
 import org.apache.beehive.samples.petstore.controls.exceptions.AccountAlreadyExistsException;
 import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAccountException;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 import org.apache.beehive.samples.petstore.model.Account;
-import java.sql.SQLException;
 
-@ControlImplementation
-public class AccountControlImpl
-    implements AccountControl, java.io.Serializable
+@ControlImplementation( isTransient=true )
+public class AccountControlImpl implements AccountControl
 {
 	@Control()
-	private AccountDBControl _accountDBControl;
+	private AccountDao _accountDao;
 
     public boolean checkAccountExists(String key)
     {
-		boolean ret = false;
-		try {
-			if (_accountDBControl.checkAccountExists(key) > 0)
-				ret = true;
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return ret;
+		return _accountDao.checkAccountExists(key);
     }
 
     public Account getAccount(String key) throws InvalidIdentifierException
     {
+        if (!checkAccountExists(key))
+            throw new InvalidIdentifierException("no Account found for userId: " + key);
+
 		Account acct = new Account();
-		try {
-			acct = _accountDBControl.getAccountById(key);
-			if (acct == null)
-				throw new InvalidIdentifierException("Account: " + key + " not found!");
-				
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		acct = _accountDao.getAccountById(key);
+		if (acct.getUserId() == null)
+			throw new InvalidIdentifierException("no Account found for userId: " + key);
 		return acct;
     }
 
     public void updateAccount(Account account) 
-        throws InvalidIdentifierException, NoSuchAccountException, DataStoreException
+        throws InvalidIdentifierException, NoSuchAccountException
     {
         String userId = account.getUserId();
         if (userId == null || userId.length()==0)
@@ -81,7 +63,7 @@
     }
 
     public void insertAccount(Account account)
-         throws InvalidIdentifierException, AccountAlreadyExistsException, DataStoreException
+         throws InvalidIdentifierException, AccountAlreadyExistsException
     {
         String userId = account.getUserId();
         if (userId == null || userId.length() == 0)
@@ -97,25 +79,11 @@
 
     private void doUpdateAccount(Account account)
     {
-		try {
-			_accountDBControl.updateAccount(account);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_accountDao.updateAccount(account);
     }
 
     private void doInsertAccount(Account account)
     {
-		try {
-			_accountDBControl.insertAccount(account);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_accountDao.insertAccount(account);
     }
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControl.java Mon May  9 20:27:00 2005
@@ -20,23 +20,21 @@
 import org.apache.beehive.controls.api.bean.ControlInterface;
 
 import org.apache.beehive.samples.petstore.model.Address;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAddressException;
 
 @ControlInterface
 public interface AddressControl {
 
-    public Address getAddress(int addressId) throws InvalidIdentifierException, DataStoreException;
+    public Address getAddress(int addressId) throws InvalidIdentifierException;
 
     public void insertAddress(Address address)
-        throws InvalidIdentifierException, DataStoreException;
+        throws InvalidIdentifierException;
 
     public void updateAddress(Address address)
-        throws InvalidIdentifierException, NoSuchAddressException, DataStoreException;
+        throws InvalidIdentifierException, NoSuchAddressException;
 
-    public Address[] getUserAddresses(String userId) throws DataStoreException;
+    public Address[] getUserAddresses(String userId);
 	
-    public void deleteAddress(int addressId, String userId) throws InvalidIdentifierException, DataStoreException, NoSuchAddressException;
-
+    public void deleteAddress(int addressId, String userId) throws InvalidIdentifierException, NoSuchAddressException;
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControlImpl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControlImpl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControlImpl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/AddressControlImpl.java Mon May  9 20:27:00 2005
@@ -19,49 +19,29 @@
 
 import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.controls.api.bean.ControlImplementation;
-import org.apache.beehive.samples.petstore.controls.data.AddressDBControl;
+import org.apache.beehive.samples.petstore.controls.data.AddressDao;
 import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAddressException;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 import org.apache.beehive.samples.petstore.model.Address;
 
-import java.sql.SQLException;
-
-@ControlImplementation
-public class AddressControlImpl
-    implements AddressControl, java.io.Serializable
+@ControlImplementation( isTransient=true )
+public class AddressControlImpl implements AddressControl
 {
 	@Control()
-	private AddressDBControl _addressDBControl;
+	private AddressDao _addressDao;
 
     public Address[] getUserAddresses(String key)
     {
-		Address[] addresses;
-		try {
-			addresses = _addressDBControl.getUserAddresses(key);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return addresses;
+		return _addressDao.getUserAddresses(key);
     }
 
 	public Address getAddress(int key) throws InvalidIdentifierException
     {
 		Address add = new Address();
-		try {
-			add = _addressDBControl.getAddress(key);
-			if (add == null)
-				throw new InvalidIdentifierException("Address: " + key + " not found!");
-				
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		add = _addressDao.getAddress(key);
+		if (add == null)
+			throw new InvalidIdentifierException("Address: " + key + " not found!");
+
 		return add;
     }
 
@@ -74,36 +54,19 @@
         if (userId == null || userId.length() == 0 || addressId == -1)
             throw new InvalidIdentifierException("cannot update Address with null or empty userId or addressId of -1");
 
-		try {
-			if (_addressDBControl.checkAddressExists(addressId, userId) == 0)
-				throw new NoSuchAddressException("no Address found for userId: " + userId + " and addressId " + addressId);
+		if (!_addressDao.checkAddressExists(addressId, userId))
+			throw new NoSuchAddressException("no Address found for userId: " + userId + " and addressId " + addressId);
 			
-			_addressDBControl.updateAddress(address);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_addressDao.updateAddress(address);
     }
 
-    public void insertAddress(Address address)
-         throws InvalidIdentifierException
+    public void insertAddress(Address address) throws InvalidIdentifierException
     {
         String userId = address.getUserId();
         if (userId == null || userId.length() == 0)
-        {
             throw new InvalidIdentifierException("cannot insert Address with null userId");
-        }
 
-		try {
-			_addressDBControl.insertAddress(address);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_addressDao.insertAddress(address);
     }
 
     public void deleteAddress(int addressId, String userId)
@@ -112,16 +75,9 @@
         if (userId == null || userId.length() == 0 || addressId == -1)
             throw new InvalidIdentifierException("cannot delete Address with null or empty userId or addressId of -1");
 
-		try {
-			if (_addressDBControl.checkAddressExists(addressId, userId) == 0)
-				throw new NoSuchAddressException("no Address found for userId: " + userId + " and addressId " + addressId);
-			
-			_addressDBControl.deleteAddress(addressId, userId);
-		} catch (SQLException e) {
+		if (!_addressDao.checkAddressExists(addressId, userId))
+			throw new NoSuchAddressException("no Address found for userId: " + userId + " and addressId " + addressId);
 			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_addressDao.deleteAddress(addressId, userId);
 	}
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/CatalogControlImpl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/CatalogControlImpl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/CatalogControlImpl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/CatalogControlImpl.java Mon May  9 20:27:00 2005
@@ -22,83 +22,43 @@
 import org.apache.beehive.samples.petstore.model.Item;
 import org.apache.beehive.samples.petstore.model.Category;
 import org.apache.beehive.samples.petstore.model.Product;
-import org.apache.beehive.samples.petstore.controls.data.CatalogDBControl;
+import org.apache.beehive.samples.petstore.controls.data.CatalogDao;
 import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 
-import java.sql.SQLException;
-
-@ControlImplementation
-public class CatalogControlImpl
-    implements CatalogControl, java.io.Serializable
+@ControlImplementation( isTransient=true )
+public class CatalogControlImpl implements CatalogControl
 {
 	@Control()
-	private CatalogDBControl _petsDBControl;
+	private CatalogDao _catalogDao;
 
     public Category[] getCategoryList()
     {
-        // todo: bad form -- should return an immutable array here
-		Category[] categories;
-		try {
-			categories = _petsDBControl.getCategoryList();
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return categories;
+		return _catalogDao.getCategoryList();
     }
 
     public Category getCategory(String key) throws InvalidIdentifierException
     {
 		Category cat = new Category();
-		try {
-			cat = _petsDBControl.getCategory(key);
-			if (cat == null)
-				throw new InvalidIdentifierException("Category: " + key + " not found!");
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		cat = _catalogDao.getCategory(key);
+		if (cat == null)
+			throw new InvalidIdentifierException("Category: " + key + " not found!");
 		return cat;
     }
 
-    /**
-     */
     public Item getItem(String key) throws InvalidIdentifierException
     {
 		Item item = new Item();
-		try {
-			item = _petsDBControl.getItem(key);
-			if (item == null)
-				throw new InvalidIdentifierException("Item: " + key + " not found!");
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		item = _catalogDao.getItem(key);
+		if (item == null)
+			throw new InvalidIdentifierException("Item: " + key + " not found!");
 		return item;
     }
     
-    /**
-     */
     public Item[] getItemListByProduct(String key)
     {
-		Item[] items;
-		try {
-			items = _petsDBControl.getItemListByProduct(key);
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return items;
+		return _catalogDao.getItemListByProduct(key);
     }
 
-    // todo: this doesn't handle the case where something goes "out of stock", ie a negative quantity
     public void updateItemQuantity(Item item, int quantity) throws InvalidIdentifierException
     {
         if(item == null)
@@ -106,67 +66,30 @@
 
 		item.setQty(item.getQty() - quantity);
 
-		try {
-			_petsDBControl.updateItemQuantity(item.getItemId(), item.getQty());
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_catalogDao.updateItemQuantity(item.getItemId(), item.getQty());
     }
 
     public Product getProduct(String key) throws InvalidIdentifierException
     {
 		Product prod = new Product();
-		try {
-			prod = _petsDBControl.getProduct(key);
-			if (prod == null)
-				throw new InvalidIdentifierException("Product: " + key + " not found!");
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		prod = _catalogDao.getProduct(key);
+		if (prod == null)
+			throw new InvalidIdentifierException("Product: " + key + " not found!");
 		return prod;
-
     }
 
     public Product[] getProductListByCategory(String key)
     {
-		Product[] products;
-		try {
-			products = _petsDBControl.getProductListByCategory(key);
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return products;
+		return _catalogDao.getProductListByCategory(key);
     }
 
-
     public Product[] searchProductList(String searchTerm)
     {
-		Product[] products;
-		try {
-			products = _petsDBControl.searchProductList("%" + searchTerm + "%");
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		return products;
+		return _catalogDao.searchProductList(searchTerm);
     }
 	
 	public void initDB(String initString)
 	{
-		try {
-			_petsDBControl.initDB(initString);
-		} catch (SQLException e) {
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
+		_catalogDao.initDB(initString);
 	}
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControl.java Mon May  9 20:27:00 2005
@@ -23,25 +23,15 @@
 import org.apache.beehive.samples.petstore.model.Cart;
 import org.apache.beehive.samples.petstore.model.Order;
 import org.apache.beehive.samples.petstore.model.OrderItem;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchOrderException;
-import org.apache.beehive.samples.petstore.controls.exceptions.OrderAlreadyExistsException;
-import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
 
 @ControlInterface
-    public interface OrderControl {
+public interface OrderControl {
 
     public Order createOrder();
-
-    public int commitOrder(Order order, Cart cart)
-        throws OrderAlreadyExistsException, NoSuchOrderException, InvalidIdentifierException, DataStoreException;
-
-    public Order getOrder(String userId, int key)
-        throws NoSuchOrderException, DataStoreException;
-
-    public Order[] getOrdersByUserId(String key) throws DataStoreException;
-
+    public int commitOrder(Order order, Cart cart);
+    public Order getOrder(String userId, int key) throws NoSuchOrderException;
+    public Order[] getOrdersByUserId(String key);
     public List getCreditCards();
-	
-	public OrderItem[] getOrderItemsByOrderId(int orderId) throws DataStoreException;
+	public OrderItem[] getOrderItemsByOrderId(int orderId);
 }

Modified: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControlImpl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControlImpl.java?rev=169407&r1=169406&r2=169407&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControlImpl.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/OrderControlImpl.java Mon May  9 20:27:00 2005
@@ -17,32 +17,21 @@
  */
 package org.apache.beehive.samples.petstore.controls;
 
-import java.sql.SQLException;
-import java.util.Iterator;
 import java.util.ArrayList;
-
 import java.util.List;
 import org.apache.beehive.samples.petstore.model.Cart;
 import org.apache.beehive.samples.petstore.model.Order;
-import org.apache.beehive.samples.petstore.model.LineItem;
-import org.apache.beehive.samples.petstore.model.Item;
 import org.apache.beehive.samples.petstore.model.OrderItem;
-import org.apache.beehive.samples.petstore.controls.data.OrderDBControl;
-import org.apache.beehive.samples.petstore.controls.exceptions.OrderAlreadyExistsException;
+import org.apache.beehive.samples.petstore.controls.data.OrderDao;
 import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchOrderException;
-import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
-import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.controls.api.bean.ControlImplementation;
 
-@ControlImplementation
-public class OrderControlImpl
-    implements OrderControl, java.io.Serializable
+@ControlImplementation( isTransient=true )
+public class OrderControlImpl implements OrderControl
 {
-    @org.apache.beehive.controls.api.bean.Control()
-    private CatalogControl _catalogControl;
-
-    @org.apache.beehive.controls.api.bean.Control()
-    private OrderDBControl _orderDBControl;
+    @Control()
+    private OrderDao _orderDao;
  
     private static final ArrayList<String> CARD_TYPE_LIST;
 
@@ -61,109 +50,32 @@
 	}
 
     public int commitOrder(Order order, Cart cart)
-        throws OrderAlreadyExistsException, NoSuchOrderException, InvalidIdentifierException
     {
-		int orderId = -1;
-		
-		try {
-			java.sql.Connection connection = _orderDBControl.getConnection();
-			connection.setAutoCommit( false );
-			
-			// Add order to DB
-			_orderDBControl.addOrder(order);
-			orderId = _orderDBControl.getLastOrderIdForUser(order.getUserId());
-			
-	        // Add the cart items and update the quantities in the DB
-			Item item = null;
-	        Iterator i = cart.getLineItems().iterator();
-	        while (i.hasNext())
-	        {
-	            LineItem lineItem = (LineItem) i.next();
-	            updateItemQuantity(lineItem.getItem(), lineItem.getQuantity());
-				addItemToOrder(orderId, lineItem.getItem(), lineItem.getQuantity());
-	        }
-			connection.commit();
-		} catch (SQLException e) {
-				
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-
-		return orderId;
-    }
-
-    /**
-     */
-    public Order getOrder(String userId, int key)
-        throws NoSuchOrderException
+		return _orderDao.addOrder(order, cart);
+    }
+
+    public Order getOrder(String userId, int key) throws NoSuchOrderException
     {
 		Order order = new Order();
-		try {
-			order = _orderDBControl.getOrder(key, userId);
-			if((order == null) || (order.getOrderId() == -1))
-	            throw new NoSuchOrderException("No order could be found with order id: " + key + " for user: " + userId);
-		} catch (SQLException e) {
-
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		
-        return order;
+		order = _orderDao.getOrder(key, userId);
+		if((order == null) || (order.getOrderId() == -1))
+			throw new NoSuchOrderException("No order could be found with order id: " + key + " for user: " + userId);
+
+		return order;
     }
 
     public Order[] getOrdersByUserId(String userId)
     {
-        Order[] orders;
-		try {
-			orders = _orderDBControl.getOrderByUserId(userId);
-		} catch (SQLException e) {
-
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		
-        return orders;
+        return _orderDao.getOrderByUserId(userId);
     }
 
     public OrderItem[] getOrderItemsByOrderId(int orderId)
     {
-        OrderItem[] orderItems;
-		try {
-			orderItems = _orderDBControl.getOrderItems(orderId);
-		} catch (SQLException e) {
-
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-		
-        return orderItems;
+        return _orderDao.getOrderItems(orderId);
     }
 
     public List getCreditCards()
     {
         return CARD_TYPE_LIST;
     }
-
-    private void updateItemQuantity(Item item, int quantity)
-        throws InvalidIdentifierException
-    {
-        _catalogControl.updateItemQuantity(item, quantity);
-    }
-	
-    private void addItemToOrder(int orderId, Item item, int quantity)
-    throws InvalidIdentifierException
-	{
-		try {
-			_orderDBControl.addOrderItem(orderId, item.getItemId(), quantity);
-		} catch (SQLException e) {
-			
-			// Print the stack to std out and bubble a friendly error
-			e.printStackTrace();
-			throw new DataStoreException("Database Error: " + e.getMessage());
-		}
-	}
 }

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,19 @@
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+
+import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+
+import org.apache.beehive.samples.petstore.model.Account;
+
+@ControlInterface(
+    defaultBinding="org.apache.beehive.samples.petstore.controls.data.DerbyAccountDao"
+)
+public interface AccountDao {
+
+    public boolean checkAccountExists( String userId ) throws DataStoreException;
+    public Account getAccountById( String userId ) throws DataStoreException;
+    public void updateAccount( Account account ) throws DataStoreException;
+    public void insertAccount( Account account ) throws DataStoreException;
+}
+

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AccountDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.samples.petstore.model.Address;
+
+@ControlInterface(
+    defaultBinding="org.apache.beehive.samples.petstore.controls.data.DerbyAddressDao"
+)
+public interface AddressDao {
+
+    public Address getAddress(int addressId);
+    public void insertAddress(Address address);
+    public void updateAddress(Address address);
+    public Address[] getUserAddresses(String userId);
+    public void deleteAddress(int addressId, String userId);
+	public boolean checkAddressExists(int addressId, String userId);
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/AddressDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.samples.petstore.model.Category;
+import org.apache.beehive.samples.petstore.model.Item;
+import org.apache.beehive.samples.petstore.model.Product;
+
+@ControlInterface(
+    defaultBinding="org.apache.beehive.samples.petstore.controls.data.DerbyCatalogDao"
+)
+public interface CatalogDao {
+
+    public Category getCategory(String catId);
+    public Category[] getCategoryList();
+    public Product[] getProductListByCategory(String catId);
+    public Product getProduct(String productId);
+    public Item[] getItemListByProduct(String productId);
+    public Item getItem(String itemId);
+    public void updateItemQuantity(String itemId, int quantity);
+    public Product[] searchProductList(String searchTerm);
+	public void initDB(String initString);
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/CatalogDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java Mon May  9 20:27:00 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+
+import org.apache.beehive.samples.petstore.model.Account;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+/** 
+ * This control contains access to the pets database
+ */ 
+
+@org.apache.beehive.controls.api.bean.ControlExtension
+@JdbcControl.ConnectionDriver(databaseDriverClass="org.apache.derby.jdbc.EmbeddedDriver",
+		databaseURL="jdbc:derby:" + DBProperties.dbLocation + "/petStoreDB;create=true")  
+
+public interface DerbyAccountDBControl extends JdbcControl {
+	
+	// getAccounts
+    @SQL(statement="select userId, password, email, firstname, lastname, status, favCategory, " +
+    		"langPref, bannerData, myListOpt as myListState, bannerOpt as bannerOptState from Accounts")
+    public Account[] getAccounts() throws SQLException;
+
+	// checkAccountExists
+    @SQL(statement="select count(*) from Accounts where userId = {userId}")
+    public int checkAccountExists(String userId) throws SQLException;
+	
+	// getAccountById
+    @SQL(statement="select userId, password, email, firstname, lastname, status, favCategory, " +
+    		"langPref, bannerData, myListOpt as myListState, bannerOpt as bannerOptState from Accounts " +
+    		"where userId = {userId}")
+    public Account getAccountById(String userId) throws SQLException;
+
+	// updateAccount
+    @SQL(statement="update Accounts set password = {account.password}, email = {account.email}, " +
+    		"firstName = {account.firstName}, lastName = {account.lastName}, status = {account.status}, " +
+    		"favCategory = {account.favCategory}, langPref = {account.langPref}, bannerData = {account.bannerData}, " +
+    		"myListOpt = {account.myListState}, bannerOpt = {account.bannerOptState} where userId = {account.userId}")
+    public void updateAccount(Account account) throws SQLException;
+
+	// insertAccount
+    @SQL(statement="insert into Accounts values ({account.userId}, {account.password}, {account.email}, {account.firstName}, " +
+    		"{account.lastName}, {account.status}, {account.favCategory}, {account.langPref}, " +
+    		"'', {account.myListState}, {account.bannerOptState})")
+    public void insertAccount(Account account) throws SQLException;
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDBControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,61 @@
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+import org.apache.beehive.samples.petstore.model.Account;
+import org.apache.log4j.Logger;
+
+@ControlImplementation( isTransient=true )
+public class DerbyAccountDao implements AccountDao {
+
+	@Control
+    private DerbyAccountDBControl _dbControl;
+	private static final Logger _logger = Logger.getLogger( DerbyAccountDao.class );
+
+    public boolean checkAccountExists( String userId ) throws DataStoreException
+    {
+        try {
+            int accountExists = _dbControl.checkAccountExists( userId );
+            if( accountExists > 0 ) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch( SQLException e ) {
+            _logger.error( "Unexpected DAO exception", e );
+            throw new DataStoreException( "unexpected database exception" );
+        }
+    }
+
+    public Account getAccountById( String userId ) throws DataStoreException
+    {
+        try {
+            return _dbControl.getAccountById( userId );
+        } catch( SQLException e ) {
+            _logger.error( "Unexpected DAO exception", e );
+            throw new DataStoreException( "unexpected database exception" );
+        }
+    }
+
+    public void updateAccount( Account account ) throws DataStoreException
+    {
+        try {
+            _dbControl.updateAccount( account );
+        } catch( SQLException e ) {
+            _logger.error( "Unexpected DAO exception", e );
+            throw new DataStoreException( "unexpected database exception" );
+        }
+    }
+
+    public void insertAccount( Account account ) throws DataStoreException
+    {
+        try {
+            _dbControl.insertAccount( account );
+        } catch( SQLException e ) {
+            _logger.error( "Unexpected DAO exception", e );
+            throw new DataStoreException( "unexpected database exception" );
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAccountDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java Mon May  9 20:27:00 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+
+import org.apache.beehive.samples.petstore.model.Address;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+/** 
+ * This control contains access to the pets database
+ */ 
+
+@org.apache.beehive.controls.api.bean.ControlExtension
+@JdbcControl.ConnectionDriver(databaseDriverClass="org.apache.derby.jdbc.EmbeddedDriver",
+		databaseURL="jdbc:derby:" + DBProperties.dbLocation + "/petStoreDB;create=true")  
+public interface DerbyAddressDBControl extends JdbcControl {
+    
+	// checkAddressExists
+    @SQL(statement="select count(*) from Addresses where addressId = {addressId} and userId = {userId}")
+    public int checkAddressExists(int addressId, String userId) throws SQLException;
+
+	// getUserAddresses
+    @SQL(statement="select addressId, userId, name, phone, addr1, addr2, " +
+    		"city, state, zip, country from Addresses where userId = {userId}") 
+    public Address[] getUserAddresses(String userId) throws SQLException;
+
+	// getAddress
+    @SQL(statement="select addressId, userId, name, phone, addr1, addr2, " +
+    		"city, state, zip, country from Addresses where addressId = {addressId}")
+    public Address getAddress(int addressId) throws SQLException;
+
+	// updateAddress
+    @SQL(statement="update Addresses set name = {address.name}, " +
+    		"phone = {address.phone}, addr1 = {address.addr1}, addr2 = {address.addr2}, " +
+    		"city = {address.city}, state = {address.state}, zip = {address.zip}, country = {address.country} " +
+    		"where addressId = {address.addressId}")
+    public void updateAddress(Address address) throws SQLException;
+
+	// insertAddress
+    @SQL(statement="insert into Addresses(userId, name, phone, addr1, addr2, " +
+    		"city, state, zip, country) values ({address.userId}, {address.name}, " +
+    		"{address.phone}, {address.addr1}, {address.addr2}, " +
+    		"{address.city}, {address.state}, {address.zip}, {address.country})")
+    public void insertAddress(Address address) throws SQLException;
+
+	// deleteAddress
+    @SQL(statement="delete from Addresses where addressId = {addressId} and userId = {userId}")
+    public void deleteAddress(int addressId, String userId) throws SQLException;
+	
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDBControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+import org.apache.beehive.samples.petstore.model.Address;
+import org.apache.log4j.Logger;
+import java.sql.SQLException;
+
+@ControlImplementation( isTransient=true )
+public class DerbyAddressDao implements AddressDao
+{
+	@Control()
+	private DerbyAddressDBControl _dbControl;
+	private static final Logger _logger = Logger.getLogger( DerbyAccountDao.class );
+
+	public Address[] getUserAddresses(String key)
+    {
+		Address[] addresses;
+		try {
+			addresses = _dbControl.getUserAddresses(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return addresses;
+    }
+
+	public Address getAddress(int key)
+    {
+		Address add = new Address();
+		try {
+			add = _dbControl.getAddress(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return add;
+    }
+
+    public void updateAddress(Address address)
+    {
+		try {
+			_dbControl.updateAddress(address);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+    }
+
+    public void insertAddress(Address address)
+    {
+		try {
+			_dbControl.insertAddress(address);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+    }
+
+    public void deleteAddress(int addressId, String userId)
+	{
+		try {
+			_dbControl.deleteAddress(addressId, userId);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+	}
+	
+	public boolean checkAddressExists(int addressId, String userId)
+	{
+		boolean ret = false;
+		try {
+			if (_dbControl.checkAddressExists(addressId, userId) > 0)
+				ret = true;
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return ret;
+		
+	}
+}

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyAddressDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java Mon May  9 20:27:00 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+import org.apache.beehive.samples.petstore.model.Category;
+import org.apache.beehive.samples.petstore.model.Item;
+import org.apache.beehive.samples.petstore.model.Product;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+/** 
+ * This control contains access to the pets database
+ */ 
+
+@org.apache.beehive.controls.api.bean.ControlExtension
+@JdbcControl.ConnectionDriver(databaseDriverClass="org.apache.derby.jdbc.EmbeddedDriver",
+		databaseURL="jdbc:derby:" + DBProperties.dbLocation + "/petStoreDB;create=true")  
+
+public interface DerbyCatalogDBControl extends JdbcControl {
+    
+	// getCategory
+    @SQL(statement="select catId, name, description, image from Categories where catId = {catId}")
+    public Category getCategory(String catId) throws SQLException;
+
+	// getCategoryList
+    @SQL(statement="select catId, name, description, image from Categories")
+    public Category[] getCategoryList() throws SQLException;
+
+	// getProductListByCategory
+    @SQL(statement="select productId, catId as category, name, description, image from Products where catId = {catId}")
+    public Product[] getProductListByCategory(String catId) throws SQLException;
+
+	// getProduct
+    @SQL(statement="select productId, catId as category, name, description, image from Products where productId = {productId}")
+    public Product getProduct(String productId) throws SQLException;
+
+	// getItemListByProduct
+    @SQL(statement="select i.itemId, i.productId, i.status, i.attr1, i.listPrice, i.unitCost, i.supplier, i.inventoryQuantity as Qty, p.name as productName from Items i, Products p where i.productId = p.productId and i.productId = {productId}")
+    public Item[] getItemListByProduct(String productId) throws SQLException;
+
+	// getItem
+	@SQL(statement="select i.itemId, i.productId, i.status, i.attr1, i.listPrice, i.unitCost, i.supplier, i.inventoryQuantity as Qty, p.name as productName from Items i, Products p where i.productId = p.productId and i.itemId = {itemId}")
+    public Item getItem(String itemId) throws SQLException;
+
+	// updateItemQuantity
+    @SQL(statement="update Items set inventoryQuantity = {quantity} where itemId = {itemId}")
+    public void updateItemQuantity(String itemId, int quantity) throws SQLException;
+
+	// searchProductList
+    @SQL(statement="select p.productId, p.catId as category, p.name, p.description, p.image from Products p, Categories c where p.catId = c.catId and (p.name like {searchTerm} or p.description like {searchTerm} or c.name like {searchTerm})")
+    public Product[] searchProductList(String searchTerm) throws SQLException;
+		
+	// initDB
+	@SQL(statement="{sql: initString}")
+	public void initDB(String initString) throws SQLException;
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDBControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.samples.petstore.model.Item;
+import org.apache.beehive.samples.petstore.model.Category;
+import org.apache.beehive.samples.petstore.model.Product;
+import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+
+@ControlImplementation( isTransient=true )
+public class DerbyCatalogDao implements CatalogDao
+{
+	@Control()
+	private DerbyCatalogDBControl _dbControl;
+	private static final Logger _logger = Logger.getLogger( DerbyAccountDao.class );
+	
+    public Category[] getCategoryList()
+    {
+        // todo: bad form -- should return an immutable array here
+		Category[] categories;
+		try {
+			categories = _dbControl.getCategoryList();
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return categories;
+    }
+
+    public Category getCategory(String key)
+    {
+		Category cat = new Category();
+		try {
+			cat = _dbControl.getCategory(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return cat;
+    }
+
+    public Item getItem(String key)
+    {
+		Item item = new Item();
+		try {
+			item = _dbControl.getItem(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return item;
+    }
+    
+    public Item[] getItemListByProduct(String key)
+    {
+		Item[] items;
+		try {
+			items = _dbControl.getItemListByProduct(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return items;
+    }
+
+    // todo: this doesn't handle the case where something goes "out of stock", ie a negative quantity
+    public void updateItemQuantity(String item, int quantity)
+    {
+		try {
+			_dbControl.updateItemQuantity(item, quantity);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+    }
+
+    public Product getProduct(String key)
+    {
+		Product prod = new Product();
+		try {
+			prod = _dbControl.getProduct(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return prod;
+    }
+
+    public Product[] getProductListByCategory(String key)
+    {
+		Product[] products;
+		try {
+			products = _dbControl.getProductListByCategory(key);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return products;
+    }
+
+    public Product[] searchProductList(String searchTerm)
+    {
+		Product[] products;
+		try {
+			products = _dbControl.searchProductList("%" + searchTerm + "%");
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return products;
+    }
+	
+	public void initDB(String initString)
+	{
+		try {
+			_dbControl.initDB(initString);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+	}
+}

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyCatalogDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java Mon May  9 20:27:00 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+import org.apache.beehive.samples.petstore.model.Order;
+import org.apache.beehive.samples.petstore.model.OrderItem;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+/** 
+ * This control contains access to the pets database
+ */ 
+@org.apache.beehive.controls.api.bean.ControlExtension
+@JdbcControl.ConnectionDriver(databaseDriverClass="org.apache.derby.jdbc.EmbeddedDriver",
+		databaseURL="jdbc:derby:" + DBProperties.dbLocation + "/petStoreDB;create=true")  
+public interface DerbyOrderDBControl 
+    extends JdbcControl {
+    
+	// addOrder
+    @SQL(statement="insert into orders (userId, totalPrice, creditCard, " +
+    		"exprDate, cardType, status, shippingAddress, billingAddress) values (" +
+    		"{order.userId}, {order.totalPrice}, {order.creditCard}, " +
+    		"{order.exprDate}, {order.cardType}, 'OK', " +
+    		"{order.shippingAddress}, {order.billingAddress})")
+    public void addOrder(Order order) throws SQLException;
+	
+	// getLastOrderIdForUser
+	@SQL(statement="select max(orderId) from Orders where userId = {userId}")
+	public int getLastOrderIdForUser(String userId) throws SQLException;
+
+	// addOrderItem
+    @SQL(statement="insert into orderitems values ({orderId}, {itemId}, {quantity})")
+    public void addOrderItem(int orderId, String itemId, int quantity) throws SQLException;
+	
+	// getOrder
+    @SQL(statement="select orderId, userId, orderDate, totalPrice, creditCard," +
+    		"exprDate, cardType, status, shippingAddress, billingAddress from Orders where " +
+    		"orderId = {orderId} and userId = {userId}")
+    public Order getOrder(int orderId, String userId) throws SQLException;
+	
+	// getOrderByUserId
+    @SQL(statement="select orderId, userId, orderDate, totalPrice, creditCard," +
+    		"exprDate, cardType, status, shippingAddress, billingAddress " +
+    		"from Orders where userId = {userId}")
+    public Order[] getOrderByUserId(String userId) throws SQLException;
+
+	// getOrderItems
+    @SQL(statement="select o.itemId, productId, listPrice, unitCost, " +
+    		"supplier, status, attr1, inventoryQuantity as Qty, o.quantity " +
+    		"from OrderItems o, Items i where o.orderId = {orderId} and o.itemId = i.itemId")
+    public OrderItem[] getOrderItems(int orderId) throws SQLException;
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDBControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+import org.apache.beehive.samples.petstore.model.Cart;
+import org.apache.beehive.samples.petstore.model.Order;
+import org.apache.beehive.samples.petstore.model.LineItem;
+import org.apache.beehive.samples.petstore.model.Item;
+import org.apache.beehive.samples.petstore.model.OrderItem;
+import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.log4j.Logger;
+
+@ControlImplementation( isTransient=true )
+public class DerbyOrderDao implements OrderDao
+{
+	@Control()
+	private DerbyCatalogDBControl _catalogControl;
+
+	@Control()
+	private DerbyOrderDBControl _dbControl;
+ 	private static final Logger _logger = Logger.getLogger( DerbyAccountDao.class );
+
+	public int getLastOrderIdForUser(String userId)
+	{
+		int lastOrder = -1;
+		try {
+			lastOrder = _dbControl.getLastOrderIdForUser(userId);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return lastOrder;
+	}
+
+	public int addOrder(Order order, Cart cart)
+    {
+		int orderId = -1;
+		try {
+			java.sql.Connection connection = _dbControl.getConnection();
+			connection.setAutoCommit( false );
+			
+			// Add order to DB
+			_dbControl.addOrder(order);
+			orderId = _dbControl.getLastOrderIdForUser(order.getUserId());
+			if (orderId == -1)
+			{
+				// somehow the order didn't get recorded
+	            _logger.error( "Unexpected DAO exception");
+				throw new DataStoreException("unexpected database exception");
+			}
+			
+	        // Add the cart items and update the quantities in the DB
+			Item item = null;
+	        Iterator i = cart.getLineItems().iterator();
+	        while (i.hasNext())
+	        {
+	            LineItem lineItem = (LineItem) i.next();
+	            _catalogControl.updateItemQuantity(lineItem.getItem().getItemId(), lineItem.getQuantity());
+				_dbControl.addOrderItem(orderId, lineItem.getItem().getItemId(), lineItem.getQuantity());
+	        }
+			connection.commit();
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+		return orderId;
+    }
+
+    public Order getOrder(int key, String userId)
+    {
+		Order order = new Order();
+		try {
+			order = _dbControl.getOrder(key, userId);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+        return order;
+    }
+
+    public Order[] getOrderByUserId(String userId)
+    {
+        Order[] orders;
+		try {
+			orders = _dbControl.getOrderByUserId(userId);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+        return orders;
+    }
+
+    public OrderItem[] getOrderItems(int orderId)
+    {
+        OrderItem[] orderItems;
+		try {
+			orderItems = _dbControl.getOrderItems(orderId);
+		} catch (SQLException e) {
+            _logger.error( "Unexpected DAO exception", e );
+			throw new DataStoreException("unexpected database exception");
+		}
+        return orderItems;
+    }
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/DerbyOrderDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java?rev=169407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java (added)
+++ incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java Mon May  9 20:27:00 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.controls.data;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.samples.petstore.model.Cart;
+import org.apache.beehive.samples.petstore.model.Order;
+import org.apache.beehive.samples.petstore.model.OrderItem;
+
+@ControlInterface(
+    defaultBinding="org.apache.beehive.samples.petstore.controls.data.DerbyOrderDao"
+)
+public interface OrderDao {
+
+    public int addOrder(Order order, Cart cart);
+	public int getLastOrderIdForUser(String userId);
+    public Order getOrder(int orderId, String userId);
+    public Order[] getOrderByUserId(String userId);
+    public OrderItem[] getOrderItems(int orderId);
+}
\ No newline at end of file

Propchange: incubator/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controls/data/OrderDao.java
------------------------------------------------------------------------------
    svn:eol-style = native