diff --git a/awsapi/.classpath b/awsapi/.classpath
new file mode 100644
index 00000000000..9dce8941421
--- /dev/null
+++ b/awsapi/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/awsapi/conf/CloudStack.cfg.xml b/awsapi/conf/CloudStack.cfg.xml
new file mode 100644
index 00000000000..d34d2f55367
--- /dev/null
+++ b/awsapi/conf/CloudStack.cfg.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+ com.mysql.jdbc.Driver
+ 20
+ false
+
+
+ 2
+
+ update
+ true
+ org.hibernate.dialect.MySQLDialect
+
+ true
+
+
+
+
+
+
+
+
diff --git a/awsapi/src/com/cloud/bridge/persist/EntityDao.java b/awsapi/src/com/cloud/bridge/persist/EntityDao.java
index 0bab9ea6e86..ba19cceb5fd 100644
--- a/awsapi/src/com/cloud/bridge/persist/EntityDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/EntityDao.java
@@ -29,38 +29,44 @@ import com.cloud.bridge.util.QueryHelper;
public class EntityDao {
private Class> clazz;
- public EntityDao(Class> clazz) {
+ private boolean isCloudStackSession = false;
+
+ public EntityDao(Class> clazz){
+ this(clazz, false);
+ }
+
+ public EntityDao(Class> clazz, boolean isCloudStackSession) {
this.clazz = clazz;
-
+ this.isCloudStackSession = isCloudStackSession;
// Note : beginTransaction can be called multiple times
- PersistContext.beginTransaction();
+ PersistContext.beginTransaction(isCloudStackSession);
}
@SuppressWarnings("unchecked")
public T get(Serializable id) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
return (T)session.get(clazz, id);
}
public T save(T entity) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
session.saveOrUpdate(entity);
return entity;
}
public T update(T entity) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
session.saveOrUpdate(entity);
return entity;
}
public void delete(T entity) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
session.delete(entity);
}
public T queryEntity(String hql, Object[] params) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
Query query = session.createQuery(hql);
query.setMaxResults(1);
QueryHelper.bindParameters(query, params);
@@ -68,7 +74,7 @@ public class EntityDao {
}
public List queryEntities(String hql, Object[] params) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
Query query = session.createQuery(hql);
QueryHelper.bindParameters(query, params);
@@ -76,7 +82,7 @@ public class EntityDao {
}
public List queryEntities(String hql, int offset, int limit, Object[] params) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
Query query = session.createQuery(hql);
QueryHelper.bindParameters(query, params);
query.setFirstResult(offset);
@@ -85,7 +91,7 @@ public class EntityDao {
}
public int executeUpdate(String hql, Object[] params) {
- Session session = PersistContext.getSession();
+ Session session = PersistContext.getSession(isCloudStackSession);
Query query = session.createQuery(hql);
QueryHelper.bindParameters(query, params);
diff --git a/awsapi/src/com/cloud/bridge/persist/PersistContext.java b/awsapi/src/com/cloud/bridge/persist/PersistContext.java
index 81001b32a8f..e721a1ddd2f 100644
--- a/awsapi/src/com/cloud/bridge/persist/PersistContext.java
+++ b/awsapi/src/com/cloud/bridge/persist/PersistContext.java
@@ -28,6 +28,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction;
import com.cloud.bridge.util.CloudSessionFactory;
+import com.cloud.bridge.util.CloudStackSessionFactory;
import com.cloud.bridge.util.Tuple;
/**
@@ -48,78 +49,144 @@ public class PersistContext {
protected final static Logger logger = Logger.getLogger(PersistContext.class);
private static final CloudSessionFactory sessionFactory;
-
+
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
private static final ThreadLocal