cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [29/50] [abbrv] Moved Awsapi (EC2/S3) from Hibernate framework to CloudStack Generic Dao Framework
Date Wed, 05 Sep 2012 21:31:49 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDao.java
index efee98c..7a02c4e 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDao.java
@@ -1,30 +1,11 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
-import com.cloud.bridge.model.MHostMount;
-import com.cloud.bridge.persist.EntityDao;
+import com.cloud.bridge.model.MHostMountVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface MHostMountDao extends GenericDao<MHostMountVO, Long> {
+
+    MHostMountVO getHostMount(long mHostId, long sHostId);
+    
 
-public class MHostMountDao extends EntityDao<MHostMount> {
-	public MHostMountDao() {
-		super(MHostMount.class);
-	}
-	
-	public MHostMount getHostMount(long mHostId, long sHostId) {
-		return queryEntity("from MHostMount where mhost=? and shost=?", new Object[] { mHostId, sHostId } );
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDaoImpl.java
new file mode 100644
index 0000000..4450da8
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MHostMountDaoImpl.java
@@ -0,0 +1,48 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.MHostMountVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={MHostMountDao.class})
+public class MHostMountDaoImpl extends GenericDaoBase<MHostMountVO, Long> implements MHostMountDao {
+    	final SearchBuilder<MHostMountVO> SearchByMHostID = createSearchBuilder();
+	public MHostMountDaoImpl() {
+	}
+	
+	@Override
+	public MHostMountVO getHostMount(long mHostId, long sHostId) { 
+	    SearchByMHostID.and("MHostID", SearchByMHostID.entity().getmHostID(), SearchCriteria.Op.EQ);
+	    SearchByMHostID.and("SHostID", SearchByMHostID.entity().getsHostID(), SearchCriteria.Op.EQ);
+	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    try {
+		txn.start();
+		SearchCriteria<MHostMountVO> sc = SearchByMHostID.create();
+		sc.setParameters("MHostID", mHostId);
+		sc.setParameters("SHostID", sHostId);
+		return findOneBy(sc);
+	    }finally {
+		txn.close();
+	    }
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDao.java
new file mode 100644
index 0000000..399e820
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDao.java
@@ -0,0 +1,18 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import com.cloud.bridge.model.MultiPartPartsVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface MultiPartPartsDao extends GenericDao<MultiPartPartsVO, Long> {
+
+    List<MultiPartPartsVO> getParts(int uploadId, int maxParts, int startAt);
+
+    int getnumParts(int uploadId, int endMarker);
+
+    MultiPartPartsVO findByUploadID(int uploadId, int partNumber);
+
+    void updateParts(MultiPartPartsVO partVO, int uploadId, int partNumber);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDaoImpl.java
new file mode 100644
index 0000000..91e4398
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartPartsDaoImpl.java
@@ -0,0 +1,101 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.MultiPartPartsVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={MultiPartPartsDao.class})
+public class MultiPartPartsDaoImpl extends GenericDaoBase<MultiPartPartsVO, Long> implements MultiPartPartsDao {
+
+    @Override
+    public  List<MultiPartPartsVO> getParts(int uploadId, int maxParts, int startAt ) {
+        
+        SearchBuilder<MultiPartPartsVO> ByUploadID = createSearchBuilder();
+        ByUploadID.and("UploadID", ByUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
+        ByUploadID.and("partNumber", ByUploadID.entity().getPartNumber(), SearchCriteria.Op.GT);
+        ByUploadID.and("partNumber", ByUploadID.entity().getPartNumber(), SearchCriteria.Op.LT);
+        Filter filter = new Filter(MultiPartPartsVO.class, "partNumber", Boolean.TRUE, null, null);
+        
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<MultiPartPartsVO> sc = ByUploadID.create();
+            sc.setParameters("UploadID", new Long(uploadId));
+            sc.setParameters("partNumber", startAt);
+            sc.setParameters("partNumber", maxParts);
+        return listBy(sc, filter);
+        
+        } finally {
+            txn.close();
+        }
+    }
+    
+    @Override
+    public int getnumParts( int uploadId, int endMarker ) {
+        SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
+        byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
+        byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.GT);
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
+            sc.setParameters("UploadID", new Long(uploadId));
+            sc.setParameters("partNumber", endMarker);
+            return listBy(sc).size();
+        
+        } finally {
+            txn.close();
+        }
+
+        
+    }
+    
+    @Override
+    public MultiPartPartsVO findByUploadID(int uploadId, int partNumber) {
+        
+        SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
+        byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
+        byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.EQ);
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
+            sc.setParameters("UploadID", new Long(uploadId));
+            sc.setParameters("partNumber", partNumber);
+            return findOneBy(sc);
+            
+        } finally {
+            txn.close();
+        }
+        
+    }
+    
+    @Override
+    public void updateParts(MultiPartPartsVO partVO, int uploadId, int partNumber) {
+        
+        SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
+        byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
+        byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.EQ);
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
+            sc.setParameters("UploadID", new Long(uploadId));
+            sc.setParameters("partNumber", partNumber);
+            update(partVO, sc);
+            txn.commit();
+        
+        } finally {
+            txn.close();
+        }
+    }
+    
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDao.java
new file mode 100644
index 0000000..4c52958
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDao.java
@@ -0,0 +1,21 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import com.cloud.bridge.model.MultiPartUploadsVO;
+import com.cloud.bridge.util.OrderedPair;
+import com.cloud.utils.db.GenericDao;
+
+public interface MultiPartUploadsDao extends
+        GenericDao<MultiPartUploadsVO, Long> {
+
+    OrderedPair<String, String> multipartExits(int uploadId);
+
+    void deleteUpload(int uploadId);
+
+    String getAtrributeValue(String attribute, int uploadid);
+
+    List<MultiPartUploadsVO> getInitiatedUploads(String bucketName,
+            int maxParts, String prefix, String keyMarker, String uploadIdMarker);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDaoImpl.java
new file mode 100644
index 0000000..b6ad611
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultiPartUploadsDaoImpl.java
@@ -0,0 +1,108 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.MultiPartPartsVO;
+import com.cloud.bridge.model.MultiPartUploadsVO;
+import com.cloud.bridge.model.SBucketVO;
+import com.cloud.bridge.util.OrderedPair;
+import com.cloud.utils.db.Attribute;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={MultiPartUploadsDao.class})
+public class MultiPartUploadsDaoImpl extends GenericDaoBase<MultiPartUploadsVO, Long> implements MultiPartUploadsDao {
+    
+    @Override
+    public OrderedPair<String,String> multipartExits( int uploadId ) {
+        MultiPartUploadsVO uploadvo = null;
+        
+        Transaction txn = null; 
+        try {
+            txn = Transaction.open(Transaction.AWSAPI_DB);
+            uploadvo = findById(new Long(uploadId));
+            if (null != uploadvo)
+                return new OrderedPair<String,String>(uploadvo.getAccessKey(), uploadvo.getNameKey());
+
+            return null;
+        } finally {
+            txn.close();
+        }
+    }
+    
+    @Override
+    public void deleteUpload(int uploadId) {
+        
+        Transaction txn = null; 
+        try {
+            txn = Transaction.open(Transaction.AWSAPI_DB);
+            remove(new Long(uploadId));
+            txn.commit();
+        }finally {
+            txn.close();
+        }
+    }
+    
+    @Override
+    public String getAtrributeValue(String attribute, int uploadid) {
+        Transaction txn = null;
+        MultiPartUploadsVO uploadvo = null;
+        try {
+            txn = Transaction.open(Transaction.AWSAPI_DB);
+            uploadvo = findById(new Long(uploadid));
+            if (null != uploadvo) {
+                if ( attribute.equalsIgnoreCase("AccessKey") )
+                    return uploadvo.getAccessKey();
+                else if ( attribute.equalsIgnoreCase("x_amz_acl") ) 
+                    return uploadvo.getAmzAcl();
+            }
+            return null;
+        } finally {
+            txn.close();
+        }
+    }
+    
+    @Override
+    public List<MultiPartUploadsVO> getInitiatedUploads(String bucketName, int maxParts, String prefix, String keyMarker, String uploadIdMarker) {
+
+        List<MultiPartUploadsVO> uploadList = new ArrayList<MultiPartUploadsVO>();
+        
+        SearchBuilder<MultiPartUploadsVO> byBucket = createSearchBuilder();
+        byBucket.and("BucketName", byBucket.entity().getBucketName() , SearchCriteria.Op.EQ);
+        
+        if (null != prefix)
+            byBucket.and("NameKey", byBucket.entity().getNameKey(), SearchCriteria.Op.LIKE);
+        if (null != uploadIdMarker)
+            byBucket.and("NameKey", byBucket.entity().getNameKey(), SearchCriteria.Op.GT);
+        if (null != uploadIdMarker)
+            byBucket.and("ID", byBucket.entity().getId(), SearchCriteria.Op.GT);
+        
+       Filter filter = new Filter(MultiPartUploadsVO.class, "nameKey", Boolean.TRUE, null, null);
+       filter.addOrderBy(MultiPartUploadsVO.class, "createTime", Boolean.TRUE);
+       
+       Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+       try {
+           txn.start();
+           SearchCriteria<MultiPartUploadsVO> sc = byBucket.create();
+           sc.setParameters("BucketName", bucketName);
+           if (null != prefix)
+               sc.setParameters("NameKey", prefix);
+           if (null != uploadIdMarker)
+               sc.setParameters("NameKey", keyMarker);
+           if (null != uploadIdMarker)
+               sc.setParameters("ID", uploadIdMarker);
+           listBy(sc, filter);
+       
+       }finally {
+           txn.close();
+       }
+        return null;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
index 0ab83eb..c9b5ec7 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
@@ -34,42 +34,25 @@ import java.util.Properties;
 
 import org.apache.log4j.Logger;
 
+import com.cloud.bridge.model.MultiPartPartsVO;
+import com.cloud.bridge.model.MultiPartUploadsVO;
+import com.cloud.bridge.model.MultipartMetaVO;
 import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
 import com.cloud.bridge.service.core.s3.S3MultipartPart;
 import com.cloud.bridge.service.core.s3.S3MultipartUpload;
 import com.cloud.bridge.util.ConfigurationHelper;
 import com.cloud.bridge.util.OrderedPair;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.db.Transaction;
 
 public class MultipartLoadDao {
 	public static final Logger logger = Logger.getLogger(MultipartLoadDao.class);
-
-	private Connection conn       = null;
-	private String     dbName     = null;
-	private String     dbUser     = null;
-	private String     dbPassword = null;
-	private String     dbHost     = null;
-	private String     dbPort     = null; 
 	
-	public MultipartLoadDao() {
-	    File propertiesFile = ConfigurationHelper.findConfigurationFile("db.properties");
-	    Properties EC2Prop = null;
-	       
-	    if (null != propertiesFile) {
-	   	    EC2Prop = new Properties();
-	    	try {
-				EC2Prop.load( new FileInputStream( propertiesFile ));
-			} catch (FileNotFoundException e) {
-				logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
-			} catch (IOException e) {
-				logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
-			}
-            dbHost     = EC2Prop.getProperty( "db.cloud.host" );
-            dbName     = EC2Prop.getProperty( "db.awsapi.name" );
-            dbUser     = EC2Prop.getProperty( "db.cloud.username" );
-            dbPassword = EC2Prop.getProperty( "db.cloud.password" );
-            dbPort     = EC2Prop.getProperty( "db.cloud.port" );
-		}
-	}
+	protected final MultipartMetaDao mpartMetaDao = ComponentLocator.inject(MultipartMetaDaoImpl.class);
+	protected final MultiPartPartsDao mpartPartsDao = ComponentLocator.inject(MultiPartPartsDaoImpl.class);
+	protected final MultiPartUploadsDao mpartUploadDao = ComponentLocator.inject(MultiPartUploadsDaoImpl.class);
+	
+	public MultipartLoadDao() {}
 	
 	/**
 	 * If a multipart upload exists with the uploadId value then return the non-null creators
@@ -77,30 +60,13 @@ public class MultipartLoadDao {
 	 * 
 	 * @param uploadId
 	 * @return creator of the multipart upload, and NameKey of upload
-	 * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException 
 	 */
+	
+	
 	public OrderedPair<String,String> multipartExits( int uploadId ) 
 	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	{
-	    PreparedStatement statement = null;
-	    String accessKey = null;
-	    String nameKey = null;
-		
-        openConnection();	
-        try {            
-		    statement = conn.prepareStatement ( "SELECT AccessKey, NameKey FROM multipart_uploads WHERE ID=?" );
-	        statement.setInt( 1, uploadId );
-	        ResultSet rs = statement.executeQuery();
-		    if ( rs.next()) {
-		    	 accessKey = rs.getString( "AccessKey" );
-		    	 nameKey = rs.getString( "NameKey" );
-		    	 return new OrderedPair<String,String>( accessKey, nameKey );
-		    }
-		    else return null;
-        
-        } finally {
-            closeConnection();
-        }
+	    return mpartUploadDao.multipartExits(uploadId);
 	}
 	
 	/**
@@ -110,23 +76,9 @@ public class MultipartLoadDao {
 	 * 
 	 * @param uploadId
 	 * 
-	 * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException 
 	 */
-	public void deleteUpload( int uploadId )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-	    PreparedStatement statement = null;
-		
-        openConnection();	
-        try {
-		    statement = conn.prepareStatement ( "DELETE FROM multipart_uploads WHERE ID=?" );
-	        statement.setInt( 1, uploadId );
-	        int count = statement.executeUpdate();
-            statement.close();	
-        
-        } finally {
-            closeConnection();
-        }
+	public void deleteUpload( int uploadId ) {
+	    mpartUploadDao.deleteUpload(uploadId);
 	}
 	
 	/**
@@ -134,26 +86,9 @@ public class MultipartLoadDao {
 	 * 
 	 * @param uploadId
 	 * @return the access key value defining the initiator
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	 */
-	public String getInitiator( int uploadId ) 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-	    PreparedStatement statement = null;
-	    String initiator = null;
-		
-        openConnection();	
-        try {
-		    statement = conn.prepareStatement ( "SELECT AccessKey FROM multipart_uploads WHERE ID=?" );
-	        statement.setInt( 1, uploadId );
-	        ResultSet rs = statement.executeQuery();
-		    if (rs.next()) initiator = rs.getString( "AccessKey" );
-            statement.close();			    
-            return initiator;
-        
-        } finally {
-            closeConnection();
-        }
+	public String getInitiator( int uploadId ) {
+	    return mpartUploadDao.getAtrributeValue("AccessKey", uploadId);
 	}
 	
 	/**
@@ -165,47 +100,38 @@ public class MultipartLoadDao {
 	 * @param cannedAccess
 	 * 
 	 * @return if positive its the uploadId to be returned to the client
-	 * 
-	 * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException 
+	 *
 	 */
-	public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta ) 
-	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-	    PreparedStatement statement = null;
+	public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta ) {
 		int uploadId = -1;
-		
-        openConnection();	
+		Transaction txn = null;
         try {
-	        Date tod = new Date();
-	        java.sql.Timestamp dateTime = new Timestamp( tod.getTime());
+            txn = Transaction.open(Transaction.AWSAPI_DB);
+            Date tod = new Date();
+            MultiPartUploadsVO uploadVO = new MultiPartUploadsVO(accessKey,
+                    bucketName, key, cannedAccess, tod);
+            uploadVO = mpartUploadDao.persist(uploadVO);
 
-		    statement = conn.prepareStatement ( "INSERT INTO multipart_uploads (AccessKey, BucketName, NameKey, x_amz_acl, CreateTime) VALUES (?,?,?,?,?)" );
-	        statement.setString( 1, accessKey );
-	        statement.setString( 2, bucketName );
-	        statement.setString( 3, key );
-	        statement.setString( 4, cannedAccess );      
-	        statement.setTimestamp( 5, dateTime );
-            int count = statement.executeUpdate();
-            statement.close();	
+            if (null != uploadVO) {
+                uploadId = uploadVO.getId().intValue();
+                if (null != meta) {
+                    for (int i = 0; i < meta.length; i++) {
+                        MultipartMetaVO mpartMeta = new MultipartMetaVO();
+                        mpartMeta.setUploadID(uploadId);
+                        S3MetaDataEntry entry = meta[i];
+                        mpartMeta.setName(entry.getName());
+                        mpartMeta.setValue(entry.getValue());
+                        mpartMetaDao.persist(mpartMeta);
+                    }
+                    txn.commit();
+                }
+            }
             
-            // -> we need the newly entered ID 
-		    statement = conn.prepareStatement ( "SELECT ID FROM multipart_uploads WHERE AccessKey=? AND BucketName=? AND NameKey=? AND CreateTime=?" );
-	        statement.setString( 1, accessKey );
-	        statement.setString( 2, bucketName );
-	        statement.setString( 3, key );
-	        statement.setTimestamp( 4, dateTime );
-	        ResultSet rs = statement.executeQuery();
-		    if (rs.next()) {
-		    	uploadId = rs.getInt( "ID" );
-		        saveMultipartMeta( uploadId, meta );
-		    }
-            statement.close();			    
             return uploadId;
-        
         } finally {
-            closeConnection();
+            txn.close();
         }
-	}
+    }
 	
 	/**
 	 * Remember all the individual parts that make up the entire multipart upload so that once
@@ -219,49 +145,28 @@ public class MultipartLoadDao {
 	 * @param size
 	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	 */
