Package org.apache.openjpa.meta

Examples of org.apache.openjpa.meta.MetaDataFactory


     * create a new repository and sets it.
     */
    public MetaDataRepository getRepository() {
        if (_repos == null) {
            MetaDataRepository repos = _conf.newMetaDataRepositoryInstance();
            MetaDataFactory mdf = repos.getMetaDataFactory();
            if (mdf instanceof DelegatingMetaDataFactory)
                mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
            if (mdf instanceof PersistenceMetaDataFactory)
                ((PersistenceMetaDataFactory) mdf).setAnnotationParser(this);
            _repos = repos;
View Full Code Here


        {
            mappings[i].setResolve(MODE_META | MODE_MAPPING, true);
            mappings[i].setUseSchemaElement(getUseSchemaElement());
        }
        // store in user's configured IO
        MetaDataFactory mdf = _conf.newMetaDataFactoryInstance();
        mdf.setRepository(getRepository());
        mdf.setStoreDirectory(_dir);
        if (perClass)
            mdf.setStoreMode(MetaDataFactory.STORE_PER_CLASS);
        mdf.store(mappings, new QueryMetaData[0], new SequenceMetaData[0],
            MODE_META | MODE_MAPPING, output);

        Set files = new TreeSet();
        for (int i = 0; i < mappings.length; i++)
            if (mappings[i].getSourceFile() != null)
View Full Code Here

        {
            mappings[i].setResolve(MODE_META | MODE_MAPPING, true);
            mappings[i].setUseSchemaElement(getUseSchemaElement());
        }
        // store in user's configured IO
        MetaDataFactory mdf = _conf.newMetaDataFactoryInstance();
        mdf.setRepository(getRepository());
        mdf.setStoreDirectory(_dir);
        mdf.store(mappings, new QueryMetaData[0], new SequenceMetaData[0],
            MODE_META | MODE_MAPPING | MODE_ANN_MAPPING, output);
        _annos = output;
    }
View Full Code Here

        record(null);
    }
   
    public void record(MappingTool.Flags flags) {
        MappingRepository repos = getRepository();
        MetaDataFactory io = repos.getMetaDataFactory();
        ClassMapping[] mappings;
       
        if (!ACTION_DROP.equals(_action))
            mappings = repos.getMappings();
        else if (_dropMap != null)
            mappings = (ClassMapping[]) _dropMap.toArray
                (new ClassMapping[_dropMap.size()]);
        else
            mappings = new ClassMapping[0];

        try {
            if (_dropCls != null && !_dropCls.isEmpty()) {
                Class<?>[] cls = (Class[]) _dropCls.toArray
                    (new Class[_dropCls.size()]);
                if (!io.drop(cls, _mode, null))
                    _log.warn(_loc.get("bad-drop", _dropCls));
            }

            if (_flushSchema) {
                // drop portions of the known schema that no mapping uses, and
                // add sequences used for value generation
                if (_dropUnused)
                    dropUnusedSchemaComponents(mappings);
                addSequenceComponents(mappings);

                // now run the schematool as long as we're doing some schema
                // action and the user doesn't just want an xml output
                String[] schemaActions = _schemaActions.split(",");
                for (int i = 0; i < schemaActions.length; i++) {
                    if (!SCHEMA_ACTION_NONE.equals(schemaActions[i])
                        && (_schemaWriter == null || (_schemaTool != null
                            && _schemaTool.getWriter() != null))) {
                        SchemaTool tool = newSchemaTool(schemaActions[i]);

                        // configure the tool with additional settings
                        if (flags != null) {
                            tool.setDropTables(flags.dropTables);
                            tool.setDropSequences(flags.dropSequences);
                            tool.setWriter(flags.sqlWriter);
                            tool.setOpenJPATables(flags.openjpaTables);
                            tool.setSQLTerminator(flags.sqlTerminator);
                        }

                        tool.setSchemaGroup(getSchemaGroup());
                        tool.run();
                        tool.record();
                        tool.clear();
                    }
                }

                // xml output of schema?
                if (_schemaWriter != null) {
                    // serialize the planned schema to the stream
                    SchemaSerializer ser = new XMLSchemaSerializer(_conf);
                    ser.addAll(getSchemaGroup());
                    ser.serialize(_schemaWriter, MetaDataSerializer.PRETTY);
                    _schemaWriter.flush();
                }
            }
            if (!_flush)
                return;

            QueryMetaData[] queries = repos.getQueryMetaDatas();
            SequenceMetaData[] seqs = repos.getSequenceMetaDatas();
            Map<File, String> output = null;

            // if we're outputting to stream, set all metas to same file so
            // they get placed in single string
            if (_mappingWriter != null) {
                output = new HashMap<File, String>();
                File tmp = new File("openjpatmp");
                for (int i = 0; i < mappings.length; i++) {
                    mappings[i].setSource(tmp, SourceTracker.SRC_OTHER, "openjpatmp");
                }
                for (int i = 0; i < queries.length; i++) {
                    queries[i].setSource(tmp, queries[i].getSourceScope(), SourceTracker.SRC_OTHER, "openjpatmp");
                }
                for (int i = 0; i < seqs.length; i++)
                    seqs[i].setSource(tmp, seqs[i].getSourceScope(),
                        SourceTracker.SRC_OTHER);
            }

            // store
            if (!io.store(mappings, queries, seqs, _mode, output))
                throw new MetaDataException(_loc.get("bad-store"));

            // write to stream
            if (_mappingWriter != null) {
                PrintWriter out = new PrintWriter(_mappingWriter);
View Full Code Here

            return;

        _flush = true;
        MappingRepository repos = getRepository();
        repos.setResolve(MODE_MAPPING, false);
        MetaDataFactory factory = repos.getMetaDataFactory();
        factory.getDefaults().setIgnoreNonPersistent(false);
        factory.setStoreMode(MetaDataFactory.STORE_VERBOSE);

        ClassMetaData meta = repos.addMetaData(cls);
        FieldMetaData[] fmds = meta.getDeclaredFields();
        for (int i = 0; i < fmds.length; i++) {
            if (fmds[i].getDeclaredTypeCode() == JavaTypes.OBJECT
View Full Code Here

     * create a new repository and sets it.
     */
    public MetaDataRepository getRepository() {
        if (_repos == null) {
            MetaDataRepository repos = _conf.newMetaDataRepositoryInstance();
            MetaDataFactory mdf = repos.getMetaDataFactory();
            if (mdf instanceof DelegatingMetaDataFactory)
                mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
            if (mdf instanceof PersistenceMetaDataFactory)
                ((PersistenceMetaDataFactory) mdf).setAnnotationParser(this);
            _repos = repos;
View Full Code Here

    /**
     * Tell the metadata factory to load object id classes even if they don't
     * exist.
     */
    private static void loadObjectIds(MetaDataRepository repos, boolean fatal) {
        MetaDataFactory mdf = repos.getMetaDataFactory();
        if (mdf instanceof DelegatingMetaDataFactory)
            mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
        if (mdf instanceof ObjectIdLoader)
            ((ObjectIdLoader) mdf).setLoadObjectIds();
        else if (fatal)
View Full Code Here

            clsName = null;
            props = null;
        }

        // instantiate factories
        MetaDataFactory map = (MetaDataFactory) newInstance(clsName,
            MetaDataFactory.class, conf, fatal);
        MetaDataFactory meta;
        if (map != null
            && map.getClass().getName().indexOf("Deprecated") != -1) {
            // deprecated mapping factories take over metadata too, so we have
            // to special-case them to treat them like metadata factory only
            meta = map;
            map = null;
        } else {
            meta = (MetaDataFactory) metaPlugin.newInstance
                (metaClsName, MetaDataFactory.class, conf, fatal);
        }

        // configure factories.  if only meta factory, allow user to specify
        // its mapping properties in the mapping factory setting
        if (map == null && props != null) {
            if (metaProps == null)
                metaProps = props;
            else
                metaProps += ", " + props;
        }
        Configurations.configureInstance(map, conf, props,
            (fatal) ? getProperty() : null);
        Configurations.configureInstance(meta, conf, metaProps,
            (fatal) ? metaPlugin.getProperty() : null);

        Log log = conf.getLog(JDBCConfiguration.LOG_METADATA);
        if (log.isTraceEnabled()) {
            log.trace(_loc.get("meta-factory", meta));
            if (map != null)
                log.trace(_loc.get("map-factory", map));
        }

        // if no mapping setting, return meta factory alone, assuming it handles
        // both metadata and mapping
        MetaDataFactory ret = null;
        if(map == null ) {
            ret = meta;
        }
        else {
            if( conf instanceof OpenJPAConfiguration) {
View Full Code Here

     * a new repository and sets it.
     */
    public MetaDataRepository getRepository() {
        if (_repos == null) {
            MetaDataRepository repos = _conf.newMetaDataRepositoryInstance();
            MetaDataFactory mdf = repos.getMetaDataFactory();
            if (mdf instanceof DelegatingMetaDataFactory)
                mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
            if (mdf instanceof PersistenceMetaDataFactory)
                ((PersistenceMetaDataFactory) mdf).setXMLParser(this);
            _repos = repos;
View Full Code Here

     * create a new repository and sets it.
     */
    public MetaDataRepository getRepository() {
        if (_repos == null) {
            MetaDataRepository repos = _conf.newMetaDataRepositoryInstance();
            MetaDataFactory mdf = repos.getMetaDataFactory();
            if (mdf instanceof DelegatingMetaDataFactory)
                mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
            if (mdf instanceof PersistenceMetaDataFactory)
                ((PersistenceMetaDataFactory) mdf).setXMLAnnotationParser(this);
            _repos = repos;
View Full Code Here

TOP

Related Classes of org.apache.openjpa.meta.MetaDataFactory

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.