Package org.jpox.metadata

Examples of org.jpox.metadata.MetaDataManager


        this.emd = emd;
        this.typeName = typeName;
        this.objectType = objectType;

        // Find the MetaData for the embedded PC class
        MetaDataManager mmgr = fmd.getAbstractClassMetaData().getMetaDataManager();
        AbstractClassMetaData pcCmd = mmgr.getMetaDataForClass(typeName, clr);
        if (pcCmd == null)
        {
            // Not found so must be an interface
            if (fmd != null)
            {
                // Try using the fieldTypes on the field/property - we support it if only 1 implementation
                String[] fieldTypes = fmd.getFieldTypes();
                if (fieldTypes != null && fieldTypes.length == 1)
                {
                    pcCmd = mmgr.getMetaDataForClass(fieldTypes[0], clr);
                }
                else if (fieldTypes != null && fieldTypes.length > 1)
                {
                    // TODO Cater for multiple implementations
                    throw new JPOXUserException("Field " + fmd.getFullFieldName() + " is a reference field that is embedded. " +
                        "JPOX doesnt support embedded reference fields that have more than 1 implementation");
                }
            }

            if (pcCmd == null)
            {
                // Try a persistent interface
                pcCmd = mmgr.getMetaDataForInterface(clr.classForName(typeName), clr);
                if (pcCmd == null && fmd.getFieldTypes() != null && fmd.getFieldTypes().length == 1)
                {
                    // No MetaData for the type so try "fieldType" specified on the field
                    pcCmd = mmgr.getMetaDataForInterface(clr.classForName(fmd.getFieldTypes()[0]), clr);
                }
            }
        }

        embCmd = pcCmd;
View Full Code Here


          if (sm != null)
          {
              sm.setStoringPC();
          }

            MetaDataManager mmgr = om.getStoreManager().getOMFContext().getMetaDataManager();
          boolean isPersistentInterface = mmgr.getMetaDataForInterface(clr.classForName(getType()), clr) != null;
          if (isPersistentInterface)
          {
              // Field is declared as a "persistent-interface" type so all impls of that type should match
              type = clr.classForName(getType());
          }
          else if (fmd != null && fmd.getFieldTypes() != null && fmd.getFieldTypes().length == 1)
          {
              isPersistentInterface = mmgr.getMetaDataForInterface(clr.classForName(fmd.getFieldTypes()[0]), clr) != null;
              if (isPersistentInterface)
              {
                  // Field is declared as interface and accepts "persistent-interface" value, so all impls should match
                  type = clr.classForName(fmd.getFieldTypes()[0]);
              }
View Full Code Here

        {
            return null;
        }

        AbstractPersistenceManagerFactory jpoxPMF = (AbstractPersistenceManagerFactory)pmf;
        MetaDataManager mdmgr = jpoxPMF.getOMFContext().getMetaDataManager();
        return (ClassMetaData)mdmgr.getMetaDataForClass(cls, jpoxPMF.getOMFContext().getClassLoaderResolver(null));
    }
