incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [1/2] CLOUDSTACK-1339: Using Sping interface injection pattern to avoid using CGLIB proxying mode. Spring with CGLIB proxying will concflict with CGLIB usage in CloudStack DB code, CloudStack CGLIB usage can cause Spring to lose tack of its proxied objec
Date Sun, 24 Feb 2013 22:15:29 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4f38d745/utils/src/com/cloud/utils/db/GenericDaoBase.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java
index cf30474..afb1247 100755
--- a/utils/src/com/cloud/utils/db/GenericDaoBase.java
+++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java
@@ -68,6 +68,7 @@ import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.Ternary;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ComponentLifecycle;
 import com.cloud.utils.component.ComponentLifecycleBase;
 import com.cloud.utils.crypt.DBEncryptionUtil;
@@ -118,7 +119,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
 
     protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT");
 
-    protected final static Map<Class<?>, GenericDaoBase<?, ? extends Serializable>>
s_daoMaps = new ConcurrentHashMap<Class<?>, GenericDaoBase<?, ? extends Serializable>>(71);
+    protected final static Map<Class<?>, GenericDao<?, ? extends Serializable>>
s_daoMaps = new ConcurrentHashMap<Class<?>, GenericDao<?, ? extends Serializable>>(71);
 
     protected Class<T> _entityBeanType;
     protected String _table;
@@ -128,8 +129,8 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
     protected Field[] _embeddedFields;
 
     // This is private on purpose.  Everyone should use createPartialSelectSql()
-    private final Pair<StringBuilder, Attribute[]> _partialSelectSql;
-    private final Pair<StringBuilder, Attribute[]> _partialQueryCacheSelectSql;
+    private Pair<StringBuilder, Attribute[]> _partialSelectSql;
+    private Pair<StringBuilder, Attribute[]> _partialQueryCacheSelectSql;
     protected StringBuilder _discriminatorClause;
     protected Map<String, Object> _discriminatorValues;
     protected String _selectByIdSql;
@@ -141,11 +142,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
     protected Pair<String, Attribute> _removed;
     protected Pair<String, Attribute[]> _removeSql;
     protected List<Pair<String, Attribute[]>> _deleteSqls;
-    protected final Map<String, Attribute[]> _idAttributes;
-    protected final Map<String, TableGenerator> _tgs;
-    protected final Map<String, Attribute> _allAttributes;
-    protected final List<Attribute> _ecAttributes;
-    protected final Map<Pair<String, String>, Attribute> _allColumns;
+    protected Map<String, Attribute[]> _idAttributes;
+    protected Map<String, TableGenerator> _tgs;
+    protected Map<String, Attribute> _allAttributes;
+    protected List<Attribute> _ecAttributes;
+    protected Map<Pair<String, String>, Attribute> _allColumns;
     protected Enhancer _enhancer;
     protected Factory _factory;
     protected Enhancer _searchEnhancer;
@@ -159,9 +160,9 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
 
     protected static final SequenceFetcher s_seqFetcher = SequenceFetcher.getInstance();
 
-    public static <J> GenericDaoBase<? extends J, ? extends Serializable> getDao(Class<J>
entityType) {
+    public static <J> GenericDao<? extends J, ? extends Serializable> getDao(Class<J>
entityType) {
         @SuppressWarnings("unchecked")
-        GenericDaoBase<? extends J, ? extends Serializable> dao = (GenericDaoBase<?
extends J, ? extends Serializable>)s_daoMaps.get(entityType);
+        GenericDao<? extends J, ? extends Serializable> dao = (GenericDao<? extends
J, ? extends Serializable>)s_daoMaps.get(entityType);
         assert dao != null : "Unable to find DAO for " + entityType + ".  Are you sure you
waited for the DAO to be initialized before asking for it?";
         return dao;
     }
@@ -192,13 +193,15 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
                     ( (Class<?>)((Class<?>)t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0];
         }
 
-        s_daoMaps.put(_entityBeanType, this);
+/*        
+        s_daoMaps.put(_entityBeanType, ComponentContext.getComponent(this.getClass()));
         Class<?>[] interphaces = _entityBeanType.getInterfaces();
         if (interphaces != null) {
             for (Class<?> interphace : interphaces) {
-                s_daoMaps.put(interphace, this);
+                s_daoMaps.put(interphace, ComponentContext.getComponent(this.getClass()));
             }
         }
+*/  
         _table = DbUtil.getTableName(_entityBeanType);
 
         final SqlGenerator generator = new SqlGenerator(_entityBeanType);
@@ -1747,6 +1750,25 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
     public boolean configure(final String name, final Map<String, Object> params) throws
ConfigurationException {
         _name = name;
 
+        Class<?> daoInterface = null;
+        for(Class<?> intf : this.getClass().getInterfaces()) {
+        	if(GenericDao.class.isAssignableFrom(intf)) {
+        		daoInterface = intf;
+        		break;
+        	}
+        }
+ 
+        if(daoInterface != null) {
+        	s_logger.info("Register dao interface in GenericDaoBase entity-DAO map. " + daoInterface.getName());
+	        s_daoMaps.put(_entityBeanType, (GenericDao<?, ? extends Serializable>) ComponentContext.getComponent(daoInterface));
+	        Class<?>[] interphaces = _entityBeanType.getInterfaces();
+	        if (interphaces != null) {
+	            for (Class<?> interphace : interphaces) {
+	                s_daoMaps.put(interphace,  (GenericDao<?, ? extends Serializable>)
ComponentContext.getComponent(daoInterface));
+	            }
+	        }
+	    }
+       
         final String value = (String)params.get("lock.timeout");
         _timeoutSeconds = NumbersUtil.parseInt(value, 300);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4f38d745/utils/src/com/cloud/utils/db/QueryBuilder.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/QueryBuilder.java b/utils/src/com/cloud/utils/db/QueryBuilder.java
index 2eb3658..3303fbd 100644
--- a/utils/src/com/cloud/utils/db/QueryBuilder.java
+++ b/utils/src/com/cloud/utils/db/QueryBuilder.java
@@ -56,21 +56,21 @@ public class QueryBuilder<S, T> implements MethodInterceptor, SimpleQueryBuilder
         }
     }
     
