Package org.jpox.metadata

Examples of org.jpox.metadata.AbstractClassMetaData


                    String typeMethodName = ASMUtils.getTypeNameForJDOMethod(fmd.getType());
                    int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(),
                        objectIdClass, fmd.getName());

                    // Check if the PK field type is a PC (CompoundIdentity)
                    AbstractClassMetaData acmd = enhancer.getClassMetaData().getMetaDataManager().getMetaDataForClass(
                        fmd.getType(), enhancer.getClassLoaderResolver());
                    if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE)
                    {
                        // CompoundIdentity, this field of the PK is a PC
                        visitor.visitVarInsn(Opcodes.ALOAD, 1);
                        ASMUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
                        visitor.visitVarInsn(Opcodes.ALOAD, 0);
                        visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(),
                            ClassEnhancer.MN_JdoGetPersistenceManager, "()Ljavax/jdo/PersistenceManager;");
                        visitor.visitVarInsn(Opcodes.ALOAD, 3);

                        // TODO Cater for property, or private field cases
                        visitor.visitFieldInsn(Opcodes.GETFIELD, ACN_objectIdClass,
                            fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");

                        visitor.visitInsn(Opcodes.ICONST_0);
                        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, ASMUtils.ACN_PersistenceManager,
                            "getObjectById", "(Ljava/lang/Object;Z)Ljava/lang/Object;");
                        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE,
View Full Code Here


                    String typeMethodName = ASMUtils.getTypeNameForJDOMethod(fmd.getType());
                    int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(),
                        objectIdClass, fmd.getName());

                    // Check if the PK field type is a PC (CompoundIdentity)
                    AbstractClassMetaData acmd = enhancer.getClassMetaData().getMetaDataManager().getMetaDataForClass(
                        fmd.getType(), enhancer.getClassLoaderResolver());
                    if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE)
                    {
                        // CompoundIdentity, this field of the PK is a PC
                        visitor.visitVarInsn(Opcodes.ALOAD, 3);
                        visitor.visitVarInsn(Opcodes.ALOAD, 1);
                        ASMUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
                        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE,
                            "javax/jdo/spi/PersistenceCapable$ObjectIdFieldSupplier",
                            "fetch" + typeMethodName + "Field", "(I)" + ASMUtils.getTypeDescriptorForJDOMethod(fmd.getType()));
                        if (typeMethodName.equals("Object"))
                        {
                            visitor.visitTypeInsn(Opcodes.CHECKCAST, fmd.getTypeName().replace('.', '/'));
                        }

                        visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
                            "getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
                        visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
                        // TODO Cater for property, and private field cases
                        visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
                            fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
                    }
                    else
                    {
                        // Standard application-identity
                        if (fmd.isProperty())
View Full Code Here

    /**
     * Method to add the contents of the class method.
     */
    public void execute()
    {
        AbstractClassMetaData cmd = getClassEnhancer().getClassMetaData();
        String pcSuperclassName = cmd.getPersistenceCapableSuperclass();

        visitor.visitCode();

        Label startLabel = new Label();
        visitor.visitLabel(startLabel);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
            ClassEnhancer.FN_StateManager, ASMUtils.CD_StateManager);
        Label l1 = new Label();
        visitor.visitJumpInsn(Opcodes.IFNULL, l1);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
            ClassEnhancer.FN_StateManager, ASMUtils.CD_StateManager);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitVarInsn(Opcodes.ALOAD, 1);
        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, ASMUtils.ACN_StateManager,
            "makeDirty", "(" + ASMUtils.CD_PersistenceCapable + "Ljava/lang/String;" + ")V");
        visitor.visitLabel(l1);

        if (cmd.isDetachable())
        {
            // if (jdoIsDetached())
            visitor.visitVarInsn(Opcodes.ALOAD, 0);
            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(),
                "jdoIsDetached", "()Z");