View Full Code Here

        {
            // Find the names of the classes to be processed
            // This will load up all MetaData for the specified input and throw exceptions where errors are found
            try
            {
                MetaDataManager metaDataMgr = ((ObjectManagerFactoryImpl)pmf).getOMFContext().getMetaDataManager();
                ClassLoaderResolver clr = ((ObjectManagerFactoryImpl)pmf).getOMFContext().getClassLoaderResolver(null);

                FileMetaData[] filemds = getFileMetaDataForInput(metaDataMgr, clr, tool.isVerbose(),
                    tool.getStringProperty("org.jpox.PersistenceUnitName"), tool.getDefaultArgs());
                classNames = new ArrayList();
View Full Code Here

            }

            Class cls = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.cls : parentExpr.getCandidateClass());
            ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
            MetaDataManager mmgr = query.getObjectManager().getMetaDataManager();
            MappedStoreManager storeMgr = (MappedStoreManager)query.getStoreManager();
            AbstractClassMetaData leftCmd = mmgr.getMetaDataForClass(cls, clr);
            LogicSetExpression leftTblExpr = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.tableExpression : parentExpr.getMainTableExpression());
            String leftAlias = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.alias : parentExpr.getCandidateAlias());
            DatastoreClass leftTable = (DatastoreClass)leftTblExpr.getMainTable();
            for (int i=1;i<tokens.length;i++)
            {
                // Process the join from the previous token to this token
                AbstractMemberMetaData leftMmd = leftCmd.getMetaDataForMember(tokens[i]);
                AbstractClassMetaData rightCmd = null;
                int relationType = leftMmd.getRelationType(clr);
                AbstractMemberMetaData rightMmd = null;
                if (relationType == Relation.ONE_TO_ONE_BI || relationType == Relation.ONE_TO_MANY_BI ||
                    relationType == Relation.MANY_TO_MANY_BI || relationType == Relation.MANY_TO_ONE_BI)
                {
                    rightMmd = leftMmd.getRelatedMemberMetaData(clr)[0]; // Take first possible
                }

                // Find class of right hand side
                if (i == tokens.length-1)
                {
                    cls = candidateClass;
                }
                else
                {
                    if (relationType == Relation.ONE_TO_ONE_BI ||
                        relationType == Relation.ONE_TO_ONE_UNI ||
                        relationType == Relation.MANY_TO_ONE_BI)
                    {
                        cls = leftMmd.getType();
                        rightCmd = mmgr.getMetaDataForClass(cls, clr);
                    }
                    else if (relationType == Relation.ONE_TO_MANY_BI ||
                        relationType == Relation.ONE_TO_MANY_UNI ||
                        relationType == Relation.MANY_TO_MANY_BI)
                    {
                        if (leftMmd.hasCollection())
                        {
                            cls = clr.classForName(leftMmd.getCollection().getElementType());
                            rightCmd = mmgr.getMetaDataForClass(cls, clr);
                        }
                        else if (leftMmd.hasMap())
                        {
                            cls = clr.classForName(leftMmd.getMap().getValueType());
                            rightCmd = mmgr.getMetaDataForClass(cls, clr);
                        }
                    }
                    else
                    {
                        throw new JPOXUserException("Subquery has been specified with a candidate-expression that" +
View Full Code Here

        String msg = null;
        ClassLoaderResolver clr = omfContext.getClassLoaderResolver(null);

        // Obtain a MetaDataManager to work with
        MetaDataManager metaDataMgr = omfContext.getMetaDataManager();
        metaDataMgr.setEnhancing();
        String metadataFactory = getClassEnhancerMetadataFactoryName();
        if (!StringUtils.isWhitespace(metadataFactory))
        {
            try
            {
                Class factoryCls = clr.classForName(metadataFactory);
                MetaDataFactory factory = (MetaDataFactory)ClassUtils.newInstance(factoryCls,
                    new Class[] {MetaDataManager.class}, new Object[] {metaDataMgr});
                metaDataMgr.setMetaDataFactory(factory);
            }
            catch (Exception e)
            {
                throw new JPOXUserException(e.getMessage(), e);
            }
        }

        // Obtain MetaData for all classes to be processed
        long startTime = System.currentTimeMillis();
        FileMetaData[] filemds = null;
        String puName = getStringProperty("org.jpox.PersistenceUnitName");
        if (puName != null)
        {
            // Enhancement via "persistence-unit"
            if (isVerbose())
            {
                msg = LOCALISER.msg("Enhancer.PersistenceUnit", puName);
                addMessage(msg);
            }

            PersistenceUnitMetaData pumd = null;
            try
            {
                pumd = metaDataMgr.getMetaDataForPersistenceUnit(puName);
            }
            catch (JPOXException jpe)
            {
                // No "persistence.xml" files found yet they have specified a persistence-unit name!
                throw new JPOXUserException(LOCALISER.msg("Enhancer.PersistenceUnit.NoPersistenceFiles", puName));
            }

            if (pumd == null)
            {
                throw new JPOXUserException(LOCALISER.msg("Enhancer.PersistenceUnit.NoSuchUnit", puName));
            }

            // Initialise the MetaDataManager using the mapping files and classes
            filemds = metaDataMgr.initialise(pumd, clr);
        }
        else
        {
            // Enhancement via "Input Files" (jdo/class) on command line
            String[] inputfiles = getDefaultArgs();
            if (inputfiles == null)
            {
                msg = LOCALISER.msg("Enhancer.NoInputFilesError");
                JPOXLogger.ENHANCER.error(msg);
                throw new JPOXUserException(msg);
            }

            if (isVerbose())
            {
                msg = LOCALISER.msg("Enhancer.InputFiles");
                addMessage(msg);
                for (int i = 0; i < inputfiles.length; i++)
                {
                    String entry = LOCALISER.msg("Enhancer.InputFiles.Entry", inputfiles[i]);
                    JPOXLogger.ENHANCER.info(entry);
                    System.out.println(entry);
                }
                addMessage("");
            }

            // Read in the specified MetaData files - errors in MetaData will return exceptions and so we stop
            Class classEnhancerClass = getClassEnhancerClass(clr);
            try
            {
                // Split the input files into MetaData files and classes
                JPOXLogger.ENHANCER.debug(LOCALISER.msg("Enhancer.ReadInputFilesStart", "" + inputfiles.length));
                HashSet metadataFiles = new HashSet();
                HashSet classNames = new HashSet();
                for (int i=0;i<inputfiles.length;i++)
                {
                    if (inputfiles[i].endsWith(".class"))
                    {
                        if (!StringUtils.getFileForFilename(inputfiles[i]).exists())
                        {
                            msg = LOCALISER.msg("Enhancer.InputFiles.Invalid", inputfiles[i]);
                            if (systemOut)
                            {
                                System.out.println(msg);
                            }
                            JPOXLogger.ENHANCER.error(msg);
                        }
                        else
                        {
                            // Class file so get the name of the class for this file
                            try
                            {
                                Method method = classEnhancerClass.getMethod("getClassNameForFileName",
                                    new Class[] {String.class});
                                String className = (String)method.invoke(null, new String[] {inputfiles[i]});
                                classNames.add(className);
                            }
                            catch (InvocationTargetException ex)
                            {
                                msg = LOCALISER.msg("Enhancer.ClassEnhancer.MethodNotFound",
                                    enhancerName, classEnhancerClass.getName(), "getClassNameForFileName", ex.getTargetException());
                                if (systemOut)
                                {
                                    System.out.println(msg);
                                }
                                JPOXLogger.ENHANCER.error(msg);
                            }
                            catch (Exception e)
                            {
                                msg = LOCALISER.msg("Enhancer.ClassEnhancer.MethodNotFound",
                                    enhancerName, classEnhancerClass.getName(), "getClassNameForFileName", e);
                                if (systemOut)
                                {
                                    System.out.println(msg);
                                }
                                JPOXLogger.ENHANCER.error(msg);
                            }
                        }
                    }
                    else
                    {
                        // MetaData file
                        metadataFiles.add(inputfiles[i]);
                    }
                }

                // Initialise the MetaDataManager using the mapping files and class names
                filemds = metaDataMgr.initialise((String[])metadataFiles.toArray(new String[metadataFiles.size()]),
                    (String[])classNames.toArray(new String[classNames.size()]), clr);
                JPOXLogger.ENHANCER.debug(LOCALISER.msg("Enhancer.ReadInputFilesEnd", "" + inputfiles.length));
            }
            catch (JPOXException jpe)
            {
View Full Code Here

        {
            throw new IllegalArgumentException("Contents of file is null");
        }

        OMFContext context = new OMFContext(new PersistenceConfiguration(){});
        MetaDataManager mgr = new JDOMetaDataManager(context);
        mgr.setEnhancing();
        mgr.setMetaDataFactory(getMetaDataFactory(mgr));
        MetaDataParser parser = new MetaDataParser(mgr, true);
        JDOClassLoaderResolver clr = new JDOClassLoaderResolver();

        // Parse the MetaData
        FileMetaData filemd = (FileMetaData)parser.parseMetaDataStream(
            new ByteArrayInputStream(jdoXmlContents.getBytes()), null, "JDO");
        if (filemd == null)
        {
            return null;
        }
        mgr.registerFile("EnhancerTestXMLFile", filemd, clr);

        // Populate/Initialise the MetaData for the actual classes.
        for (int i=0;i<filemd.getNoOfPackages();i++)
        {
            PackageMetaData pmd = filemd.getPackage(i);
View Full Code Here

                        il.append(BCELUtils.getBIPUSH(i));

                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(fieldConfig.getType(),
                            enhancer.getClassLoaderResolver());
                        if (cmd != null && cmd.getIdentityType() != IdentityType.NONDURABLE)
                        {
                            //jdoGetPersistenceManager().getObjectById(id.field,false)
                            //  jdoGetPersistenceManager
                            il.append(InstructionConstants.ALOAD_0);
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceCapable, ClassEnhancer.MN_JdoGetPersistenceManager,
                                BCELClassEnhancer.OT_PersistenceManager, Type.NO_ARGS, Constants.INVOKEINTERFACE));
                            //  getObjectById(id.field,false)
                            //  id.field
                            createGetField(
                                oidClassName,
                                fieldConfig.getName(),
                                new ObjectType(cmd.getObjectidClass()),
                                fieldConfig.isProperty(),
                                getModifiers(oidClassName, fieldConfig.getName()),
                                new ALOAD(3));

                            //  false
                            il.append(InstructionConstants.ICONST_0);
                            //  getObjectById
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceManager, "getObjectById", Type.OBJECT,
                                new Type[]{Type.OBJECT, Type.BOOLEAN}, Constants.INVOKEINTERFACE));
                            il.append(factory.createCast(Type.OBJECT, ((BCELFieldPropertyMetaData)fieldConfig).getEnhanceField().getType()));
                        }
                        else
                        {
                            if (mgr.getApiAdapter().isSingleFieldIdentityClass(oidClassName))
                            {
                                Type getKeyReturnType = field.getType();
                                if (oidClassName.equals(LongIdentity.class.getName()))
                                {
                                    getKeyReturnType = Type.LONG;
View Full Code Here

                    if (fieldConfig.isPrimaryKey())
                    {
                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(fieldConfig.getType(),
                            enhancer.getClassLoaderResolver());
                        BCELMember fieldMethod = ((BCELFieldPropertyMetaData)fieldConfig).getEnhanceField();
                        if (cmd != null && cmd.getIdentityType() != IdentityType.NONDURABLE)
                        {
                            // Identifying Relationships (PC field as primary key)
                            il.append(InstructionConstants.ALOAD_0);
                            //jdoGetPersistenceManager().getObjectById(id.field,false)
                            //  jdoGetPersistenceManager
                            il.append(InstructionConstants.ALOAD_0);
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceCapable, ClassEnhancer.MN_JdoGetPersistenceManager,
                                BCELClassEnhancer.OT_PersistenceManager, Type.NO_ARGS, Constants.INVOKEINTERFACE));

                            //  getObjectById(id.field,false)
                            //  id.field

                            createGetField(
                                objectIdClass,
                                fieldConfig.getName(),
                                new ObjectType(cmd.getObjectidClass()),
                                fieldConfig.isProperty(),
                                getModifiers(objectIdClass, fieldConfig.getName()),
                                InstructionFactory.createLoad(objectIdClassType, objectIdInstance));

                            //  false
                            il.append(InstructionConstants.ICONST_0);

                            //  getObjectById
                            il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceManager, "getObjectById", Type.OBJECT,
                                new Type[]{Type.OBJECT, Type.BOOLEAN}, Constants.INVOKEINTERFACE));
                            il.append(factory.createCast(Type.OBJECT, fieldMethod.getType()));

                            createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
                        }
                        else
                        {
                            // Single Field Identity
                            if (mgr.getApiAdapter().isSingleFieldIdentityClass(objectIdClass))
                            {
                                if (Object.class.isAssignableFrom(fieldConfig.getType()) && fieldConfig.getType() != String.class)
                                {
                                    // Object wrapper type
                                    Type primitiveType = null;
View Full Code Here

                        }

                        //support for identifying relationships
                        //if the class has metadata, it is PersistenceCapable
                        //add JDOHelper.getObjectId(fieldXXXX);
                        MetaDataManager mgr = cmd.getMetaDataManager();
                        AbstractClassMetaData cmd = mgr.getMetaDataForClass(f.getType(), enhancer.getClassLoaderResolver());
                        if (cmd != null)
                        {
                            il.append(
                                factory.createInvoke(
                                    ClassEnhancer.CN_JDOHelper,
View Full Code Here

TOP

Related Classes of org.jpox.metadata.MetaDataManager

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.