-	public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size ) 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-    {
-        PreparedStatement statement = null;
-        int id = -1;
-        int count = 0;
-	
-        openConnection();	
+	public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size ) {
+
         try {
-            Date tod = new Date();
-            java.sql.Timestamp dateTime = new java.sql.Timestamp( tod.getTime());
+            MultiPartPartsVO partVO = null;
 
-            // -> are we doing an update or an insert?  (are we over writting an existing entry?)
-		    statement = conn.prepareStatement ( "SELECT ID FROM multipart_parts WHERE UploadID=? AND partNumber=?" );
-            statement.setInt( 1, uploadId );
-            statement.setInt( 2, partNumber  );
-            ResultSet rs = statement.executeQuery();
-		    if (rs.next()) id = rs.getInt( "ID" );
-            statement.close();			    
+            partVO = mpartPartsDao.findByUploadID(uploadId, partNumber);
+            // -> are we doing an update or an insert? (are we over writting an
+            // existing entry?)
 
-            if ( -1 == id )
-            {
-	             statement = conn.prepareStatement ( "INSERT INTO multipart_parts (UploadID, partNumber, MD5, StoredPath, StoredSize, CreateTime) VALUES (?,?,?,?,?,?)" );
-                 statement.setInt(    1, uploadId );
-                 statement.setInt(    2, partNumber );
-                 statement.setString( 3, md5 );
-                 statement.setString( 4, storedPath );   
-                 statement.setInt(    5, size );
-                 statement.setTimestamp( 6, dateTime );
+            if (null == partVO) {
+                MultiPartPartsVO part = new MultiPartPartsVO(uploadId,
+                        partNumber, md5, storedPath, size, new Date());
+                mpartPartsDao.persist(part);
+            } else {
+                partVO.setMd5(md5);
+                partVO.setStoredSize(new Long(size));
+                partVO.setCreateTime(new Date());
+                partVO.setUploadid(new Long(uploadId));
+                partVO.setPartNumber(partNumber);
+                mpartPartsDao.updateParts(partVO, uploadId, partNumber);
             }
-            else
-            {    statement = conn.prepareStatement ( "UPDATE multipart_parts SET MD5=?, StoredSize=?, CreateTime=? WHERE UploadId=? AND partNumber=?" );
-                 statement.setString( 1, md5 );
-                 statement.setInt(    2, size );
-                 statement.setTimestamp( 3, dateTime );
-                 statement.setInt(    4, uploadId );
-                 statement.setInt(    5, partNumber );
-            }
-            count = statement.executeUpdate();
-            statement.close();	
-            
         } finally {
-            closeConnection();
         }
     }
 	
@@ -270,24 +175,8 @@ public class MultipartLoadDao {
 	 * @param uploadId
 	 * @return the value defined in the x-amz-acl header or null
 	 */
-	public String getCannedAccess( int uploadId )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-	    PreparedStatement statement = null;
-	    String access = null;
-		
-        openConnection();	
-        try {
-		    statement = conn.prepareStatement ( "SELECT x_amz_acl FROM multipart_uploads WHERE ID=?" );
-	        statement.setInt( 1, uploadId );
-	        ResultSet rs = statement.executeQuery();
-		    if (rs.next()) access = rs.getString( "x_amz_acl" );
-            statement.close();			    
-            return access;
-        
-        } finally {
-            closeConnection();
-        }
+	public String getCannedAccess( int uploadId ) {
+	    return mpartUploadDao.getAtrributeValue("x_amz_acl", uploadId);
 	}
 	
 	/**
@@ -302,31 +191,25 @@ public class MultipartLoadDao {
         throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	{
 		List<S3MetaDataEntry> metaList = new ArrayList<S3MetaDataEntry>();
-	    PreparedStatement statement = null;
 	    int count = 0;
-		
-        openConnection();	
+	    List<MultipartMetaVO> metaVO; 
         try {
-		    statement = conn.prepareStatement ( "SELECT Name, Value FROM multipart_meta WHERE UploadID=?" );
-	        statement.setInt( 1, uploadId );
-		    ResultSet rs = statement.executeQuery();
-		    
-		    while (rs.next()) 
-		    {
-		    	S3MetaDataEntry oneMeta = new S3MetaDataEntry();
-		    	oneMeta.setName(  rs.getString( "Name" ));
-	            oneMeta.setValue( rs.getString( "Value" ));
-	            metaList.add( oneMeta );
-	            count++;
-		    }
-            statement.close();	
+            
+            metaVO = mpartMetaDao.getByUploadID(uploadId);
+            for (MultipartMetaVO multipartMetaVO : metaVO) {
+                S3MetaDataEntry oneMeta = new S3MetaDataEntry();
+                oneMeta.setName(  multipartMetaVO.getName());
+                oneMeta.setValue( multipartMetaVO.getValue());
+                metaList.add( oneMeta );
+                count++;
+            }
             
             if ( 0 == count )
-            	 return null;
+                return null;
             else return metaList.toArray(new S3MetaDataEntry[0]);
         
         } finally {
-            closeConnection();
+
         }
 	}
 	
@@ -346,52 +229,33 @@ public class MultipartLoadDao {
         throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	{
 		S3MultipartUpload[] inProgress = new S3MultipartUpload[maxParts];
-	    PreparedStatement statement = null;
 	    boolean isTruncated = false;
 	    int i = 0;
 	    int pos = 1;
-	    
+	    List<MultiPartUploadsVO> uploadList;
 	    // -> SQL like condition requires the '%' as a wildcard marker
 	    if (null != prefix) prefix = prefix + "%";
 	    
-	    StringBuffer queryStr = new StringBuffer();
-	    queryStr.append( "SELECT ID, AccessKey, NameKey, CreateTime FROM multipart_uploads WHERE BucketName=? " );   
-	    if (null != prefix        ) queryStr.append( "AND NameKey like ? " );
-	    if (null != keyMarker     ) queryStr.append( "AND NameKey > ? ");
-        if (null != uploadIdMarker) queryStr.append( "AND ID > ? " );    
-        queryStr.append( "ORDER BY NameKey, CreateTime" );
-		
-        openConnection();	
+
         try {
-		    statement = conn.prepareStatement ( queryStr.toString());
-		    statement.setString( pos++, bucketName );
-		    if (null != prefix        ) statement.setString( pos++, prefix );
-		    if (null != keyMarker     ) statement.setString( pos++, keyMarker );
-		    if (null != uploadIdMarker) statement.setString( pos, uploadIdMarker );
-		    ResultSet rs = statement.executeQuery();
-		    
-		    while (rs.next() && i < maxParts) 
-		    {
-		    	Calendar tod = Calendar.getInstance();
-		    	tod.setTime( rs.getTimestamp( "CreateTime" ));
+		    uploadList = mpartUploadDao.getInitiatedUploads(bucketName, maxParts, prefix, keyMarker, uploadIdMarker);
+            for (MultiPartUploadsVO uploadsVO : uploadList) {
+                Calendar tod = Calendar.getInstance();
+                tod.setTime(uploadsVO.getCreateTime());
+                inProgress[i] = new S3MultipartUpload();
+                inProgress[i].setId( uploadsVO.getId().intValue()); 
+                inProgress[i].setAccessKey(uploadsVO.getAccessKey());
+                inProgress[i].setLastModified( tod );
+                inProgress[i].setBucketName( bucketName );
+                inProgress[i].setKey(uploadsVO.getNameKey());
+                i++;
+            }
 
-		    	inProgress[i] = new S3MultipartUpload();
-		    	inProgress[i].setId( rs.getInt( "ID" )); 
-		    	inProgress[i].setAccessKey( rs.getString( "AccessKey" ));
-		    	inProgress[i].setLastModified( tod );
-		    	inProgress[i].setBucketName( bucketName );
-		    	inProgress[i].setKey( rs.getString( "NameKey" ));
-		    	i++;
-		    }
-		    
-		    if (rs.next()) isTruncated = true;
-            statement.close();		
-            
-            if (i < maxParts) inProgress = (S3MultipartUpload[])resizeArray(inProgress,i);
-            return new OrderedPair<S3MultipartUpload[], Boolean>(inProgress, isTruncated);
-        
-        } finally {
-            closeConnection();
+            if (i < maxParts)
+                inProgress = (S3MultipartUpload[]) resizeArray(inProgress, i);
+            return new OrderedPair<S3MultipartUpload[], Boolean>(inProgress,
+                    isTruncated);
+        }finally {
         }
 
 	}
@@ -411,41 +275,30 @@ public class MultipartLoadDao {
 	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	{
 		S3MultipartPart[] parts = new S3MultipartPart[maxParts];
-	    PreparedStatement statement = null;
 	    int i = 0;
-		
-        openConnection();	
-        try {
-		    statement = conn.prepareStatement ( "SELECT   partNumber, MD5, StoredSize, StoredPath, CreateTime " +
-		    		                            "FROM     multipart_parts " +
-		    		                            "WHERE    UploadID=? " +
-		    		                            "AND      partNumber > ? AND partNumber < ? " +
-		    		                            "ORDER BY partNumber" );
-	        statement.setInt( 1, uploadId );
-	        statement.setInt( 2, startAt  );
-	        statement.setInt( 3, startAt + maxParts + 1 );
-		    ResultSet rs = statement.executeQuery();
-		    
-		    while (rs.next() && i < maxParts) 
-		    {
-		    	Calendar tod = Calendar.getInstance();
-		    	tod.setTime( rs.getTimestamp( "CreateTime" ));
-		    	
-		    	parts[i] = new S3MultipartPart();
-		    	parts[i].setPartNumber( rs.getInt( "partNumber" )); 
-		    	parts[i].setEtag( rs.getString( "MD5" ).toLowerCase());
-		    	parts[i].setLastModified( tod );
-		    	parts[i].setSize( rs.getInt( "StoredSize" ));
-		    	parts[i].setPath( rs.getString( "StoredPath" ));
-		    	i++;
-		    }
-            statement.close();		
-            
+	    List<MultiPartPartsVO> partsVO;
+	    try {
+	        
+	        partsVO = mpartPartsDao.getParts(uploadId, startAt + maxParts + 1, startAt);
+	        
+	        for (MultiPartPartsVO partVO : partsVO) {
+                Calendar tod = Calendar.getInstance();
+                tod.setTime(partVO.getCreateTime());
+                
+                parts[i] = new S3MultipartPart();
+                parts[i].setPartNumber(partVO.getPartNumber());
+                parts[i].setEtag(partVO.getMd5());
+                parts[i].setLastModified(tod);
+                parts[i].setSize(partVO.getStoredSize().intValue());
+                parts[i].setPath(partVO.getStoredPath());
+                i++;
+            }
+	        
             if (i < maxParts) parts = (S3MultipartPart[])resizeArray(parts,i);
             return parts;
         
         } finally {
-            closeConnection();
+
         }
 	}
   
@@ -457,25 +310,8 @@ public class MultipartLoadDao {
 	 * @return number of parts with partNumber greater than endMarker
 	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
 	 */
-	public int numParts( int uploadId, int endMarker ) 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-    {
-        PreparedStatement statement = null;
-        int count = 0;
-	
-        openConnection();	
-        try {
-	        statement = conn.prepareStatement ( "SELECT count(*) FROM multipart_parts WHERE UploadID=? AND partNumber > ?" );
-            statement.setInt( 1, uploadId );
-            statement.setInt( 2, endMarker );
-	        ResultSet rs = statement.executeQuery();	    
-	        if (rs.next()) count = rs.getInt( 1 );
-            statement.close();			    
-            return count;
-    
-        } finally {
-            closeConnection();
-        }
+	public int numParts( int uploadId, int endMarker ) {
+	    return mpartPartsDao.getnumParts(uploadId, endMarker);
     }
 
 	/**
@@ -485,46 +321,30 @@ public class MultipartLoadDao {
 	 * @param uploadId - defines an in-process multipart upload
 	 * @param meta - an array of meta data to be assocated with the uploadId value
 	 * 
-	 * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException 
 	 */
-	private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta ) 
-	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-		if (null == meta) return;	
-	    PreparedStatement statement = null;
+	private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta ) {
+		if (null == meta) return;
 		
-        openConnection();	
+		Transaction txn = null;
         try {
+            txn = Transaction.open(Transaction.AWSAPI_DB);
             for( int i=0; i < meta.length; i++ ) 
             {
                S3MetaDataEntry entry = meta[i];
-		       statement = conn.prepareStatement ( "INSERT INTO multipart_meta (UploadID, Name, Value) VALUES (?,?,?)" );
-	           statement.setInt( 1, uploadId );
-	           statement.setString( 2, entry.getName());
-	           statement.setString( 3, entry.getValue());
-               int count = statement.executeUpdate();
-               statement.close();
+               MultipartMetaVO metaVO = new MultipartMetaVO();
+               metaVO.setUploadID(uploadId);
+               metaVO.setName(entry.getName());
+               metaVO.setValue(entry.getValue());
+               metaVO=mpartMetaDao.persist(metaVO);
             }
-            
+            txn.commit();
         } finally {
-            closeConnection();
+            txn.close();
         }
 	}
 	
-	private void openConnection() 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
-        if (null == conn) {
-	        Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
-            conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword );
-        }
-	}
 