View Full Code Here

                Label reflectionFieldStart = null;
                for (int i=0;i<pkFieldNums.length;i++)
                {
                    AbstractMemberMetaData fmd = enhancer.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[i]);
                    String fieldTypeDesc = Type.getDescriptor(fmd.getType());
                    AbstractClassMetaData acmd = enhancer.getClassMetaData().getMetaDataManager().getMetaDataForClass(
                        fmd.getType(), enhancer.getClassLoaderResolver());
                    int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(),
                        objectIdClass, fmd.getName());

                    // Check if the PK field type is a PC (CompoundIdentity)
                    if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE)
                    {
                        // CompoundIdentity, this field of the PK is a PC
                        if (fmd.isProperty())
                        {
                            // Persistent Property so use o.setXXX((XXX.Key)JDOHelper.getObjectId(jdoGetXXX()))
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(),
                                "jdoGet" + fmd.getName(), "()" + Type.getDescriptor(fmd.getType()));
                            visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
                                "getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
                            visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
                            // TODO Use properties here
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
                                fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
                        }
                        else if (Modifier.isPublic(pkFieldModifiers))
                        {
                            // Persistent Field public, so use o.xxx = (XXX.Key)JDOHelper.getObjectId(xxx);
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
                                fmd.getName(), fieldTypeDesc);
                            visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
                                "getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
                            visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
                                fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
                        }
                        else
                        {
                            // Persistent Field private/protected so use reflection
                            // TODO Use reflection here
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
                                fmd.getName(), fieldTypeDesc);
                            visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
                                "getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
                            visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
                            // TODO Use reflection here
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
                                fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
                        }
                    }
                    else
                    {
                        // Standard application-identity field
View Full Code Here

                    String fieldTypeName = fmd.getTypeName().replace('.', '/');
                    int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(),
                        objectIdClass, fmd.getName());

                    // Check if the PK field type is a PC (CompoundIdentity)
                    AbstractClassMetaData acmd = enhancer.getClassMetaData().getMetaDataManager().getMetaDataForClass(
                        fmd.getType(), enhancer.getClassLoaderResolver());
                    if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE)
                    {
                        // CompoundIdentity, this field of the PK is a PC
                        visitor.visitVarInsn(Opcodes.ALOAD, 0);
                        visitor.visitVarInsn(Opcodes.ALOAD, 0);
                        visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(),
                            ClassEnhancer.MN_JdoGetPersistenceManager, "()Ljavax/jdo/PersistenceManager;");
                        visitor.visitVarInsn(Opcodes.ALOAD, 2);

                        // TODO Cater for property/private field cases
                        visitor.visitFieldInsn(Opcodes.GETFIELD, ACN_objectIdClass,
                            fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");

                        visitor.visitInsn(Opcodes.ICONST_0);
                        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/PersistenceManager",
                            "getObjectById", "(Ljava/lang/Object;Z)Ljava/lang/Object;");
                        visitor.visitTypeInsn(Opcodes.CHECKCAST, fieldTypeName);
