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


Java PersistenceBroker.getClassDescriptor方法代码示例

本文整理汇总了Java中org.apache.ojb.broker.PersistenceBroker.getClassDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceBroker.getClassDescriptor方法的具体用法?Java PersistenceBroker.getClassDescriptor怎么用?Java PersistenceBroker.getClassDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ojb.broker.PersistenceBroker的用法示例。


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

示例1: buildObjectImage

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * buildObjectImage() will return the image of the Object.
 */
private Map buildObjectImage(PersistenceBroker broker) throws PersistenceBrokerException
{
    Map imageMap = new HashMap();
    ClassDescriptor cld = broker.getClassDescriptor(getObject().getClass());
    //System.out.println("++++ build image: " + getObject());
    // register 1:1 references in image
    buildImageForSingleReferences(imageMap, cld);
    // put object values to image map
    buildImageForFields(imageMap, cld);
    // register 1:n and m:n references in image
    buildImageForCollectionReferences(imageMap, cld);
    return imageMap;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:17,代码来源:ObjectEnvelope.java

示例2: write

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public Object write(PersistenceBroker broker, Object obj, Object oldObject)
{
    ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());
    // we store field values by name in a Map
    HashMap target = oldObject != null ? (HashMap) oldObject : new HashMap();
    // perform main object values
    FieldDescriptor[] flds = cld.getFieldDescriptor(true);
    FieldDescriptor fld;
    int length = flds.length;
    for(int i = 0; i < length; i++)
    {
        fld = flds[i];
        // get the value
        Object value = fld.getPersistentField().get(obj);
        // convert value to a supported sql type
        value = fld.getFieldConversion().javaToSql(value);
        // copy the sql type
        value = fld.getJdbcType().getFieldType().copy(value);
        target.put(fld.getPersistentField().getName(), value);
    }
    target.put(CLASS_NAME_STR, obj.getClass().getName());
    return target;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:24,代码来源:ObjectCacheTwoLevelImpl.java

示例3: afterStore

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * @see org.apache.ojb.broker.ManageableCollection#afterStore(PersistenceBroker broker)
 */
public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
{
    // make sure allObjectsToBeRemoved does not contain
    // any instances that got re-added to the list
    allObjectsToBeRemoved.removeAll(this);

    Iterator iter = allObjectsToBeRemoved.iterator();
    while (iter.hasNext())
    {
        Object obj = iter.next();
        ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());
        if (broker.serviceBrokerHelper().assertValidPkForDelete(cld, obj))
        {    
            broker.delete(obj);
        }    
    }
    allObjectsToBeRemoved.clear();
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:22,代码来源:RemovalAwareCollection.java

示例4: changeReferenceSetting

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void changeReferenceSetting(PersistenceBroker broker, Class clazz,
                                           String referenceField, boolean autoRetrieve,
                                           int autoUpdate, int autoDelete, boolean useProxy)
        {
            ClassDescriptor cld = broker.getClassDescriptor(clazz);
            ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
            ref = cld.getCollectionDescriptorByName(referenceField);
            if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
            if(ref == null)
            {
                throw new OJBRuntimeException("Given field " + referenceField + " does not match a reference in " + clazz);
            }

            prepareSetting(ref, cld, clazz, referenceField);

            ref.setLazy(useProxy);
            ref.setCascadeRetrieve(autoRetrieve);
            ref.setCascadingStore(autoUpdate);
            ref.setCascadingDelete(autoDelete);

//            System.out.println("old settings: " + oldRef.toXML());
//            System.out.println("new settings: " + ref.toXML());
        }
 
开发者ID:KualiCo,项目名称:ojb,代码行数:24,代码来源:OJBTestCase.java

示例5: SequenceManagerHandle

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public SequenceManagerHandle(PersistenceBroker broker, Class targetClass, int loops)
{
    this.broker = broker;
    this.targetClass = targetClass;
    this.field = broker.getClassDescriptor(targetClass).getAutoIncrementFields()[0];
    if(field == null)
    {
        String error = "No autoincrement field found for class "+targetClass+
        " using class descriptor from given broker: "+broker.getClassDescriptor(targetClass);
        throw new PersistenceBrokerException(error);
    }
    this.loops = loops;
    resultList = new ArrayList();
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:15,代码来源:SequenceManagerHandle.java

示例6: customizeQuery

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * In addition to what the referenced method does, this also fixes a mysql order by issue (see class comments)
 *
 * @see org.apache.ojb.broker.accesslayer.QueryCustomizerDefaultImpl#customizeQuery(java.lang.Object,
 *      org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
 *      org.apache.ojb.broker.query.QueryByCriteria)
 */
@Override
public Query customizeQuery(Object anObject, PersistenceBroker broker, CollectionDescriptor cod, QueryByCriteria query) {
    boolean platformMySQL = broker.serviceSqlGenerator().getPlatform() instanceof PlatformMySQLImpl;

    Map<String, String> attributes = getAttributes();
    for (String attributeName : attributes.keySet()) {
        if (!attributeName.startsWith(ORDER_BY_FIELD)) {
            continue;
        }

        String fieldName = attributeName.substring(ORDER_BY_FIELD.length());
        ClassDescriptor itemClassDescriptor = broker.getClassDescriptor(cod.getItemClass());
        FieldDescriptor orderByFieldDescriptior = itemClassDescriptor.getFieldDescriptorByName(fieldName);

        // the column to sort on derived from the property name
        String orderByColumnName = orderByFieldDescriptior.getColumnName();

        // ascending or descending
        String fieldValue = attributes.get(attributeName);
        boolean ascending = (StringUtils.equals(fieldValue, ASCENDING));
        // throw an error if not ascending or descending
        if (!ascending && StringUtils.equals(fieldValue, DESCENDING)) {
            throw new RuntimeException("neither ASC nor DESC was specified in ojb file for " + fieldName);
        }

        if (platformMySQL) {
            // by negating the column name in MySQL we can get nulls last (ascending or descending)
            String mysqlPrefix = (ascending) ? MYSQL_NEGATION : "";
            query.addOrderBy(mysqlPrefix + orderByColumnName, false);
        } else {
            query.addOrderBy(orderByColumnName, ascending);
        }
    }
    return query;
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:43,代码来源:PurapItemQueryCustomizer.java

示例7: selectClassDescriptor

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException {
    String[] key = new String[column.length];

    for (int i = 0; i < column.length; i++) {
        key[i] = (String) row.get(column[i]);
    }

    Class clazz = null;

    if (key != null) {
        clazz = chooseClass(key);
    }
    if (clazz == null) {
        return getClassDescriptor();
    }

    PersistenceBroker broker = null;
    try {
        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        ClassDescriptor result = broker.getClassDescriptor(clazz);
        broker.close();
        if (result == null) {
            return getClassDescriptor();
        }
        else {
            return result;
        }
    }
    catch (PersistenceBrokerException e) {
        broker.close();
        throw e;
    }
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:34,代码来源:PolymorphicMultiColumnDiscriminator.java

示例8: getIsolationLevel

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 *
 * Fetches the isolation level of given class from its ClassDescriptor.
 *
 */
public static TransactionIsolation getIsolationLevel (PersistenceBroker pb,
                                                      ObjectLock lock)
{
    /*
    arminw: use real object class instead of top-level class
    to match isolation level of given class
    */
    // Class clazz = lock.getTargetIdentity().getObjectsTopLevelClass();
    Class clazz = lock.getTargetIdentity().getObjectsRealClass();
    ClassDescriptor classDescriptor = pb.getClassDescriptor(clazz);
    int isolationLevel = classDescriptor.getIsolationLevel();

    TransactionIsolation isolation = null;
    switch (isolationLevel) {

        case IsolationLevels.IL_READ_UNCOMMITTED:
            isolation = READ_UNCOMMITTED_ISOLATION;
            break;

        case IsolationLevels.IL_READ_COMMITTED:
            isolation = READ_COMMITTED_ISOLATION;
            break;

        case IsolationLevels.IL_REPEATABLE_READ:
            isolation = REPEATABLE_READ_ISOLATION;
            break;

        case IsolationLevels.IL_SERIALIZABLE:
            isolation = SERIALIZABLE_ISOLATION;
            break;

        default:
            throw new UnknownIsolationException(
                "Isolation level " + isolationLevel + " is not supported");
    }

    return isolation;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:44,代码来源:IsolationFactory.java

示例9: getPkCriteriaForAllElements

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
private Criteria getPkCriteriaForAllElements(PersistenceBroker broker)
{
    try
    {
        Criteria crit = null;
        for (int i = 0; i < elements.size(); i++)
        {
            DListEntry entry = (DListEntry) elements.get(i);
            Object obj = entry.getRealSubject();
            ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());

            FieldDescriptor[] pkFields = cld.getPkFields();
            ValueContainer[] pkValues = broker.serviceBrokerHelper().getKeyValues(cld, obj);

            Criteria criteria = new Criteria();
            for (int j = 0; j < pkFields.length; j++)
            {
                FieldDescriptor fld = pkFields[j];
                criteria.addEqualTo(fld.getPersistentField().getName(), pkValues[j].getValue());
            }

            if (crit == null)
                crit = criteria;
            else
                crit.addOrCriteria(criteria);
        }
        return crit;
    }
    catch (PersistenceBrokerException e)
    {
        log.error(e);
        return null;
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:35,代码来源:DSetImpl.java

示例10: getPkCriteriaForAllElements

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
private Criteria getPkCriteriaForAllElements(PersistenceBroker brokerForClass)
{
    try
    {
        Criteria crit = null;
        for (int i = 0; i < elements.size(); i++)
        {
            DListEntry entry = (DListEntry) elements.get(i);
            Object obj = entry.getRealSubject();
            ClassDescriptor cld = brokerForClass.getClassDescriptor(obj.getClass());

            FieldDescriptor[] pkFields = cld.getPkFields();
            ValueContainer[] pkValues = brokerForClass.serviceBrokerHelper().getKeyValues(cld, obj);

            Criteria criteria = new Criteria();
            for (int j = 0; j < pkFields.length; j++)
            {
                FieldDescriptor fld = pkFields[j];
                criteria.addEqualTo(fld.getPersistentField().getName(), pkValues[j].getValue());
            }

            if (crit == null)
                crit = criteria;
            else
                crit.addOrCriteria(criteria);
        }
        return crit;
    }
    catch (PersistenceBrokerException e)
    {
        return null;
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:34,代码来源:DListImpl.java

示例11: customizeQuery

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * In addition to what the referenced method does, this also fixes a mysql order by issue (see class comments)
 * @see org.apache.ojb.broker.accesslayer.QueryCustomizerDefaultImpl#customizeQuery(java.lang.Object,
 *      org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
 *      org.apache.ojb.broker.query.QueryByCriteria)
 */
@Override
public Query customizeQuery(Object anObject, PersistenceBroker broker, CollectionDescriptor cod, QueryByCriteria query) {
    boolean platformMySQL = broker.serviceSqlGenerator().getPlatform() instanceof PlatformMySQLImpl;

    Map<String, String> attributes = getAttributes();
    for (String attributeName : attributes.keySet()) {
        if (!attributeName.startsWith(ORDER_BY_FIELD)) {
            continue;
        }

        String fieldName = attributeName.substring(ORDER_BY_FIELD.length());
        ClassDescriptor itemClassDescriptor = broker.getClassDescriptor(cod.getItemClass());
        FieldDescriptor orderByFieldDescriptior = itemClassDescriptor.getFieldDescriptorByName(fieldName);

        // the column to sort on derived from the property name
        String orderByColumnName = orderByFieldDescriptior.getColumnName();

        // ascending or descending
        String fieldValue = attributes.get(attributeName);
        boolean ascending = (StringUtils.equals(fieldValue, ASCENDING));
        // throw an error if not ascending or descending
        if (!ascending && StringUtils.equals(fieldValue, DESCENDING)) {
            throw new RuntimeException("neither ASC nor DESC was specified in ojb file for " + fieldName);
        }

        if (platformMySQL) {
            // by negating the column name in MySQL we can get nulls last (ascending or descending)
            String mysqlPrefix = (ascending) ? MYSQL_NEGATION : "";
            query.addOrderBy(mysqlPrefix + orderByColumnName, false);
        }
        else {
            query.addOrderBy(orderByColumnName, ascending);
        }
    }
    return query;
}
 
开发者ID:kuali,项目名称:kfs,代码行数:43,代码来源:PurapItemQueryCustomizer.java

示例12: isTransient

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * Detect new objects.
 */
protected boolean isTransient(ClassDescriptor cld, Object obj, Identity oid)
{
    // if the Identity is transient we assume a non-persistent object
    boolean isNew = oid != null && oid.isTransient();
    /*
    detection of new objects is costly (select of ID in DB to check if object
    already exists) we do:
    a. check if the object has nullified PK field
    b. check if the object is already registered
    c. lookup from cache and if not found, last option select on DB
    */
    if(!isNew)
    {
        final PersistenceBroker pb = getBroker();
        if(cld == null)
        {
            cld = pb.getClassDescriptor(obj.getClass());
        }
        isNew = pb.serviceBrokerHelper().hasNullPKField(cld, obj);
        if(!isNew)
        {
            if(oid == null)
            {
                oid = pb.serviceIdentity().buildIdentity(cld, obj);
            }
            final ObjectEnvelope mod = objectEnvelopeTable.getByIdentity(oid);
            if(mod != null)
            {
                // already registered object, use current state
                isNew = mod.needsInsert();
            }
            else
            {
                // if object was found cache, assume it's old
                // else make costly check against the DB
                isNew = pb.serviceObjectCache().lookup(oid) == null
                        && !pb.serviceBrokerHelper().doesExist(cld, oid, obj);
            }
        }
    }
    return isNew;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:46,代码来源:TransactionImpl.java

示例13: bind

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void bind(Object object, String name) throws ObjectNameNotUniqueException
{
    boolean useIdentity = true;
    PersistenceBroker broker = tx.getBroker();
    ClassDescriptor cld = null;
    try
    {
        cld = broker.getClassDescriptor(ProxyHelper.getRealClass(object));
    }
    catch(PersistenceBrokerException e)
    {
    }

    // if null a non-persistent capable object was specified
    if(cld == null)
    {
        useIdentity = false;
        if(!(object instanceof Serializable))
        {
            throw new ClassNotPersistenceCapableException(
                    "Can't bind named object, because it's not Serializable. Name=" + name + ", object=" + object);
        }
    }
    else
    {
        RuntimeObject rt = new RuntimeObject(object, tx);
        // if the object is already persistet, check for read
        // lock to make sure
        // that the used object is a valid version
        // else persist the specified named object
        if(!rt.isNew())
        {
            tx.lockAndRegister(rt, Transaction.READ, tx.getRegistrationList());
        }
        else
        {
            tx.makePersistent(rt);
        }
    }
    NamedEntry oldEntry = localLookup(name);
    if(oldEntry == null)
    {
        Identity oid = broker.serviceIdentity().buildIdentity(NamedEntry.class, name);
        oldEntry = (NamedEntry) broker.getObjectByIdentity(oid);
    }
    if(oldEntry != null)
    {
        throw new ObjectNameNotUniqueException("The name of the specified named object already exist, name=" + name);
    }

    NamedEntry entry = new NamedEntry(name, object, useIdentity);
    addForInsert(entry);
    localBind(name, entry);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:55,代码来源:NamedRootsMap.java

示例14: getMaxId

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * Search down all extent classes and return max of all found
 * PK values.
 */
public static long getMaxId(PersistenceBroker brokerForClass, Class topLevel, FieldDescriptor original) throws PersistenceBrokerException
{
    long max = 0;
    long tmp;
    ClassDescriptor cld = brokerForClass.getClassDescriptor(topLevel);

    // if class is not an interface / not abstract we have to search its directly mapped table
    if (!cld.isInterface() && !cld.isAbstract())
    {
        tmp = getMaxIdForClass(brokerForClass, cld, original);
        if (tmp > max)
        {
            max = tmp;
        }
    }
    // if class is an extent we have to search through its subclasses
    if (cld.isExtent())
    {
        Vector extentClasses = cld.getExtentClasses();
        for (int i = 0; i < extentClasses.size(); i++)
        {
            Class extentClass = (Class) extentClasses.get(i);
            if (cld.getClassOfObject().equals(extentClass))
            {
                throw new PersistenceBrokerException("Circular extent in " + extentClass +
                        ", please check the repository");
            }
            else
            {
                // fix by Mark Rowell
                // Call recursive
                tmp = getMaxId(brokerForClass, extentClass, original);
            }
            if (tmp > max)
            {
                max = tmp;
            }
        }
    }
    return max;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:46,代码来源:SequenceManagerHelper.java

示例15: YYYtestBrokerCrash

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**try to crash odmg and broker tx*/
public void YYYtestBrokerCrash()
{
    // get facade instance
    Implementation odmg = OJB.getInstance();
    Database db = odmg.newDatabase();
    PersistenceBroker broker = null;
    ClassDescriptor cld = null;
    String tablename = null;

    //open database
    try
    {
        db.open(databaseName, Database.OPEN_READ_WRITE);
    }
    catch (ODMGException ex)
    {
        fail("ODMGException: " + ex.getMessage());
    }
    try
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();

        // retrieve an Article
        OQLQuery query = odmg.newOQLQuery();
        query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
        query.bind(new Integer(30));
        List results = (List) query.execute();
        Article a = (Article) results.get(0);

        // manipulate metadata
        broker = ((TransactionImpl) tx).getBroker();
        cld = broker.getClassDescriptor(Article.class);
        tablename = cld.getFullTableName();
        cld.setTableName("ELVIS");
        broker.getDescriptorRepository().setClassDescriptor(cld);

        //broker will crash as metadata is corrupt
        a.addToStock(5);
        tx.commit();
        fail("Can commit tx with corrupt metadata");
    }
    catch (Throwable t)
    {
        //ignore
    }
    finally
    {
        cld.setTableName(tablename);
        broker.getDescriptorRepository().setClassDescriptor(cld);
    }

}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:55,代码来源:OdmgExamples.java


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