-    private void closeConnection() throws SQLException {
-	    if (null != conn) conn.close();
-	    conn = null;
-    }
-    
-    /**
+	/**
     * Reallocates an array with a new size, and copies the contents
     * of the old array to the new array.
     * 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDao.java
new file mode 100644
index 0000000..449ce44
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDao.java
@@ -0,0 +1,12 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import com.cloud.bridge.model.MultipartMetaVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface MultipartMetaDao extends GenericDao<MultipartMetaVO, Long> {
+
+    List<MultipartMetaVO> getByUploadID(long uploadID);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDaoImpl.java
new file mode 100644
index 0000000..cfe56c0
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultipartMetaDaoImpl.java
@@ -0,0 +1,34 @@
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.MultipartMetaVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={MultipartMetaDao.class})
+public class MultipartMetaDaoImpl extends GenericDaoBase<MultipartMetaVO, Long> implements MultipartMetaDao {
+    
+    @Override
+    public List<MultipartMetaVO> getByUploadID (long uploadID) {
+        SearchBuilder <MultipartMetaVO> searchByUID = createSearchBuilder();
+        searchByUID.and("UploadID", searchByUID.entity().getUploadID(), SearchCriteria.Op.EQ);
+        searchByUID.done();
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        try {
+            txn.start();
+            SearchCriteria<MultipartMetaVO> sc = searchByUID.create();
+            sc.setParameters("UploadID", uploadID);
+            return  listBy(sc);
+        
+        }finally {
+            txn.close();
+        }
+        
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/OfferingDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/OfferingDao.java b/awsapi/src/com/cloud/bridge/persist/dao/OfferingDao.java
index 358ce3d..c46b015 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/OfferingDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/OfferingDao.java
@@ -1,169 +1,18 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Properties;
+import com.cloud.bridge.model.OfferingBundleVO;
+import com.cloud.utils.db.GenericDao;
 
-import org.apache.log4j.Logger;
+public interface OfferingDao extends GenericDao<OfferingBundleVO, Long> {
 
-import com.cloud.bridge.util.ConfigurationHelper;
+    int getOfferingCount();
 
+    String getCloudOffering(String amazonEC2Offering);
 
-public class OfferingDao extends BaseDao {
-	public static final Logger logger = Logger.getLogger(OfferingDao.class);
+    String getAmazonOffering(String cloudStackOffering);
 
-	private Connection conn       = null;
-	
-	public OfferingDao() 
-	{
-	}
-	
-	public int getOfferingCount()
-		throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-        PreparedStatement statement = null;
-        int result = 0;
-	
-        openConnection();	
-        try {            
-	        statement = conn.prepareStatement ( "SELECT count(*) FROM offering_bundle" );
-            ResultSet rs = statement.executeQuery();
-	        if (rs.next()) result = rs.getInt(1);
-            statement.close();	
-            return result;
-        } finally {
-            closeConnection();
-        }
-	}
-	
-	public String getCloudOffering( String amazonEC2Offering )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-        PreparedStatement statement = null;
-        String result = null;
-	
-        openConnection();	
-        try {            
-	        statement = conn.prepareStatement ( "SELECT CloudStackOffering FROM offering_bundle WHERE AmazonEC2Offering=?" );
-            statement.setString( 1, amazonEC2Offering );
-            ResultSet rs = statement.executeQuery();
-	        if (rs.next()) result = rs.getString( "CloudStackOffering" );
-            statement.close();	
-            return result;
-    
-        } finally {
-            closeConnection();
-        }
-	}
-	
-	public String getAmazonOffering( String cloudStackOffering )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-        PreparedStatement statement = null;
-        String result = null;
-	
-        openConnection();	
-        try {            
-	        statement = conn.prepareStatement ( "SELECT AmazonEC2Offering FROM offering_bundle WHERE CloudStackOffering=?" );
-            statement.setString( 1, cloudStackOffering );
-            ResultSet rs = statement.executeQuery();
-	        if (rs.next()) result = rs.getString( "AmazonEC2Offering" );
-            statement.close();	
-            return result;
-    
-        } finally {
-            closeConnection();
-        }		
-	}
-		
-	public void setOfferMapping( String amazonEC2Offering, String cloudStackOffering ) 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-   {
-        PreparedStatement statement = null;
-        int id = -1;
-        int count = 0;
+    void setOfferMapping(String amazonEC2Offering, String cloudStackOffering);
 
-        openConnection();	
-        try {    
-            // -> are we doing an update or an insert?  (are we over writing an existing entry?)
-		    statement = conn.prepareStatement ( "SELECT ID FROM offering_bundle WHERE AmazonEC2Offering=?" );
-            statement.setString( 1, amazonEC2Offering  );
-            ResultSet rs = statement.executeQuery();
-		    if (rs.next()) id = rs.getInt( "ID" );
-            statement.close();			    
+    void deleteOfferMapping(String amazonEC2Offering);
 
-            if ( -1 == id )
-            {
-                 statement = conn.prepareStatement ( "INSERT INTO offering_bundle (AmazonEC2Offering, CloudStackOffering) VALUES (?,?)" );
-                 statement.setString( 1, amazonEC2Offering  );
-                 statement.setString( 2, cloudStackOffering );
-            }
-            else
-            {    statement = conn.prepareStatement ( "UPDATE offering_bundle SET CloudStackOffering=? WHERE AmazonEC2Offering=?" );
-                 statement.setString( 1, cloudStackOffering );
-                 statement.setString( 2, amazonEC2Offering  );
-            }         
-            count = statement.executeUpdate();
-            statement.close();	
-
-        } finally {
-            closeConnection();
-        }
-    }
-	
-	public void deleteOfferMapping( String amazonEC2Offering )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-    {
-        PreparedStatement statement = null;
-
-        openConnection();	
-        try {
-            statement = conn.prepareStatement ( "DELETE FROM offering_bundle WHERE AmazonEC2Offering=?" );
-            statement.setString( 1, amazonEC2Offering );
-            int count = statement.executeUpdate();
-            statement.close();	
-
-        } finally {
-            closeConnection();
-        }
-    }
-
-	private void openConnection() 
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException 
-    {
-        if (null == conn) {
-            Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
-            conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + awsapi_dbName, dbUser, dbPassword );
-        }
-    }
-
-    private void closeConnection() throws SQLException 
-    {
-        if (null != conn) conn.close();
-        conn = null;
-    }
 }
-

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java
new file mode 100644
index 0000000..5a9a625
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java
@@ -0,0 +1,135 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+
+import javax.ejb.Local;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.bridge.model.OfferingBundleVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={OfferingDao.class})
+public class OfferingDaoImpl extends GenericDaoBase<OfferingBundleVO, Long> implements OfferingDao {
+	public static final Logger logger = Logger.getLogger(OfferingDaoImpl.class);
+
+	public OfferingDaoImpl() {}
+	
+	@Override
+	public int getOfferingCount() {
+       Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        try {
+            txn.start();
+            return listAll().size();
+        }finally {
+            txn.close();
+        }
+	    
+	}
+	
+	@Override
+	public String getCloudOffering( String amazonEC2Offering ) {
+	    
+       SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
+       searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
+       searchByAmazon.done();
+       Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+       try {
+           txn.start();
+           SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
+           sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
+           return findOneBy(sc).getCloudstackOffering();
+           
+        } finally {
+            txn.close();
+        }
+	}
+	
+	@Override
+	public String getAmazonOffering( String cloudStackOffering ) {
+        
+	       SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
+	       searchByAmazon.and("CloudStackOffering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
+	       searchByAmazon.done();
+	       Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	       try {
+	           txn.start();
+	           SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
+	           sc.setParameters("CloudStackOffering", cloudStackOffering);
+	           return findOneBy(sc).getAmazonOffering();
+	           
+	        } finally {
+	            txn.close();
+	        }
+	    }
+	
+	@Override
+	public void setOfferMapping( String amazonEC2Offering, String cloudStackOffering ) {
+	    
+        SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
+        searchByAmazon.and("CloudStackOffering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
+        searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getCloudstackOffering() , SearchCriteria.Op.EQ);
+        searchByAmazon.done();
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        OfferingBundleVO offering = null;
+        try {
+            txn.start();
+            SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
+            sc.setParameters("CloudStackOffering", cloudStackOffering);
+            sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
+            offering = findOneBy(sc);
+            if (null == offering) {
+                offering = new OfferingBundleVO();
+            }
+            offering.setAmazonOffering(amazonEC2Offering);
+            offering.setCloudstackOffering(cloudStackOffering);
+            if (null == offering) 
+                offering = persist(offering);
+            else
+                update(offering.getID(), offering);
+
+            txn.commit();
+         } finally {
+             txn.close();
+         }
+
+	}
+	
+	@Override
+	public void deleteOfferMapping( String amazonEC2Offering ) {
+	    SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
+        searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
+        searchByAmazon.done();
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        try {
+            txn.start();
+            SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
+            sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
+            remove(sc);
+            txn.commit();
+         } finally {
+             txn.close();
+         }
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SAclDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SAclDao.java b/awsapi/src/com/cloud/bridge/persist/dao/SAclDao.java
index d62ae5b..5a5be6e 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SAclDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SAclDao.java
@@ -1,76 +1,21 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
-import java.util.Date;
 import java.util.List;
 
 import com.cloud.bridge.model.SAcl;
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.bridge.persist.PersistContext;
+import com.cloud.bridge.model.SAclVO;
 import com.cloud.bridge.service.core.s3.S3AccessControlList;
 import com.cloud.bridge.service.core.s3.S3Grant;
+import com.cloud.utils.db.GenericDao;
 
-public class SAclDao extends EntityDao<SAcl> {
-	
-	public SAclDao() {
-		super(SAcl.class);
-	}
-	
-	public List<SAcl> listGrants(String target, long targetId) {
-		return queryEntities("from SAcl where target=? and targetId=? order by grantOrder asc",
-			new Object[] { target, new Long(targetId)});
-	}
+public interface SAclDao extends GenericDao<SAclVO, Long> {
 
-	public List<SAcl> listGrants(String target, long targetId, String userCanonicalId) {
-		return queryEntities("from SAcl where target=? and targetId=? and granteeCanonicalId=? order by grantOrder asc",
-			new Object[] { target, new Long(targetId), userCanonicalId });
-	}
+    List<SAclVO> listGrants(String target, long targetId, String userCanonicalId);
+
+    void save(String target, long targetId, S3AccessControlList acl);
+
+    SAcl save(String target, long targetId, S3Grant grant, int grantOrder);
+
+    List<SAclVO> listGrants(String target, long targetId);
 
-	public void save(String target, long targetId, S3AccessControlList acl) {
-		// -> the target's ACLs are being redefined
-		executeUpdate("delete from SAcl where target=? and targetId=?",	new Object[] { target, new Long(targetId)});
-		
-		if(acl != null) {
-			S3Grant[] grants = acl.getGrants();
-			if(grants != null && grants.length > 0) {
-				int grantOrder = 1;
-				for(S3Grant grant : grants) {
-					save(target, targetId, grant, grantOrder++);
-				}
-			}
-		}
-	}
-	
-	public SAcl save(String target, long targetId, S3Grant grant, int grantOrder) {
-		SAcl aclEntry = new SAcl();
-		aclEntry.setTarget(target);
-		aclEntry.setTargetId(targetId);
-		aclEntry.setGrantOrder(grantOrder);
-		
-		int grantee = grant.getGrantee();
-		aclEntry.setGranteeType(grantee);
-		aclEntry.setPermission(grant.getPermission());
-		aclEntry.setGranteeCanonicalId(grant.getCanonicalUserID());
-		
-		Date ts = new Date();
-		aclEntry.setCreateTime(ts);
-		aclEntry.setLastModifiedTime(ts);
-		PersistContext.getSession().save(aclEntry);
-		return aclEntry;
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java
new file mode 100644
index 0000000..c73c1db
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java
@@ -0,0 +1,127 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.SAcl;
+import com.cloud.bridge.model.SAclVO;
+import com.cloud.bridge.service.core.s3.S3AccessControlList;
+import com.cloud.bridge.service.core.s3.S3Grant;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={SAclDao.class})
+public class SAclDaoImpl extends GenericDaoBase<SAclVO, Long> implements SAclDao {
+
+	public SAclDaoImpl() {}
+	
+	@Override
+	public List<SAclVO> listGrants(String target, long targetId) {
+	    SearchBuilder<SAclVO> SearchByTarget = createSearchBuilder();
+	    SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
+	    SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
+	    SearchByTarget.done();
+	    Filter filter = new Filter(SAclVO.class, "grantOrder", Boolean.TRUE, null, null);
+	    Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
+	    try {
+		txn.start();
+		SearchCriteria<SAclVO> sc = SearchByTarget.create();
+		sc.setParameters("Target", target);
+		sc.setParameters("TargetID", targetId);
+		return listBy(sc, filter);
+		
+	    } finally {
+		txn.close();
+	    }
+	}
+	
+	@Override
+	public List<SAclVO> listGrants(String target, long targetId, String userCanonicalId) {
+	    SearchBuilder<SAclVO> SearchByAcl = createSearchBuilder();
+	    SearchByAcl.and("Target", SearchByAcl.entity().getTarget(), SearchCriteria.Op.EQ);
+	    SearchByAcl.and("TargetID", SearchByAcl.entity().getTargetId(), SearchCriteria.Op.EQ);
+	    SearchByAcl.and("GranteeCanonicalID", SearchByAcl.entity().getGranteeCanonicalId(), SearchCriteria.Op.EQ);
+	    Filter filter = new Filter(SAclVO.class, "grantOrder", Boolean.TRUE, null, null);
+	    Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
+	    try {
+    		txn.start();
+    		SearchCriteria<SAclVO> sc = SearchByAcl.create();
+    		sc.setParameters("Target", target);
+    		sc.setParameters("TargetID", targetId);
+    		sc.setParameters("GranteeCanonicalID", userCanonicalId);
+    		return listBy(sc, filter);
+	    } finally {
+		txn.close();
+	    }
+	}
+
+	@Override
+	public void save(String target, long targetId, S3AccessControlList acl) {
+	    SearchBuilder<SAclVO> SearchByTarget = createSearchBuilder();
+	    SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
+	    SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
+
+	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    try {
+		txn.start();
+		SearchCriteria<SAclVO> sc = SearchByTarget.create();
+		sc.setParameters("Target", target);
+		sc.setParameters("TargetID", targetId);
+		this.remove(sc);
+		if(acl != null) {
+			S3Grant[] grants = acl.getGrants();
+			if(grants != null && grants.length > 0) {
+				int grantOrder = 1;
+				for(S3Grant grant : grants) {
+					save(target, targetId, grant, grantOrder++);
+				}
+			}
+		}
+		txn.commit();
+	    } finally {
+		txn.close();
+	    }
+	    
+	    
+	}
+	
+	@Override
+	public SAcl save(String target, long targetId, S3Grant grant, int grantOrder) {
+		SAclVO aclEntry = new SAclVO();
+		aclEntry.setTarget(target);
+		aclEntry.setTargetId(targetId);
+		aclEntry.setGrantOrder(grantOrder);
+		
+		int grantee = grant.getGrantee();
+		aclEntry.setGranteeType(grantee);
+		aclEntry.setPermission(grant.getPermission());
+		aclEntry.setGranteeCanonicalId(grant.getCanonicalUserID());
+		
+		Date ts = new Date();
+		aclEntry.setCreateTime(ts);
+		aclEntry.setLastModifiedTime(ts);
+		aclEntry = this.persist(aclEntry);
+		return aclEntry;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SBucketDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SBucketDao.java b/awsapi/src/com/cloud/bridge/persist/dao/SBucketDao.java
index 833bf6a..0f42200 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SBucketDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SBucketDao.java
@@ -1,37 +1,14 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
 import java.util.List;
 
-import com.cloud.bridge.model.SBucket;
-import com.cloud.bridge.persist.EntityDao;
+import com.cloud.bridge.model.SBucketVO;
+import com.cloud.utils.db.GenericDao;
 
-public class SBucketDao extends EntityDao<SBucket> {
-	public SBucketDao() {
-		super(SBucket.class);
-	}
+public interface SBucketDao extends GenericDao<SBucketVO, Long> {
+
+    SBucketVO getByName(String bucketName);
+
+    List<SBucketVO> listBuckets(String canonicalId);
 
-	public SBucket getByName(String bucketName) {
-		return queryEntity("from SBucket where name=?", new Object[] {bucketName});
-	}
-	
-	public List<SBucket> listBuckets(String canonicalId) {
-		return queryEntities("from SBucket where ownerCanonicalId=? order by createTime asc", 
-			new Object[] {canonicalId});
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java
new file mode 100644
index 0000000..53e9e07
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.SBucket;
+import com.cloud.bridge.model.SBucketVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={SBucketDao.class})
+public class SBucketDaoImpl extends GenericDaoBase<SBucketVO, Long> implements SBucketDao {
+    	
+	public SBucketDaoImpl() {
+	}
+
+	@Override
+	public SBucketVO getByName(String bucketName) {
+	    SearchBuilder<SBucketVO> SearchByName = createSearchBuilder();
+	    SearchByName.and("Name", SearchByName.entity().getName(), SearchCriteria.Op.EQ);
+	    //Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+	    try {
+		txn.start();
+		SearchCriteria<SBucketVO> sc = SearchByName.create();
+		sc.setParameters("Name", bucketName);
+		return findOneBy(sc);
+		
+	    }finally {
+		txn.close();
+	    }
+	}
+	
+	@Override
+	public List<SBucketVO> listBuckets(String canonicalId) {
+	    SearchBuilder<SBucketVO> ByCanonicalID = createSearchBuilder();
+	    ByCanonicalID.and("OwnerCanonicalID", ByCanonicalID.entity().getOwnerCanonicalId(), SearchCriteria.Op.EQ);
+	    Filter filter = new Filter(SBucketVO.class, "createTime", Boolean.TRUE, null, null);
+	    Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+	    try {
+            txn.start();
+            SearchCriteria<SBucketVO> sc = ByCanonicalID.create();
+            sc.setParameters("OwnerCanonicalID", canonicalId);
+		return listBy(sc, filter);
+	    }finally {
+            txn.close();
+	    }
+
+	}
+	
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SHostDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SHostDao.java b/awsapi/src/com/cloud/bridge/persist/dao/SHostDao.java
index 1108bcb..fc8865c 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SHostDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SHostDao.java
@@ -1,35 +1,12 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
-import com.cloud.bridge.model.SHost;
-import com.cloud.bridge.persist.EntityDao;
+import com.cloud.bridge.model.SHostVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface SHostDao extends GenericDao<SHostVO, Long> {
+
+    SHostVO getByHost(String host);
+
+    SHostVO getLocalStorageHost(long mhostId, String storageRoot);
 
-public class SHostDao extends EntityDao<SHost> {
-	public SHostDao() {
-		super(SHost.class);
-	}
-	
-	public SHost getByHost(String host) {
-		return queryEntity("from SHost where host=?", new Object[] { host });
-	}
-	
-	public SHost getLocalStorageHost(long mhostId, String storageRoot) {
-		return queryEntity("from SHost where mhost=? and exportRoot=?", 
-			new Object[] { new Long(mhostId), storageRoot});
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java
new file mode 100644
index 0000000..efe9500
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.SHostVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={SHostDao.class})
+public class SHostDaoImpl extends GenericDaoBase<SHostVO, Long> implements SHostDao {
+	public SHostDaoImpl() {}
+	
+	@Override
+	public SHostVO getByHost(String host) {
+	    SearchBuilder <SHostVO> HostSearch = createSearchBuilder();
+	    HostSearch.and("Host", HostSearch.entity().getHost(), SearchCriteria.Op.EQ);
+	    HostSearch.done();
+	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    try {
+    		txn.start();
+    		SearchCriteria<SHostVO> sc = HostSearch.create();
+    		sc.setParameters("Host", host);
+    		return findOneBy(sc);
+		
+	    }finally {
+	        txn.close();
+	    }
+	    
+	}
+	
+	@Override
+	public SHostVO getLocalStorageHost(long mhostId, String storageRoot) {
+	    SearchBuilder <SHostVO> LocalStorageHostSearch = createSearchBuilder();
+	    LocalStorageHostSearch.and("MHostID", LocalStorageHostSearch.entity().getMhostid(), SearchCriteria.Op.EQ);
+	    LocalStorageHostSearch.and("ExportRoot", LocalStorageHostSearch.entity().getExportRoot(), SearchCriteria.Op.EQ);
+	    LocalStorageHostSearch.done();
+	    Transaction txn = Transaction.currentTxn();
+	    try {
+            txn.start();
+            SearchCriteria<SHostVO> sc = LocalStorageHostSearch.create();
+            sc.setParameters("MHostID", mhostId);
+            sc.setParameters("ExportRoot", storageRoot);
+            return findOneBy(sc);
+		
+	    }finally {
+            txn.close();
+	    }	
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SMetaDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SMetaDao.java b/awsapi/src/com/cloud/bridge/persist/dao/SMetaDao.java
index b781bbb..225138e 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SMetaDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SMetaDao.java
@@ -1,55 +1,17 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
 import java.util.List;
 
-import com.cloud.bridge.model.SMeta;
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.bridge.persist.PersistContext;
+import com.cloud.bridge.model.SMetaVO;
 import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
+import com.cloud.utils.db.GenericDao;
 
-public class SMetaDao extends EntityDao<SMeta> {
-	public SMetaDao() {
-		super(SMeta.class);
-	}
-	
-	public List<SMeta> getByTarget(String target, long targetId) {
-		return queryEntities("from SMeta where target=? and targetId=?", new Object[] {target, targetId});
-	}
+public interface SMetaDao extends GenericDao<SMetaVO, Long> {
 
-	public SMeta save(String target, long targetId, S3MetaDataEntry entry) {
-		SMeta meta = new SMeta();
-		meta.setTarget(target);
-		meta.setTargetId(targetId);
-		meta.setName(entry.getName());
-		meta.setValue(entry.getValue());
-		
-		PersistContext.getSession().save(meta);
-		return meta;
-	}
-	
-	public void save(String target, long targetId, S3MetaDataEntry[] entries) {
-		// To redefine the target's metadaa
-		executeUpdate("delete from SMeta where target=? and targetId=?", new Object[] { target, new Long(targetId)});
+    List<SMetaVO> getByTarget(String target, long targetId);
+
+    SMetaVO save(String target, long targetId, S3MetaDataEntry entry);
+
+    void save(String target, long targetId, S3MetaDataEntry[] entries);
 
-		if(entries != null) {
-			for(S3MetaDataEntry entry : entries)
-				save(target, targetId, entry);
-		}
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java
new file mode 100644
index 0000000..e0555ec
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.SMetaVO;
+import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={SMetaDao.class})
+public class SMetaDaoImpl extends GenericDaoBase<SMetaVO, Long> implements SMetaDao {
+
+	public SMetaDaoImpl() {}
+	
+	@Override
+	public List<SMetaVO> getByTarget(String target, long targetId) {
+	    SearchBuilder <SMetaVO> SearchByTarget = createSearchBuilder();
+	    SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
+	    SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
+	    SearchByTarget.done();
+	    Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
+	    try {
+            txn.start();
+            SearchCriteria<SMetaVO> sc = SearchByTarget.create();
+            sc.setParameters("Target", target);
+            sc.setParameters("TargetID", targetId);
+            return listBy(sc);
+	    } finally {
+            txn.close();
+	    }
+
+	}
+	
+	@Override
+	public SMetaVO save(String target, long targetId, S3MetaDataEntry entry) {
+		SMetaVO meta = new SMetaVO();
+		meta.setTarget(target);
+		meta.setTargetId(targetId);
+		meta.setName(entry.getName());
+		meta.setValue(entry.getValue());
+		meta = this.persist(meta);
+		return meta;
+	}
+	
+	@Override
+	public void save(String target, long targetId, S3MetaDataEntry[] entries) {
+		// To redefine the target's metadaa
+	    SearchBuilder <SMetaVO> SearchByTarget = createSearchBuilder();
+	    SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
+	    SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
+	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    try {
+		txn.start();
+		SearchCriteria<SMetaVO> sc = SearchByTarget.create();
+		sc.setParameters("Target", target);
+		sc.setParameters("TargetID", targetId);
+		this.remove(sc);
+
+		if(entries != null) {
+		    for(S3MetaDataEntry entry : entries)
+        		save(target, targetId, entry);
+        	}
+		txn.commit();
+		}finally {
+		    txn.close();
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SObjectDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SObjectDao.java b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDao.java
index 3d87cbe..42fcd02 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SObjectDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDao.java
@@ -1,76 +1,19 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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.
 package com.cloud.bridge.persist.dao;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import com.cloud.bridge.model.SBucket;
-import com.cloud.bridge.model.SObject;
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.bridge.util.EntityParam;
+import com.cloud.bridge.model.SBucketVO;
+import com.cloud.bridge.model.SObjectVO;
+import com.cloud.utils.db.GenericDao;
 
-public class SObjectDao extends EntityDao<SObject> {
-	public SObjectDao() {
-		super(SObject.class);
-	}
+public interface SObjectDao extends GenericDao<SObjectVO, Long> {
 
-	public SObject getByNameKey(SBucket bucket, String nameKey) {
-		return queryEntity("from SObject where bucket=? and nameKey=?", 
-				new Object[] { new EntityParam(bucket), nameKey });
-	}
-	
-	public List<SObject> listBucketObjects(SBucket bucket, String prefix, String marker, int maxKeys) {
-		StringBuffer sb = new StringBuffer();
-		List<Object> params = new ArrayList<Object>();
+    List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix,
+            String marker, int maxKeys);
 
-		sb.append("from SObject o left join fetch o.items where deletionMark is null and o.bucket=?");
-		params.add(new EntityParam(bucket));
-		
-		if(prefix != null && !prefix.isEmpty()) {
-			sb.append(" and o.nameKey like ?");
-			params.add(new String(prefix + "%"));
-		}
-		
-		if(marker != null && !marker.isEmpty()) {
-			sb.append(" and o.nameKey > ?");
-			params.add(marker);
-		}
-		
-		return queryEntities(sb.toString(), 0, maxKeys, params.toArray());
-	}
-	
-	public List<SObject> listAllBucketObjects(SBucket bucket, String prefix, String marker, int maxKeys) {
-		StringBuffer sb = new StringBuffer();
-		List<Object> params = new ArrayList<Object>();
+    List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix,
+            String marker, int maxKeys);
+
+    SObjectVO getByNameKey(SBucketVO bucket, String nameKey);
 
-		sb.append("from SObject o left join fetch o.items where o.bucket=?");
-		params.add(new EntityParam(bucket));
-		
-		if(prefix != null && !prefix.isEmpty()) {
-			sb.append(" and o.nameKey like ?");
-			params.add(new String(prefix + "%"));
-		}
-		
-		if(marker != null && !marker.isEmpty()) {
-			sb.append(" and o.nameKey > ?");
-			params.add(marker);
-		}
-		
-		return queryEntities(sb.toString(), 0, maxKeys, params.toArray());
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
new file mode 100644
index 0000000..b588877
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+package com.cloud.bridge.persist.dao;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.SBucket;
+import com.cloud.bridge.model.SBucketVO;
+import com.cloud.bridge.model.SObjectItemVO;
+import com.cloud.bridge.model.SObjectVO;
+import com.cloud.bridge.util.EntityParam;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={SObjectDao.class})
+public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements SObjectDao {
+    protected final SObjectItemDao itemDao = ComponentLocator.inject(SObjectItemDaoImpl.class);
+    
+	public SObjectDaoImpl() {}
+
+	@Override
+	public SObjectVO getByNameKey(SBucketVO bucket, String nameKey) {
+		SObjectVO object = null; 
+	    SearchBuilder<SObjectVO> SearchByName = createSearchBuilder();
+	    SearchByName.and("SBucketID", SearchByName.entity().getBucketID() , SearchCriteria.Op.EQ);
+	    SearchByName.and("NameKey", SearchByName.entity().getNameKey() , SearchCriteria.Op.EQ);
+	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+	    try {
+            txn.start();
+            SearchCriteria<SObjectVO> sc = SearchByName.create();
+            sc.setParameters("SBucketID", bucket.getId());
+            sc.setParameters("NameKey", nameKey);
+            object = findOneBy(sc);
+            if (null != object) {
+                Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(
+                        itemDao.getItems(object.getId()));
+                object.setItems(items);
+            }
+		return object;
+		
+	    }finally {
+            txn.close();
+	    }
+	    
+	}
+	
+	@Override
+	public List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
+		StringBuffer sb = new StringBuffer();
+		List<Object> params = new ArrayList<Object>();
+		SearchBuilder<SObjectVO> SearchByBucket = createSearchBuilder();
+		List<SObjectVO> objects = new ArrayList<SObjectVO>();
+		
+		SearchByBucket.and("SBucketID", SearchByBucket.entity().getBucketID(), SearchCriteria.Op.EQ);
+		SearchByBucket.and("DeletionMark", SearchByBucket.entity().getDeletionMark(), SearchCriteria.Op.NULL);		
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<SObjectVO> sc = SearchByBucket.create();
+            sc.setParameters("SBucketID", bucket.getId());
+            objects = listBy(sc);
+            for (SObjectVO sObjectVO : objects) {
+                Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(itemDao.getItems(sObjectVO.getId()));
+                sObjectVO.setItems(items);
+            }
+            return objects;
+        }finally {
+        txn.close();
+        }
+	}
+	
+	@Override
+	public List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
+		StringBuffer sb = new StringBuffer();
+		List<Object> params = new ArrayList<Object>();
+		SearchBuilder<SObjectVO> getAllBuckets = createSearchBuilder();
+		List<SObjectVO> objects = new ArrayList<SObjectVO>();
+		getAllBuckets.and("SBucketID", getAllBuckets.entity().getBucketID(), SearchCriteria.Op.EQ);
+
+		Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        try {
+            txn.start();
+            SearchCriteria<SObjectVO> sc = getAllBuckets.create();
+            sc.setParameters("SBucketID", bucket.getId());
+            objects = listBy(sc);
+            for (SObjectVO sObjectVO : objects) {
+                Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(itemDao.getItems(sObjectVO.getId()));
+                sObjectVO.setItems(items);
+            }
+            return objects;
+        }finally {
+        txn.close();
+        }
+		
+	}
+}


Mime
View raw message