-    protected HashMap<Class<?>, Pair<GenericDaoBase<?,?>, Object>>
_entities;
+    protected HashMap<Class<?>, Pair<GenericDao<?,?>, Object>> _entities;
     protected ArrayList<Attribute> _specifiedAttrs = new ArrayList<Attribute>();
     protected T _resultSetClass;
     protected ArrayList<Select<S, T>> _selects;
     
     public QueryBuilder(Class<T> resultSetClass, Class<?>... clazzes) {
-        _entities = new HashMap<Class<?>, Pair<GenericDaoBase<?,?>, Object>>(clazzes.length);
+        _entities = new HashMap<Class<?>, Pair<GenericDao<?,?>, Object>>(clazzes.length);
         for (Class<?> clazz : clazzes) {
-            GenericDaoBase<?,?> dao = GenericDaoBase.getDao(clazz);
+            GenericDao<?,?> dao = GenericDaoBase.getDao(clazz);
             Enhancer searchEnhancer = new Enhancer();
             searchEnhancer.setSuperclass(clazz);
             searchEnhancer.setCallback(this);
             Object entity = searchEnhancer.create();
             
-            _entities.put(clazz, new Pair<GenericDaoBase<?, ?>, Object>(dao,
entity));
+            _entities.put(clazz, new Pair<GenericDao<?, ?>, Object>(dao, entity));
         }
     }
     
@@ -86,14 +86,14 @@ public class QueryBuilder<S, T> implements MethodInterceptor, SimpleQueryBuilder
      * @param resultSetClass result class to put the result set in.
      */
     public QueryBuilder(Class<S> entityClass, Class<T> resultSetClass) {
-        _entities = new HashMap<Class<?>, Pair<GenericDaoBase<?,?>, Object>>(1);
-        GenericDaoBase<?,?> dao = GenericDaoBase.getDao(entityClass);
+        _entities = new HashMap<Class<?>, Pair<GenericDao<?,?>, Object>>(1);
+        GenericDao<?,?> dao = GenericDaoBase.getDao(entityClass);
         Enhancer searchEnhancer = new Enhancer();
         searchEnhancer.setSuperclass(entityClass);
         searchEnhancer.setCallback(this);
         Object entity = searchEnhancer.create();
         
-        _entities.put(entityClass, new Pair<GenericDaoBase<?, ?>, Object>(dao,
entity));
+        _entities.put(entityClass, new Pair<GenericDao<?, ?>, Object>(dao, entity));
     }
     
     @Override
@@ -114,7 +114,7 @@ public class QueryBuilder<S, T> implements MethodInterceptor, SimpleQueryBuilder
         return this;
     }
     
-    protected void set(GenericDaoBase<?, ?> dao , String name) {
+    protected void set(GenericDao<?, ?> dao , String name) {
         Attribute attr = dao.getAllAttributes().get(name);
         assert (attr != null) : "Searching for a field that's not there: " + name;
         _specifiedAttrs.add(attr);
@@ -125,9 +125,9 @@ public class QueryBuilder<S, T> implements MethodInterceptor, SimpleQueryBuilder
     public Object intercept(Object entity, Method method, Object[] args, MethodProxy proxy)
throws Throwable {
         Class<?> entityClass = entity.getClass().getSuperclass();
         
-        Pair<GenericDaoBase<?,?>, Object> daoInfo = _entities.get(entityClass);
+        Pair<GenericDao<?,?>, Object> daoInfo = _entities.get(entityClass);
         assert (daoInfo != null) : "You need to specify " + entityClass + " as one of the
entities in the Query";
-        GenericDaoBase<?,?> dao = daoInfo.first();
+        GenericDao<?,?> dao = daoInfo.first();
         
         String name = method.getName();
         if (name.startsWith("get")) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4f38d745/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
index c8a7f7a..744e75c 100644
--- a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
+++ b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
@@ -30,7 +30,7 @@ public class TransactionContextBuilder implements MethodInterceptor {
 	public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable {
 		MethodSignature methodSignature = (MethodSignature)call.getSignature();
         Method targetMethod = methodSignature.getMethod();	
-        if(needToIntercept(targetMethod)) {
+        if(true) { // TODO ??? needToIntercept(targetMethod)) {
 			Transaction txn = Transaction.open(call.getSignature().getName());
 			Object ret = null;
 			try {


Mime
View raw message