Search in sources :

Example 16 with Factory

use of net.sf.cglib.proxy.Factory in project cloudstack by apache.

the class SearchBase method finalize.

/**
     * Marks the SearchBuilder as completed in building the search conditions.
     */
@Override
protected synchronized void finalize() {
    if (_entity != null) {
        final Factory factory = (Factory) _entity;
        factory.setCallback(0, null);
        _entity = null;
    }
    if (_joins != null) {
        for (final JoinBuilder<SearchBase<?, ?, ?>> join : _joins.values()) {
            join.getT().finalize();
        }
    }
    if (_selects == null || _selects.size() == 0) {
        _selectType = SelectType.Entity;
        assert _entityBeanType.equals(_resultType) : "Expecting " + _entityBeanType + " because you didn't specify any selects but instead got " + _resultType;
        return;
    }
    for (final Select select : _selects) {
        if (select.field == null) {
            assert (_selects.size() == 1) : "You didn't specify any fields to put the result in but you're specifying more than one select so where should I put the selects?";
            _selectType = SelectType.Single;
            return;
        }
        if (select.func != null) {
            _selectType = SelectType.Result;
            return;
        }
    }
    _selectType = SelectType.Fields;
}
Also used : Factory(net.sf.cglib.proxy.Factory)

Example 17 with Factory

use of net.sf.cglib.proxy.Factory in project cloudstack by apache.

the class AsyncCallbackDispatcher method getTarget.

@SuppressWarnings("unchecked")
public T getTarget() {
    Class<?> clz = _targetObject.getClass();
    String clzName = clz.getName();
    if (clzName.contains("EnhancerByCloudStack"))
        clz = clz.getSuperclass();
    Enhancer en = null;
    synchronized (enMap) {
        en = enMap.get(clz);
        if (en == null) {
            en = new Enhancer();
            en.setSuperclass(clz);
            en.setCallback(new MethodInterceptor() {

                @Override
                public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
                    return null;
                }
            });
            enMap.put(clz, en);
        }
    }
    try {
        T t = (T) en.create();
        Factory factory = (Factory) t;
        factory.setCallback(0, new MethodInterceptor() {

            @Override
            public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
                if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize")) {
                    return null;
                } else {
                    _callbackMethod = arg1;
                    _callbackMethod.setAccessible(true);
                    return null;
                }
            }
        });
        return t;
    } catch (Throwable e) {
        s_logger.error("Unexpected exception", e);
    }
    return null;
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) Enhancer(net.sf.cglib.proxy.Enhancer) MethodProxy(net.sf.cglib.proxy.MethodProxy) Factory(net.sf.cglib.proxy.Factory) Method(java.lang.reflect.Method)

Aggregations

Factory (net.sf.cglib.proxy.Factory)17 Test (org.junit.Test)5 AttributeOverride (javax.persistence.AttributeOverride)4 Method (java.lang.reflect.Method)2 Enhancer (net.sf.cglib.proxy.Enhancer)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)1 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)1 Select (com.cloud.utils.db.GenericSearchBuilder.Select)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 AnnotationInfo (com.spaceprogram.simplejpa.AnnotationInfo)1 LazyInterceptor (com.spaceprogram.simplejpa.LazyInterceptor)1 PersistentProperty (com.spaceprogram.simplejpa.PersistentProperty)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1