View Full Code Here

        if (schemaName == null && catalogName == null)
        {
            // Check the <class schema="..." catalog="..." >
            if (fmd.getParent() instanceof AbstractClassMetaData)
            {
                AbstractClassMetaData ownerCmd = (AbstractClassMetaData)fmd.getParent();
                if (rdba.supportsCatalogsInTableDefinitions())
                {
                    catalogName = ownerCmd.getCatalog();
                }
                if (rdba.supportsSchemasInTableDefinitions())
                {
                    schemaName = ownerCmd.getSchema();
                }
            }

            if (schemaName == null && catalogName == null)
            {
View Full Code Here

            pkMappings = new JavaTypeMapping[cmd.getNoOfPrimaryKeyMembers()];
            if (cmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.COMPLETE_TABLE)
            {
                // COMPLETE-TABLE so use root class metadata and add PK members
                // TODO Does this allow for overridden PK field info ?
                AbstractClassMetaData baseCmd = cmd.getBaseAbstractClassMetaData();
                fieldCount = baseCmd.getNoOfManagedMembers();
                for (int relFieldNum = 0; relFieldNum < fieldCount; ++relFieldNum)
                {
                    AbstractMemberMetaData mmd = baseCmd.getMetaDataForManagedMemberAtPosition(relFieldNum);
                    if (mmd.isPrimaryKey())
                    {
                        if (mmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                        {
                            fieldsToAdd[pkFieldNum++] = mmd;
                            hasPrimaryKeyInThisClass = true;
                        }
                        else if (mmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                        {
                            throw new JPOXException(LOCALISER.msg("057006", mmd.getName())).setFatal();
                        }

                        // Check if auto-increment and that it is supported by this RDBMS
                        if ((mmd.getValueStrategy() == IdentityStrategy.IDENTITY) && !dba.supportsIdentityFields())
                        {
                            throw new JPOXException(LOCALISER.msg("057020",
                                cmd.getFullClassName(), mmd.getName())).setFatal();
                        }
                    }
                }
            }
            else
            {
                for (int relFieldNum=0; relFieldNum<fieldCount; ++relFieldNum)
                {
                    AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtPosition(relFieldNum);
                    if (fmd.isPrimaryKey())
                    {
                        if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                        {
                            fieldsToAdd[pkFieldNum++] = fmd;
                            hasPrimaryKeyInThisClass = true;
                        }
                        else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                        {
                            throw new JPOXException(LOCALISER.msg("057006",fmd.getName())).setFatal();
                        }

                        // Check if auto-increment and that it is supported by this RDBMS
                        if ((fmd.getValueStrategy() == IdentityStrategy.IDENTITY) && !dba.supportsIdentityFields())
                        {
                            throw new JPOXException(LOCALISER.msg("057020",
                                cmd.getFullClassName(), fmd.getName())).setFatal();
                        }
                    }
                }
            }
        }

        // No Primary Key defined, so search for superclass or handle datastore id
        if (!hasPrimaryKeyInThisClass)
        {
            if (cmd.getIdentityType() == IdentityType.APPLICATION)
            {
                // application-identity
                DatastoreClass elementCT = storeMgr.getDatastoreClass(cmd.getPersistenceCapableSuperclass(), clr);
                if (elementCT != null)
                {
                    // Superclass has a table so copy its PK mappings
                    ColumnMetaDataContainer colContainer = null;
                    if (cmd.getInheritanceMetaData() != null)
                    {
                        // Try via <inheritance><join>...</join></inheritance>
                        colContainer = cmd.getInheritanceMetaData().getJoinMetaData();
                    }
                    if (colContainer == null)
                    {
                        // Try via <primary-key>...</primary-key>
                        colContainer = cmd.getPrimaryKeyMetaData();
                    }

                    addApplicationIdUsingClassTableId(colContainer, elementCT, clr, cmd);
                }
                else
                {
                    // Superclass has no table so create new mappings and columns
                    AbstractClassMetaData pkCmd = storeMgr.getClassWithPrimaryKeyForClass(cmd.getSuperAbstractClassMetaData(), clr);
                    if (pkCmd != null)
                    {
                        pkMappings = new JavaTypeMapping[pkCmd.getNoOfPrimaryKeyMembers()];
                        pkFieldNum = 0;
                        fieldCount = pkCmd.getNoOfInheritedManagedMembers() + pkCmd.getNoOfManagedMembers();
                        for (int absFieldNum = 0; absFieldNum < fieldCount; ++absFieldNum)
                        {
                            AbstractMemberMetaData fmd = pkCmd.getMetaDataForManagedMemberAtAbsolutePosition(absFieldNum);
                            if (fmd.isPrimaryKey())
                            {
                                AbstractMemberMetaData overriddenFmd = cmd.getOverriddenMember(fmd.getName());
                                if (overriddenFmd != null)
                                {
View Full Code Here

     * this class with other than "subclass-table" we stop the process.
     * @param theCmd The ClassMetaData for the class
     */
    private void initializeForClass(AbstractClassMetaData theCmd, ClassLoaderResolver clr)
    {
        AbstractClassMetaData parentCmd = theCmd.getSuperAbstractClassMetaData();

        // Manage the fields for the passed class
        manageClass(theCmd, clr);

        // Now check the superclass of this class
        // This caters for superclasses which have their fields persisted with the subclass ("subclass-table" strategy)
        if (parentCmd != null)
        {
            if (cmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.COMPLETE_TABLE)
            {
                // Managed class requires all superclasses managed here too
                initializeForClass(parentCmd, clr);
            }
            else if (parentCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
            {
                // Superclass uses "subclass-table" so needs managing here
                initializeForClass(parentCmd, clr);
            }
        }
View Full Code Here

        {
            // "complete-table" has no super table. All is persisted into this table
            return null;
        }

        AbstractClassMetaData superCmd = theCmd.getSuperAbstractClassMetaData();
        if (superCmd != null)
        {
            if (superCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.NEW_TABLE)
            {
                // This class has its own table, so return it.
                return (ClassTable) storeMgr.getDatastoreClass(superCmd.getFullClassName(), clr);
            }
            else if (superCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
            {
                // This class is mapped to the same table, so go up another level.
                return getSupertable(superCmd, clr);
            }
            else
View Full Code Here

        // Create the ForeignKey base details
        ForeignKey fk = new ForeignKey(fkmd.isDeferred());
        fk.setForMetaData(fkmd);

        // Find the target of the foreign-key
        AbstractClassMetaData acmd = cmd;
        if (fkmd.getTable() == null)
        {
            // Can't create a FK if we don't know where it goes to
            JPOXLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058105", acmd.getFullClassName()));
            return null;
        }
        DatastoreIdentifier tableId = storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(fkmd.getTable());
        ClassTable refTable = (ClassTable)storeMgr.getDatastoreClass(tableId);
        if (refTable == null)
        {
            // TODO Go to the datastore and query for this table to get the columns of the PK
            JPOXLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058106", acmd.getFullClassName(),
                fkmd.getTable()));
            return null;
        }
        PrimaryKey pk = refTable.getPrimaryKey();
        List targetCols = pk.getColumns();

        // Generate the columns for the source of the foreign-key
        List sourceCols = new ArrayList();
        ColumnMetaData[] colmds = fkmd.getColumnMetaData();
        AbstractMemberMetaData[] fmds = fkmd.getMemberMetaData();
        if (colmds != null && colmds.length > 0)
        {
            // FK specified via <column>
            for (int i=0;i<colmds.length;i++)
            {
                // Find the column and add to the source columns for the FK
                DatastoreIdentifier colId = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(colmds[i].getName());
                Column sourceCol = (Column)columnsByName.get(colId);
                if (sourceCol == null)
                {
                    JPOXLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058107",
                        acmd.getFullClassName(), fkmd.getTable(), colmds[i].getName(), toString()));
                    return null;
                }
                sourceCols.add(sourceCol);
            }
        }
        else if (fmds != null && fmds.length > 0)
        {
            // FK specified via <field>
            for (int i=0;i<fmds.length;i++)
            {
                // Find the metadata for the actual field with the same name as this "foreign-key" field
                // and add all columns to the source columns for the FK
                AbstractMemberMetaData realFmd = getFieldMetaData(fmds[i].getName());
                JavaTypeMapping fieldMapping = (JavaTypeMapping)fieldMappingsMap.get(realFmd);
                int countDatastoreFields = fieldMapping.getNumberOfDatastoreFields();
                for (int j=0; j<countDatastoreFields; j++)
                {
                    // Add each column of this field to the FK definition
                    sourceCols.add(fieldMapping.getDataStoreMapping(i).getDatastoreField());
                }
            }
        }

        if (sourceCols.size() != targetCols.size())
        {
            // Different number of cols in this table and target table
            JPOXLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058108",
                acmd.getFullClassName(), fkmd.getTable(), "" + sourceCols.size(), "" + targetCols.size()));
        }

        // Add all column mappings to the ForeignKey
        if (sourceCols.size() > 0)
        {
View Full Code Here

TOP

Related Classes of org.jpox.metadata.AbstractClassMetaData

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.