Package org.apache.ojb.broker.metadata

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


     * new object with PK 0, because PK field is not primitive
     */
    public void testNull_0_Complex_2() throws Exception
    {
        Class objClass = ObjectRepository.E.class;
        ClassDescriptor cld = broker.getClassDescriptor(objClass);
        Integer someOtherValue = new Integer(1111111111);
        String delete = "DELETE FROM TABLE_E WHERE ID=0";
        Statement stmt;
        try
        {
View Full Code Here


    /**
     * performs a test to check if metadata can be read
     */
    public void testGetDescriptor() throws Exception
    {
        ClassDescriptor cld = broker.getClassDescriptor(Article.class);
        assertNotNull("classdescriptor should not be null", cld);
    }
View Full Code Here

            System.err.println("Cannot swizzle objects of different classes: "
                    + newObj.getClass() + " and " + oldObj.getClass());
            return newObj;
        }

        ClassDescriptor mif = pb.getClassDescriptor(newObj.getClass());
        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();

        for (int i = 0; i < fieldDescs.length; i++)
        {
            FieldDescriptor fd = fieldDescs[i];
            PersistentField f = fd.getPersistentField();
            f.set(oldObj, f.get(newObj));
        }

        // N:1 relations
        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
        ObjectReferenceDescriptor rds;
        PersistentField field;
        Object newRelObj;
        Identity newRelOid;
        Object oldRelObj;

        while (iter.hasNext())
        {
            rds = (ObjectReferenceDescriptor) iter.next();
            field = rds.getPersistentField();
            newRelObj = field.get(newObj);
            oldRelObj = field.get(oldObj);
            if ((newRelObj == null) && (oldRelObj != null))
            {
                field.set(oldObj, null);
            }
            else if (newRelObj != null)
            {
                newRelOid = new Identity(newRelObj, pb);
                if ((oldRelObj == null) ||
                        !newRelOid.equals(new Identity(oldRelObj, pb)))
                {
                    // seek for existing old object with the new identity
                    oldRelObj = cache.lookup(newRelOid);
                    if (oldRelObj == null)
                    {
                        throw new IllegalStateException("Related object not found in the context: " + newRelOid);
                    }
                    field.set(oldObj, oldRelObj);
                }
            }
        }

        // 1:N relations
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor collectionDescriptor;

        while (collections.hasNext())
        {
            collectionDescriptor = (CollectionDescriptor) collections.next();
View Full Code Here

                    "', property 'autoNaming' in sequence-manager element in repository was '" +
                    autoNaming + "'. Set autoNaming true in sequence-descriptor or define a " +
                    " sequence-name in field-descriptor.");
        }

        ClassDescriptor cldTargetClass = field.getClassDescriptor();
        /*
        check for inheritance on multiple table
        */
        cldTargetClass = findInheritanceRoot(cldTargetClass);
        Class topLevel = brokerForClass.getTopLevelClass(cldTargetClass.getClassOfObject());
        ClassDescriptor cldTopLevel = brokerForClass.getClassDescriptor(topLevel);
        /**
         *
         * MBAIRD
         * Should not use classname for the sequenceName as we will end up
         * re-using sequence numbers for classes mapped to the same table.
         * Instead, make the FullTableName the discriminator since it will
         * always be unique for that table, and hence that class.
         *
         * arminw:
         * If the found top-level class has extents, we take the first
         * found extent class table name as sequence name. Else we take
         * the table name of the 'targetClass'.
         *
         */
        if (cldTopLevel.isExtent())
        {
            /*
            arminw:
            this is a little critical, because we do not know if the extent classes
            will change by and by and the first found extent class may change, thus the
View Full Code Here

     * hierachy of the given descriptor or the descriptor itself if no inheriatance on multiple table is
     * used.
     */
    private static ClassDescriptor findInheritanceRoot(ClassDescriptor cld)
    {
        ClassDescriptor result = cld;
        if(cld.getSuperClassDescriptor() != null)
        {
            result = findInheritanceRoot(cld.getSuperClassDescriptor());
        }
        return result;
View Full Code Here

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

        DescriptorRepository repos = broker.getDescriptorRepository();
        _fkInfo = new HashMap();
        for (Iterator it = repos.iterator(); it.hasNext();)
        {
            ClassDescriptor desc = (ClassDescriptor) it.next();
            List ordList = desc.getObjectReferenceDescriptors();
            if (!ordList.isEmpty())
            {
                HashSet fkTables = getFKTablesFor(desc.getFullTableName());
                for (Iterator it2 = ordList.iterator(); it2.hasNext();)
                {
                    ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) it2.next();
                    ClassDescriptor oneDesc = repos.getDescriptorFor(ord.getItemClass());
                    fkTables.addAll(getFullTableNames(oneDesc, repos));
                }
            }

            List codList = desc.getCollectionDescriptors();
            for (Iterator it2 = codList.iterator(); it2.hasNext();)
            {
                CollectionDescriptor cod = (CollectionDescriptor) it2.next();
                ClassDescriptor manyDesc = repos.getDescriptorFor(cod.getItemClass());
                if (cod.isMtoNRelation())
                {
                    HashSet fkTables = getFKTablesFor(cod.getIndirectionTable());
                    fkTables.addAll(getFullTableNames(desc, repos));
                    fkTables.addAll(getFullTableNames(manyDesc, repos));
View Full Code Here

            tableNamesSet.add(tableName);
        }
        for (Iterator it = extents.iterator(); it.hasNext();)
        {
            Class extClass = (Class) it.next();
            ClassDescriptor extDesc = repos.getDescriptorFor(extClass);
            tableName = extDesc.getFullTableName();
            if (tableName != null)
            {
                tableNamesSet.add(tableName);
            }
        }
View Full Code Here

        assertEquals(1, retrievednodeB.getParents().size());
    }

    void changeRelationMetadata(String field, boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(Node.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName(field);
        cod.setLazy(proxy);
        cod.setCascadeRetrieve(autoRetrieve);
        cod.setCascadingStore(autoUpdate);
        cod.setCascadingDelete(autoDelete);
    }
View Full Code Here

            TransactionExt tx = (TransactionExt) odmg.newTransaction();
            tx.begin();
            // now we tell OJB that one 1:1 reference of the bidirectional 1:1 reference
            // between Shop and ShopDetail has a FK constraint
            ClassDescriptor cld = tx.getBroker().getClassDescriptor(CircularTest.Shop.class);
            ord = cld.getObjectReferenceDescriptorByName("detail");
            // current DB schema create a foreign key constraint and we can
            // inform OJB
            ord.setConstraint(true);
            // now it doesn't matter in which order we persist the new objects, OJB should
            // always reorder the objects before insert/update call
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.