Package org.apache.ojb.broker.metadata

Examples of org.apache.ojb.broker.metadata.ClassDescriptor


    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)
View Full Code Here


            Object cacheObject, int lock, Stack stack, boolean buildingObject)
            throws LockingException
    {
        ContextEntry entry;
        boolean onlyDependants = !_tx.getKit().isImplicitLockingUsed();
        ClassDescriptor mif = _pb.getClassDescriptor(userObject.getClass());

        // N:1 relations
        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
        ObjectReferenceDescriptor rds = null;
        PersistentField f;
        Object relUserObj;
        Identity relOid;
        boolean isDependent;

        while (iter.hasNext())
        {
            rds = (ObjectReferenceDescriptor) iter.next();
            isDependent = rds.getOtmDependent();
            if (onlyDependants && !isDependent)
            {
                continue;
            }
            f = rds.getPersistentField();
            relUserObj = f.get(userObject);
            if (relUserObj != null)
            {
                relOid = new Identity(relUserObj, _pb);
                entry = (ContextEntry) _objects.get(relOid);
                if ((entry == null) || (entry.userObject != relUserObj))
                {
                    entry = insertInternal(relOid, relUserObj, lock, isDependent,
                                           oid, stack);
                    if (buildingObject && (entry != null))
                    {
                        f.set(userObject, entry.userObject);
                        f.set(cacheObject, entry.cacheObject);
                    }
                }
            }
        }

        // 1:N relations
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor cds;
        Object userCol;
        Iterator userColIterator;
        Class type;
        ArrayList newUserCol = null;
View Full Code Here

     * if "withObjects" parameter is "false", then returns nulls
     * in places of 3) and 4)
     */
    private Object[][] getFields(Object obj, boolean withObjects, boolean addListeners)
    {
        ClassDescriptor mif = _pb.getClassDescriptor(obj.getClass());
        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
        Collection refDescs = mif.getObjectReferenceDescriptors();
        Collection colDescs = mif.getCollectionDescriptors();
        int count = 0;
        Object[] fields = new Object[1 + fieldDescs.length + refDescs.size()];
        ArrayList[] collections = new ArrayList[colDescs.size()];
        Object[] references = null;
        ArrayList[] collectionsOfObjects = null;
View Full Code Here

        return new Object[][] {fields, collections, references, collectionsOfObjects};
    }

    private void setFields(Object obj, Object[][] fieldsAndCollections)
    {
        ClassDescriptor mif = _pb.getClassDescriptor(obj.getClass());
        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
        Collection refDescs = mif.getObjectReferenceDescriptors();
        Collection colDescs = mif.getCollectionDescriptors();
        Object[] fields = fieldsAndCollections[0];
        ArrayList[] collections = (ArrayList[]) fieldsAndCollections[1];
        int count = 0;

        if (!fields[0].equals(obj.getClass()))
View Full Code Here

     * Does the given class has bidirectional assiciation
     * with some other class?
     */
    private boolean hasBidirectionalAssociation(Class clazz)
    {
        ClassDescriptor cdesc;
        Collection refs;
        boolean hasBidirAssc;

        if (_withoutBidirAssc.contains(clazz))
        {
            return false;
        }

        if (_withBidirAssc.contains(clazz))
        {
            return true;
        }

        // first time we meet this class, let's look at metadata
        cdesc = _pb.getClassDescriptor(clazz);
        refs = cdesc.getObjectReferenceDescriptors();
        hasBidirAssc = false;
        REFS_CYCLE:
        for (Iterator it = refs.iterator(); it.hasNext(); )
        {
            ObjectReferenceDescriptor ord;
            ClassDescriptor relCDesc;
            Collection relRefs;

            ord = (ObjectReferenceDescriptor) it.next();
            relCDesc = _pb.getClassDescriptor(ord.getItemClass());
            relRefs = relCDesc.getObjectReferenceDescriptors();
            for (Iterator relIt = relRefs.iterator(); relIt.hasNext(); )
            {
                ObjectReferenceDescriptor relOrd;

                relOrd = (ObjectReferenceDescriptor) relIt.next();
View Full Code Here

     */
    private ArrayList handleDependentReferences(Identity oid, Object userObject,
            Object[] origFields, Object[] newFields, Object[] newRefs)
            throws LockingException
    {
        ClassDescriptor mif = _pb.getClassDescriptor(userObject.getClass());
        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
        Collection refDescs = mif.getObjectReferenceDescriptors();
        int count = 1 + fieldDescs.length;
        ArrayList newObjects = new ArrayList();
        int countRefs = 0;

        for (Iterator it = refDescs.iterator(); it.hasNext(); count++, countRefs++)
View Full Code Here

    private ArrayList handleDependentCollections(Identity oid, Object obj,
            Object[] origCollections, Object[] newCollections,
            Object[] newCollectionsOfObjects)
            throws LockingException
    {
        ClassDescriptor mif = _pb.getClassDescriptor(obj.getClass());
        Collection colDescs = mif.getCollectionDescriptors();
        ArrayList newObjects = new ArrayList();
        int count = 0;

        for (Iterator it = colDescs.iterator(); it.hasNext(); count++)
        {
View Full Code Here

     * Mark for deletion all dependent objects (via references and collections).
     * @return the number of deleted objects
     */
    private int doCascadeDelete(Identity oid, Object obj)
    {
        ClassDescriptor mif = _pb.getClassDescriptor(ProxyHelper.getRealClass(obj));
        Collection refDescs = mif.getObjectReferenceDescriptors();
        Collection colDescs = mif.getCollectionDescriptors();
        int countCascadeDeleted = 0;

        for (Iterator it = refDescs.iterator(); it.hasNext(); )
        {
            ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) it.next();
View Full Code Here

     * @see OjbMetaTreeNode#_load()
     */
    protected boolean _load()
    {
      java.util.ArrayList newChildren = new java.util.ArrayList();
      ClassDescriptor itemClass = this.getRepository().getDescriptorFor(this.collectionDescriptor.getItemClassName());
      newChildren.add(getOjbMetaTreeModel().getClassDescriptorNodeForClassDescriptor(itemClass));
     
    // Foreign Key fields retrieved here map to FieldDescriptors of the table in the collection
    System.err.println(toString());
      java.util.Iterator it;
View Full Code Here

    {
        // 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);
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.metadata.ClassDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.