当前位置: 首页>>代码示例>>Java>>正文


Java ProxyHelper类代码示例

本文整理汇总了Java中org.apache.ojb.broker.core.proxy.ProxyHelper的典型用法代码示例。如果您正苦于以下问题:Java ProxyHelper类的具体用法?Java ProxyHelper怎么用?Java ProxyHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProxyHelper类属于org.apache.ojb.broker.core.proxy包,在下文中一共展示了ProxyHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: materializeUpdateableCollections

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * This method checks for updateable collections on the business object provided and materializes the corresponding
 * collection proxies
 *
 * @param bo The business object for which you want unpdateable, proxied collections materialized
 * @throws FormatException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * 
 * @deprecated Replaced by {@link DataObjectWrapper#materializeReferencedObjects(org.kuali.rice.krad.data.MaterializeOption...)}
 */
@Deprecated
public static void materializeUpdateableCollections(
        Object bo) throws FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (isNotNull(bo)) {
        PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(bo.getClass());
        for (int i = 0; i < propertyDescriptors.length; i++) {
            if (KNSServiceLocator.getPersistenceStructureService().hasCollection(bo.getClass(),
                    propertyDescriptors[i].getName()) && KNSServiceLocator.getPersistenceStructureService()
                    .isCollectionUpdatable(bo.getClass(), propertyDescriptors[i].getName())) {
                Collection updateableCollection = (Collection) getPropertyValue(bo,
                        propertyDescriptors[i].getName());
                if ((updateableCollection != null) && ProxyHelper.isCollectionProxy(updateableCollection)) {
                    materializeObjects(updateableCollection);
                }
            }
        }
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:31,代码来源:ObjectUtils.java

示例2: isNull

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * This method is a OJB Proxy-safe way to test for null on a proxied object that may or may not be materialized yet.
 * It is safe
 * to use on a proxy (materialized or non-materialized) or on a non-proxy (ie, regular object). Note that this will
 * force a
 * materialization of the proxy if the object is a proxy and unmaterialized.
 *
 * @param object - any object, proxied or not, materialized or not
 * @return true if the object (or underlying materialized object) is null, false otherwise
 */
public static boolean isNull(Object object) {

    // regardless, if its null, then its null
    if (object == null) {
        return true;
    }

    // only try to materialize the object to see if its null if this is a
    // proxy object
    if (ProxyHelper.isProxy(object) || ProxyHelper.isCollectionProxy(object)) {
        if (ProxyHelper.getRealObject(object) == null) {
            return true;
        }
    }

    // JPA does not provide a way to determine if an object is a proxy, instead we invoke
    // the equals method and catch an EntityNotFoundException
    try {
        object.equals(null);
    } catch (EntityNotFoundException e) {
        return true;
    }

    return false;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:36,代码来源:ObjectUtils.java

示例3: materializeClassForProxiedObject

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
     * Attempts to find the Class for the given potentially proxied object
     *
     * @param object the potentially proxied object to find the Class of
     * @return the best Class which could be found for the given object
     */
    public static Class materializeClassForProxiedObject(Object object) {
        if (object == null) {
            return null;
        }

//        if (object instanceof HibernateProxy) {
//            final Class realClass = ((HibernateProxy) object).getHibernateLazyInitializer().getPersistentClass();
//            return realClass;
//        }

        if (ProxyHelper.isProxy(object) || ProxyHelper.isCollectionProxy(object)) {
            return ProxyHelper.getRealClass(object);
        }

        return object.getClass();
    }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:23,代码来源:ObjectUtils.java

示例4: getObjectByIdentity

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * @see org.apache.ojb.otm.OTMConnection#getObjectByIdentity(Identity, int)
 */
public Object getObjectByIdentity(Identity oid, int lock) throws LockingException
{
    checkTransaction("getObjectByIdentity");
    Object userObject;
    Object cacheObject;

    cacheObject = _pb.getObjectByIdentity(oid);
    if (cacheObject == null)
    {
        // Possibly the object was inserted in this transaction
        // and was not stored to database yet
        userObject = _editingContext.lookup(oid);
    }
    else
    {
        userObject = getUserObject(oid, cacheObject);
        // userObject from editing context may be proxy
        userObject = ProxyHelper.getRealObject(userObject);
        _editingContext.insert(oid, userObject, lock);
    }
    return userObject;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:26,代码来源:BaseConnection.java

示例5: lockAndRegisterReferences

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * we only use the registrationList map if the object is not a proxy. During the
 * reference locking, we will materialize objects and they will enter the registered for
 * lock map.
 */
private void lockAndRegisterReferences(ClassDescriptor cld, Object sourceObject, int lockMode, List registeredObjects) throws LockNotGrantedException
{
    if (implicitLocking)
    {
        Iterator i = cld.getObjectReferenceDescriptors(true).iterator();
        while (i.hasNext())
        {
            ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
            Object refObj = rds.getPersistentField().get(sourceObject);
            if (refObj != null)
            {
                boolean isProxy = ProxyHelper.isProxy(refObj);
                RuntimeObject rt = isProxy ? new RuntimeObject(refObj, this, false) : new RuntimeObject(refObj, this);
                if (!registrationList.contains(rt.getIdentity()))
                {
                    lockAndRegister(rt, lockMode, registeredObjects);
                }
            }
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:27,代码来源:TransactionImpl.java

示例6: afterLoading

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * Remove colProxy from list of pending collections and
 * register its contents with the transaction.
 */
public void afterLoading(CollectionProxyDefaultImpl colProxy)
{
    if (log.isDebugEnabled()) log.debug("loading a proxied collection a collection: " + colProxy);
    Collection data = colProxy.getData();
    for (Iterator iterator = data.iterator(); iterator.hasNext();)
    {
        Object o = iterator.next();
        if(!isOpen())
        {
            log.error("Collection proxy materialization outside of a running tx, obj=" + o);
            try{throw new Exception("Collection proxy materialization outside of a running tx, obj=" + o);}
            catch(Exception e)
            {e.printStackTrace();}
        }
        else
        {
            Identity oid = getBroker().serviceIdentity().buildIdentity(o);
            ClassDescriptor cld = getBroker().getClassDescriptor(ProxyHelper.getRealClass(o));
            RuntimeObject rt = new RuntimeObject(o, oid, cld, false, ProxyHelper.isProxy(o));
            lockAndRegister(rt, Transaction.READ, isImplicitLocking(), getRegistrationList());
        }
    }
    unregisterFromCollectionProxy(colProxy);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:29,代码来源:TransactionImpl.java

示例7: ObjectEnvelope

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * Create a wrapper by providing an Object.
 */
public ObjectEnvelope(ObjectEnvelopeTable buffer, Identity oid, Object obj, boolean isNewObject)
{
    this.linkEntryList = new ArrayList();
    this.buffer = buffer;
    this.oid = oid;
    // TODO: do we really need to materialize??
    myObj = ProxyHelper.getRealObject(obj);
    prepareInitialState(isNewObject);
    /*
    TODO: is it possible to improve this? Take care that "new"
    objects should support "persistence by reachability" too
    (detection of new/persistent reference objects after maon object lock)
    */
    beforeImage = buildObjectImage(getBroker());
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:19,代码来源:ObjectEnvelope.java

示例8: initCld

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
private void initCld(final TransactionImpl tx)
{
    final IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
    if(handler != null)
    {
        this.handler = handler;
        isNew = Boolean.FALSE;
        identity = handler.getIdentity();
        if(handler.alreadyMaterialized())
        {
            cld = tx.getBroker().getClassDescriptor(handler.getRealSubject().getClass());
        }
        else
        {
            cld = tx.getBroker().getClassDescriptor(identity.getObjectsRealClass());
        }
    }
    else
    {
        cld = tx.getBroker().getClassDescriptor(obj.getClass());
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:RuntimeObject.java

示例9: cleanup

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
public void cleanup(boolean reuse)
{
    if(log.isDebugEnabled()) log.debug("Cleanup collection image, reuse=" + reuse);
    if(reuse)
    {
        isRefreshed = false;
    }
    else
    {
        if(status == IS_UNMATERIALIZED_PROXY)
        {
            CollectionProxy colProxy = ProxyHelper.getCollectionProxy(collectionOrArray);
            if(colProxy != null)
            {
                colProxy.removeListener(this);
            }
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:20,代码来源:Image.java

示例10: getIsolationLevel

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * determines the isolationlevel of class c by evaluating
 * the ClassDescriptor of obj.getClass().
 *
 * @return int the isolationlevel
 */
public static int getIsolationLevel(Object obj)
{
    Class c = ProxyHelper.getRealClass(obj);
    int isolationLevel = IsolationLevels.IL_READ_UNCOMMITTED;

    try
    {
        ClassDescriptor cld = TxManagerFactory.instance().getCurrentTransaction().getBroker().getClassDescriptor(c);
        isolationLevel = cld.getIsolationLevel();
    }
    catch (PersistenceBrokerException e)
    {
        LoggerFactory.getDefaultLogger().error("[LockStrategyFactory] Can't detect locking isolation level", e);
    }
    return isolationLevel;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:LockStrategyFactory.java

示例11: getForeignKeyValues

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * Returns an Object array of all FK field values of the specified object.
 * If the specified object is an unmaterialized Proxy, it will be materialized
 * to read the FK values.
 *
 * @throws MetadataException if an error occours while accessing ForeingKey values on obj
 */
public Object[] getForeignKeyValues(Object obj, ClassDescriptor mif)
        throws PersistenceBrokerException
{
    FieldDescriptor[] fks = getForeignKeyFieldDescriptors(mif);
    // materialize object only if FK fields are declared
    if(fks.length > 0) obj = ProxyHelper.getRealObject(obj);
    Object[] result = new Object[fks.length];
    for (int i = 0; i < result.length; i++)
    {
        FieldDescriptor fmd = fks[i];
        PersistentField f = fmd.getPersistentField();

        // BRJ: do NOT convert.
        // conversion is done when binding the sql-statement
        //
        // FieldConversion fc = fmd.getFieldConversion();
        // Object val = fc.javaToSql(f.get(obj));

        result[i] = f.get(obj);
    }
    return result;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:30,代码来源:ObjectReferenceDescriptor.java

示例12: getValueFrom

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
private Object getValueFrom(PropertyDescriptor pd, Object target)
{
    if (target == null) return null;
    Method m = pd.getReadMethod();
    if (m != null)
    {
        try
        {
            return m.invoke(ProxyHelper.getRealObject(target), null);
        }
        catch (Throwable e)
        {
            logProblem(pd, target, null, "Can't read value from given object");
            throw new MetadataException("Error invoking method:" + m.getName() + " in object " + target.getClass().getName(), e);
        }
    }
    else
    {
        throw new MetadataException("Can't get ReadMethod for property:" + pd.getName() + " in object " + target.getClass().getName());
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:22,代码来源:PersistentFieldIntrospectorImpl.java

示例13: getRealClassDescriptor

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * Answer the real ClassDescriptor for anObj
 * ie. aCld may be an Interface of anObj, so the cld for anObj is returned
 */
private ClassDescriptor getRealClassDescriptor(ClassDescriptor aCld, Object anObj)
{
    ClassDescriptor result;

    if(aCld.getClassOfObject() == ProxyHelper.getRealClass(anObj))
    {
        result = aCld;
    }
    else
    {
        result = aCld.getRepository().getDescriptorFor(anObj.getClass());
    }

    return result;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:20,代码来源:BrokerHelper.java

示例14: hasNullPKField

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * Detect if the given object has a PK field represents a 'null' value.
 */
public boolean hasNullPKField(ClassDescriptor cld, Object obj)
{
    FieldDescriptor[] fields = cld.getPkFields();
    boolean hasNull = false;
    // an unmaterialized proxy object can never have nullified PK's
    IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
    if(handler == null || handler.alreadyMaterialized())
    {
        if(handler != null) obj = handler.getRealSubject();
        FieldDescriptor fld;
        for(int i = 0; i < fields.length; i++)
        {
            fld = fields[i];
            hasNull = representsNull(fld, fld.getPersistentField().get(obj));
            if(hasNull) break;
        }
    }
    return hasNull;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:BrokerHelper.java

示例15: assertValidPkForDelete

import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入依赖的package包/类
/**
 * returns true if the primary key fields are valid for delete, else false.
 * PK fields are valid if each of them contains a valid non-null value
 * @param cld the ClassDescriptor
 * @param obj the object
 * @return boolean
 */
public boolean assertValidPkForDelete(ClassDescriptor cld, Object obj)
{
    if(!ProxyHelper.isProxy(obj))
    {
        FieldDescriptor fieldDescriptors[] = cld.getPkFields();
        int fieldDescriptorSize = fieldDescriptors.length;
        for(int i = 0; i < fieldDescriptorSize; i++)
        {
            FieldDescriptor fd = fieldDescriptors[i];
            Object pkValue = fd.getPersistentField().get(obj);
            if (representsNull(fd, pkValue))
            {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:26,代码来源:BrokerHelper.java


注:本文中的org.apache.ojb.broker.core.proxy.ProxyHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。