Package org.jpox.metadata

Examples of org.jpox.metadata.AbstractClassMetaData


                }
            }
        }

        int[] fieldNumbers = new int[this.fieldNumbers.length];
        AbstractClassMetaData cmd = om.getMetaDataManager().getMetaDataForClass(pcClassForObject, clr);
        for (int i = 0; i < this.fieldNumbers.length; i++)
        {
            if (acmd instanceof InterfaceMetaData)
            {
                fieldNumbers[i] = cmd.getAbsolutePositionOfMember(acmd.getMetaDataForManagedMemberAtAbsolutePosition(this.fieldNumbers[i]).getName());
            }
            else
            {
                fieldNumbers[i] = cmd.getAbsolutePositionOfMember(acmd.getMetaDataForManagedMemberAtAbsolutePosition(this.fieldNumbers[i]).getClassName(),
                    acmd.getMetaDataForManagedMemberAtAbsolutePosition(this.fieldNumbers[i]).getName());
                if (fieldNumbers[i] == -1)
                {
                    fieldNumbers[i] = cmd.getAbsolutePositionOfMember(acmd.getMetaDataForManagedMemberAtAbsolutePosition(this.fieldNumbers[i]).getName());
                }
            }
        }

        // Extract the object from the ResultSet
        Object obj = null;
        if (cmd.getIdentityType() == IdentityType.APPLICATION)
        {
            obj = getObjectByAID(om, (ResultSet)rs, fieldNumbers, cmd, pcClassForObject, requiresInheritanceCheck);
        }
        else if (cmd.getIdentityType() == IdentityType.DATASTORE)
        {
            JavaTypeMapping mapping = new OIDMapping();
            mapping.initialize(table.getStoreManager().getDatastoreAdapter(), pcClassForObject.getName());
            mapping.addDataStoreMapping(table.getDataStoreObjectIdMapping().getDataStoreMapping(0));
            Object id = mapping.getObject(om, rs, datastoreIdentityExpressionIndex);
            if (fieldNumbers == null)
            {
                obj = om.findObject(id, false, requiresInheritanceCheck, null);
            }
            else
            {
              if (requiresInheritanceCheck)
              {
                    obj = getObjectById(om, (ResultSet)rs, fieldNumbers, cmd, id, null);
              }
              else
              {
                obj = getObjectById(om, (ResultSet)rs, fieldNumbers, cmd, id, pcClassForObject);
              }
            }
        }
        else if (cmd.getIdentityType() == IdentityType.NONDURABLE)
        {
            Object id = om.newObjectId(className, null);
            if (fieldNumbers == null)
            {
                obj = om.findObject(id, false, requiresInheritanceCheck, null);
View Full Code Here


                prefetchFieldNumbers = new int[prefetchFieldCount];
                System.arraycopy(fn, 0, prefetchFieldNumbers, 0, prefetchFieldCount);
            }
            else
            {
                AbstractClassMetaData cmd = vmd;
                if (cmd.getIdentityType() == IdentityType.APPLICATION)
                {
                    prefetchFieldNumbers = new int[cmd.getPKMemberPositions().length];
                    int fieldCount = cmd.getNoOfInheritedManagedMembers() + cmd.getNoOfManagedMembers();
                    statementExpressionIndex = new StatementExpressionIndex[fieldCount];
                    for (int i = 0; i < prefetchFieldNumbers.length; ++i)
                    {
                        prefetchFieldNumbers[i] = cmd.getPKMemberPositions()[i];
                        JavaTypeMapping m = valueTable.getFieldMapping(cmd.getMetaDataForManagedMemberAtAbsolutePosition(prefetchFieldNumbers[i]));
                        if (m != null) // field is not stored in the table, e.g List, Set, etc or is transactional
                        {
                            if (m.includeInFetchStatement() && !(m instanceof AbstractContainerMapping))
                            {
                                statementExpressionIndex[prefetchFieldNumbers[i]] = new StatementExpressionIndex();
View Full Code Here

                StatementExpressionIndex[] statementExpressionIndex;
                Set columnsInThisType = new HashSet();
                AbstractMemberMetaData[] fmds = new AbstractMemberMetaData[columnNames.length];
                Map fieldColumns = new HashMap();
                DatastoreClass dc = storeMgr.getDatastoreClass(persistentTypes[i].getClassName(),om.getClassLoaderResolver());
                AbstractClassMetaData acmd = om.getMetaDataManager().getMetaDataForClass(persistentTypes[i].getClassName(), om.getClassLoaderResolver());
                Object id = null;
                for (int j=startColumnIndex;j<columnNames.length;j++)
                {
                    if( columnsInThisType.contains(columnNames[j]) )
                    {
                        //already added this column, so must be another persistent type
                        startColumnIndex = j;
                        break;
                    }

                    boolean found = false;
                    if (acmd.getIdentityType() == IdentityType.DATASTORE)
                    {
                        DatastoreField df = dc.getDataStoreObjectIdMapping().getDataStoreMapping(0).getDatastoreField();
                        if( df.getIdentifier().getIdentifier().equals(columnNames[j]))
                        {
                            //add +1 because result sets in jdbc starts with 1
                            int datastoreIdentityExpressionIndex = j+1;
                            //get object id if datastore identifier
                            if( dc.getDataStoreObjectIdMapping() != null )
                            {
                                id = dc.getDataStoreObjectIdMapping().getObject(om, rs, new int[] {datastoreIdentityExpressionIndex});
                            }
                            found=true;
                        }
                    }
                    for(int k=0; k<acmd.getNoOfManagedMembers()+acmd.getNoOfInheritedManagedMembers() && !found; k++)
                    {
                        AbstractMemberMetaData apmd = acmd.getMetaDataForManagedMemberAtAbsolutePosition(k);
                        if( persistentTypes[i].getColumnForField(apmd.getName())!=null )
                        {
                            if(persistentTypes[i].getColumnForField(apmd.getName()).equals(columnNames[j]))
                            {
                                fieldColumns.put(columnNames[j], apmd);
                                columnsInThisType.add(columnNames[j]);
                                fmds[j] = apmd;
                                found = true;
                            }
                        }
                        else
                        {
                            JavaTypeMapping mapping = dc.getFieldMapping(apmd);
                            for(int l=0; l<mapping.getDataStoreMappings().length && !found; l++)
                            {
                                DatastoreField df = mapping.getDataStoreMapping(l).getDatastoreField();
                                if( df.getIdentifier().getIdentifier().equals(columnNames[j]))
                                {
                                    fieldColumns.put(columnNames[j], apmd);
                                    columnsInThisType.add(columnNames[j]);
                                    fmds[j] = apmd;
                                    found = true;
                                }
                            }
                        }
                    }
                    if( !columnsInThisType.contains(columnNames[j]) )
                    {
                       
                        //column not found in this type, so must be another persistent type
                        startColumnIndex = j;
                        break;
                    }
                }
               
                //build StatementExpressionIndex
                Set fields = new HashSet();
                fields.addAll(fieldColumns.values());
                statementExpressionIndex = new StatementExpressionIndex[acmd.getNoOfManagedMembers() + acmd.getNoOfInheritedManagedMembers()];
                fieldNumbers = new int[fields.size()];
                Iterator it = fields.iterator();
                int j=0;
                while (it.hasNext())
                {
                    AbstractMemberMetaData apmd = (AbstractMemberMetaData)it.next();
                    fieldNumbers[j] = apmd.getAbsoluteFieldNumber();
                    statementExpressionIndex[fieldNumbers[j]] = new StatementExpressionIndex();
                    List indexes = new ArrayList();
                    for( int k=0; k<fmds.length; k++)
                    {
                        if( fmds != null && fmds[k] == apmd)
                        {
                            indexes.add(new Integer(k));
                        }
                    }
                    int[] indxs = new int[indexes.size()];
                    for( int k=0; k<indxs.length; k++)
                    {
                        //add +1 because result sets in jdbc starts with 1
                        indxs[k] = ((Integer)indexes.get(k)).intValue()+1;
                    }
                   
                    statementExpressionIndex[fieldNumbers[j]].setExpressionIndex(indxs);
                    statementExpressionIndex[fieldNumbers[j]].setMapping(dc.getFieldMapping(apmd));
                    j++;
                   
                }
                Object obj = null;
                Class type = om.getClassLoaderResolver().classForName(persistentTypes[i].getClassName());
                if (acmd.getIdentityType() == IdentityType.APPLICATION)
                {
                    obj = getObjectByAID(om, (ResultSet)rs, fieldNumbers, acmd, type, false, statementExpressionIndex);
                }
                else if (acmd.getIdentityType() == IdentityType.DATASTORE)
                {
                    obj = getObjectById(om, (ResultSet)rs, fieldNumbers, acmd, id, type, statementExpressionIndex);
                }
                returnObjects.add(obj);
            }
View Full Code Here

                    FieldRole.ROLE_COLLECTION_ELEMENT, clr);
                elementInfo = new ElementInfo[implNames.length];
                for (int i=0;i<implNames.length;i++)
                {
                    DatastoreClass table = storeMgr.getDatastoreClass(implNames[i], clr);
                    AbstractClassMetaData cmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(implNames[i], clr);
                    elementInfo[i] = new ElementInfo(cmd,table);
                }
            }
            else
            {
View Full Code Here

     * Method to perform any necessary pre-processing on the users query statement before we execute it.
     * @return The compiled SQL
     */
    protected String generateQueryStatement()
    {
        final AbstractClassMetaData candidateCmd;
        if (candidateClass == null)
        {
            // We have no candidate so don't need to bother about aligning the return columns to our mappings.
            fieldColumnNames = new ArrayList(); // Empty
            candidateCmd = null;
        }
        else
        {
            MappedStoreManager storeMgr = (MappedStoreManager)om.getStoreManager();
            DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
            candidateCmd = om.getMetaDataManager().getMetaDataForClass(candidateClass,om.getClassLoaderResolver());
            if (candidateCmd == null)
            {
                throw new ClassNotPersistenceCapableException(candidateClass.getName());
            }
            if (candidateCmd.getPersistenceCapableSuperclass() != null)
            {
                throw new PersistentSuperclassNotAllowedException(candidateClass.getName());
            }
            if (candidateCmd.isRequiresExtent())
            {
                throw new JPOXUserException(LOCALISER_RDBMS.msg("060000",
                    candidateClass.getName()));
            }
            if (candidateCmd.getIdentityType() != IdentityType.NONDURABLE)
            {
                throw new JPOXUserException(LOCALISER_RDBMS.msg("060001",
                    candidateClass.getName()));
            }

            int fieldCount = candidateCmd.getNoOfManagedMembers();
            int[] fn = new int[fieldCount];
            statementExpressionIndex = new StatementExpressionIndex[fieldCount];
            fieldColumnNames = new ArrayList(fieldCount);
            int n = 0;

            for (int fieldNumber = 0; fieldNumber < fieldCount; ++fieldNumber)
            {
                statementExpressionIndex[fieldNumber] = new StatementExpressionIndex();
                AbstractMemberMetaData fmd = candidateCmd.getMetaDataForManagedMemberAtPosition(fieldNumber);
                String fieldName = fmd.getName();
                Class fieldType = fmd.getType();

                if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                {
                    JavaTypeMapping m = dba.getMapping(fieldType, storeMgr, om.getClassLoaderResolver());
                    if (m.includeInFetchStatement())
                    {
                        statementExpressionIndex[fieldNumber].setMapping(m);
                        fn[n++] = fieldNumber;

                        String columnName = null;
                        if (fmd.getColumnMetaData() != null && fmd.getColumnMetaData().length > 0)
                        {
                            columnName = fmd.getColumnMetaData()[0].getName();
                        }
                        else
                        {
                            columnName = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(fieldName,
                                om.getOMFContext().getTypeManager().isDefaultEmbeddedType(fieldType),
                                FieldRole.ROLE_NONE).getIdentifier();
                        }
                        fieldColumnNames.add(columnName);
                    }

                    if (m instanceof AbstractContainerMapping)
                    {
                        // TODO Remove this. Why is it needed ?
                        throw new JPOXUserException("Mapping " + m +
                            " not suitable for a JPOXSQL result column, field = " + fieldName).setFatal();
                    }
                }
                else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                {
                    throw new JPOXException("Invalid persistence modifier on field " + fieldName).setFatal();
                }
            }

            if (n == 0)
            {
                throw new JPOXUserException("View class has no persistent fields: " + candidateClass.getName()).setFatal();
            }

            fieldNumbers = new int[n];
            System.arraycopy(fn, 0, fieldNumbers, 0, n);
        }

        // Generate the actual JDBC SQL text by processing the embedded parameter/field macros
        // in the provided JPOXSQL text.
        parameterOccurrences = new ArrayList();
        MacroString ms = new MacroString(candidateClass != null ? candidateClass.getName() : null,
                                         candidateClass != null ? imports : null, inputSQL);
        return ms.substituteMacros(new MacroString.MacroHandler()
            {
            public void onIdentifierMacro(MacroString.IdentifierMacro im)
            {
                // Only process identifier macros when the candidate class is known
                if (candidateClass != null)
                {
                    if (im.className.equals(candidateClass.getName()))
                    {
                        if (im.fieldName == null)
                        {
                            throw new JPOXUserException(LOCALISER_RDBMS.msg("060004",im));
                        }
                        if (im.subfieldName != null)
                        {
                            throw new JPOXUserException(LOCALISER_RDBMS.msg("060003",im.className,im));
                        }
                        int fieldNumber = candidateCmd.getRelativePositionOfMember(im.fieldName);
                       
                        if (fieldNumber < 0)
                        {
                            throw new JPOXUserException(LOCALISER_RDBMS.msg("060003",im.className,im));
                        }
View Full Code Here

        String[] argNames = new String[] {"objPC"};
        String fieldTypeDesc = Type.getDescriptor(mmd.getType());

        mv.visitCode();

        AbstractClassMetaData cmd = mmd.getAbstractClassMetaData();
        if ((mmd.getJdoFieldFlag() & PersistenceCapable.MEDIATE_READ) == PersistenceCapable.MEDIATE_READ)
        {
            // MEDIATE_READ
            Label startLabel = new Label();
            mv.visitLabel(startLabel);

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFNULL, l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                "isLoaded", "(Ljavax/jdo/spi/PersistenceCapable;I)Z");
            mv.visitJumpInsn(Opcodes.IFNE, l1);

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
                mv.visitInsn(Opcodes.IADD);
            }

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
            String jdoMethodName = "get" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
            String argTypeDesc = fieldTypeDesc;
            if (jdoMethodName.equals("getObjectField"))
            {
                argTypeDesc = ASMUtils.CD_Object;
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + ")" + argTypeDesc);
            if (jdoMethodName.equals("getObjectField"))
            {
                // Cast any object fields to the correct type
                mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
            }
            ASMUtils.addReturnForType(mv, mmd.getType());

            mv.visitLabel(l1);

            Label l4 = new Label();
            if (cmd.isDetachable())
            {
                // "if (objPC.jdoIsDetached() != false && ((BitSet) objPC.jdoDetachedState[2]).get(5) != true)"
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, "jdoIsDetached", "()Z");
                mv.visitJumpInsn(Opcodes.IFEQ, l4);
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                    ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
                mv.visitInsn(Opcodes.ICONST_2);
                mv.visitInsn(Opcodes.AALOAD);
                mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
                ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
                if (cmd.getPersistenceCapableSuperclass() != null)
                {
                    mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
                    mv.visitInsn(Opcodes.IADD);
                }
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
                mv.visitJumpInsn(Opcodes.IFNE, l4);
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                    ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
                mv.visitInsn(Opcodes.ICONST_3);
                mv.visitInsn(Opcodes.AALOAD);
                mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
                ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
                if (cmd.getPersistenceCapableSuperclass() != null)
                {
                    mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
                    mv.visitInsn(Opcodes.IADD);
                }
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
                mv.visitJumpInsn(Opcodes.IFNE, l4);

                // "throw new JDODetachedFieldAccessException(...)"
                mv.visitTypeInsn(Opcodes.NEW, "javax/jdo/JDODetachedFieldAccessException");
                mv.visitInsn(Opcodes.DUP);
                mv.visitLdcInsn(LOCALISER.msg("Enhancer.DetachedPropertyAccess", mmd.getName()));
                mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "javax/jdo/JDODetachedFieldAccessException",
                    "<init>", "(Ljava/lang/String;)V");
                mv.visitInsn(Opcodes.ATHROW);
            }

            mv.visitLabel(l4);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
            ASMUtils.addReturnForType(mv, mmd.getType());

            Label endLabel = new Label();
            mv.visitLabel(endLabel);
            mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
            mv.visitMaxs(4, 1);
        }
        else if ((mmd.getJdoFieldFlag() & PersistenceCapable.CHECK_READ) == PersistenceCapable.CHECK_READ)
        {
            // CHECK_READ
            Label startLabel = new Label();
            mv.visitLabel(startLabel);

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, ClassEnhancer.FN_Flag, "B");
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFLE, l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitJumpInsn(Opcodes.IFNULL, l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
                    ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                "isLoaded", "(Ljavax/jdo/spi/PersistenceCapable;I)Z");
            mv.visitJumpInsn(Opcodes.IFNE, l1);

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                mv.visitInsn(Opcodes.IADD);
            }

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
            String jdoMethodName = "get" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
            String argTypeDesc = fieldTypeDesc;
            if (jdoMethodName.equals("getObjectField"))
            {
                argTypeDesc = ASMUtils.CD_Object;
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + ")" + argTypeDesc);
            if (jdoMethodName.equals("getObjectField"))
            {
                // Cast any object fields to the correct type
                mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
            }
            ASMUtils.addReturnForType(mv, mmd.getType());

            mv.visitLabel(l1);

            Label l4 = new Label();
            if (cmd.isDetachable())
            {
                // "if (objPC.jdoIsDetached() != false && ((BitSet) objPC.jdoDetachedState[2]).get(5) != true)"
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, ClassEnhancer.MN_JdoIsDetached, "()Z");
                mv.visitJumpInsn(Opcodes.IFEQ, l4);
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                    ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
                mv.visitInsn(Opcodes.ICONST_2);
                mv.visitInsn(Opcodes.AALOAD);
                mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
                ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
                if (cmd.getPersistenceCapableSuperclass() != null)
                {
                    mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
                        ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                    mv.visitInsn(Opcodes.IADD);
                }
View Full Code Here

        String[] argNames = new String[] {"objPC", "val"};
        String fieldTypeDesc = Type.getDescriptor(mmd.getType());

        mv.visitCode();

        AbstractClassMetaData cmd = mmd.getAbstractClassMetaData();
        if ((mmd.getJdoFieldFlag() & PersistenceCapable.MEDIATE_WRITE) == PersistenceCapable.MEDIATE_WRITE)
        {
            // MEDIATE_WRITE
            Label startLabel = new Label();
            mv.visitLabel(startLabel);

            // "if (objPC.jdoStateManager == null) objPC.ZZZ = zzz;"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFNONNULL, l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addLoadForType(mv, mmd.getType(), 1);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoSet" + mmd.getName(), "(" + fieldTypeDesc + ")V");
            Label l3 = new Label();
            mv.visitJumpInsn(Opcodes.GOTO, l3);

            // "else objPC.jdoStateManager.setYYYField(objPC, 0, objPC.ZZZ, zzz);"
            mv.visitLabel(l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
                mv.visitInsn(Opcodes.IADD);
            }

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
            ASMUtils.addLoadForType(mv, mmd.getType(), 1);
            String jdoMethodName = "set" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
            String argTypeDesc = fieldTypeDesc;
            if (jdoMethodName.equals("setObjectField"))
            {
                argTypeDesc = ASMUtils.CD_Object;
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + argTypeDesc + ")V");
            mv.visitLabel(l3);

            if (cmd.isDetachable())
            {
                // "if (objPC.jdoIsDetached() == true)"
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                    ClassEnhancer.MN_JdoIsDetached, "()Z");
                Label l6 = new Label();
                mv.visitJumpInsn(Opcodes.IFEQ, l6);

                // "((BitSet) objPC.jdoDetachedState[3]).set(0);"
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                    ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
                mv.visitInsn(Opcodes.ICONST_3);
                mv.visitInsn(Opcodes.AALOAD);
                mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
                ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
                if (cmd.getPersistenceCapableSuperclass() != null)
                {
                    mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
                        ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                    mv.visitInsn(Opcodes.IADD);
                }
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "set", "(I)V");
                mv.visitLabel(l6);
            }
            mv.visitInsn(Opcodes.RETURN);

            Label endLabel = new Label();
            mv.visitLabel(endLabel);
            mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
            mv.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
            mv.visitMaxs(5, 2);
        }
        else if ((mmd.getJdoFieldFlag() & PersistenceCapable.CHECK_WRITE) == PersistenceCapable.CHECK_WRITE)
        {
            // CHECK_WRITE
            Label startLabel = new Label();
            mv.visitLabel(startLabel);

            // "if (objPC.jdoFlags != 0 && objPC.jdoStateManager != null)"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, ClassEnhancer.FN_Flag, "B");
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitJumpInsn(Opcodes.IFNULL, l1);

            // "objPC.jdoStateManager.setYYYField(objPC, 8, objPC.ZZZ, val);"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
                    ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                mv.visitInsn(Opcodes.IADD);
            }

            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
            ASMUtils.addLoadForType(mv, mmd.getType(), 1);
            String jdoMethodName = "set" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
            String argTypeDesc = fieldTypeDesc;
            if (jdoMethodName.equals("setObjectField"))
            {
                argTypeDesc = ASMUtils.CD_Object;
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
                jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + argTypeDesc + ")V");
            Label l3 = new Label();
            mv.visitJumpInsn(Opcodes.GOTO, l3);

            // "objPC.text = val;"
            mv.visitLabel(l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            ASMUtils.addLoadForType(mv, mmd.getType(), 1);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                "jdoSet" + mmd.getName(), "(" + fieldTypeDesc + ")V");

            if (cmd.isDetachable())
            {
                // "if (objPC.jdoIsDetached() == true)  ((BitSet) objPC.jdoDetachedState[3]).set(8);"
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
                    ClassEnhancer.MN_JdoIsDetached, "()Z");
                mv.visitJumpInsn(Opcodes.IFEQ, l3);
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
                    ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
                mv.visitInsn(Opcodes.ICONST_3);
                mv.visitInsn(Opcodes.AALOAD);
                mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
                ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
                if (cmd.getPersistenceCapableSuperclass() != null)
                {
                    mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
                        ClassEnhancer.FN_JdoInheritedFieldCount, "I");
                    mv.visitInsn(Opcodes.IADD);
                }
View Full Code Here

    /**
     * Creates fields for the properties of this class and super classes.
     */
    protected void createPropertyFields()
    {
        AbstractClassMetaData acmd = inputCmd;
        do
        {
            createPropertyFields(acmd);
            acmd = acmd.getSuperAbstractClassMetaData();
        }
        while (acmd != null);
    }
View Full Code Here

    /**
     * Create getters and setters methods for this class and super classes
     */
    protected void createPropertyMethods()
    {
        AbstractClassMetaData acmd = inputCmd;
        do
        {
            createPropertyMethods(acmd);
            acmd = acmd.getSuperAbstractClassMetaData();
        }
        while (acmd != null);
   
View Full Code Here

            catch (ClassNotResolvedException e1)
            {
                JPOXLogger.ENHANCER.debug(StringUtils.getStringFromStackTrace(e1));
                return null;
            }
            AbstractClassMetaData acmd = omfContext.getMetaDataManager().getMetaDataForClass(clazz, clr);
           
            if( acmd == null )
            {
                //metadata or class not found, ignore.
                //happens in two conditions:
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.