Package org.apache.cayenne.access

Examples of org.apache.cayenne.access.DbLoader


        DbImportAction action = i.getInstance(DbImportAction.class);

        DbImportParameters parameters = new DbImportParameters();
        parameters.setUsePrimitives(true);

        DbLoader loader1 = action.createLoader(parameters, mock(DbAdapter.class), mock(Connection.class),
                mock(DbLoaderDelegate.class));

        DataMap map = new DataMap();

        DbEntity e1 = new DbEntity("e1");
        DbAttribute nonPk = new DbAttribute("nonPk", Types.INTEGER, e1);
        e1.addAttribute(nonPk);

        map.addDbEntity(e1);

        // DbLoader is so ugly and hard to test..
        Field dbEntityList = DbLoader.class.getDeclaredField("dbEntityList");
        dbEntityList.setAccessible(true);
        List<DbEntity> entities = (List<DbEntity>) dbEntityList.get(loader1);
        entities.add(e1);

        loader1.loadObjEntities(map);

        ObjEntity oe1 = map.getObjEntity("E1");

        ObjAttribute oa1 = (ObjAttribute) oe1.getAttribute("nonPk");
        assertEquals("int", oa1.getType());
View Full Code Here


        DbImportDbLoaderDelegate loaderDelegate = new DbImportDbLoaderDelegate();

        Connection connection = dataSource.getConnection();

        try {
            DbLoader loader = createLoader(parameters, adapter, connection, loaderDelegate);

            String[] types = loader.getDefaultTableTypes();
            loader.load(dataMap, parameters.getCatalog(), parameters.getSchema(), parameters.getTablePattern(), types);

            for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
                DeleteRuleUpdater.updateObjEntity(addedObjEntity);
            }

            if (parameters.isImportProcedures()) {
                loader.loadProcedures(dataMap, parameters.getCatalog(), parameters.getSchema(),
                        parameters.getProcedurePattern());
            }
        } finally {
            connection.close();
        }
View Full Code Here

        String meangfulPkExclude = parameters.getMeaningfulPkTables() != null ? null : "*";
        final NamePatternMatcher meaningfulPkFilter = new NamePatternMatcher(logger,
                parameters.getMeaningfulPkTables(), meangfulPkExclude);

        DbLoader loader = new DbLoader(connection, adapter, loaderDelegate) {
            @Override
            public boolean includeTableName(String tableName) {
                return nameFilter.isIncluded(tableName);
            }

            @Override
            protected EntityMergeSupport createEntityMerger(DataMap map) {
                EntityMergeSupport emSupport = new EntityMergeSupport(map, namingStrategy, true) {

                    @Override
                    protected boolean removePK(DbEntity dbEntity) {
                        return !meaningfulPkFilter.isIncluded(dbEntity.getName());
                    }
                };

                emSupport.setUsePrimitives(parameters.isUsePrimitives());
                return emSupport;
            }
        };

        // TODO: load via DI AdhocObjectFactory
        String namingStrategy = parameters.getNamingStrategy();
        if (namingStrategy != null) {
            NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(namingStrategy).newInstance();
            loader.setNamingStrategy(namingStrategyInst);
        }

        return loader;
    }
View Full Code Here

    public DbLoaderHelper(ProjectController mediator, Connection connection,
            DbAdapter adapter, String dbUserName) {
        this.dbUserName = dbUserName;
        this.mediator = mediator;
        this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
    }
View Full Code Here

            // load driver taking custom CLASSPATH into account...
            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url, username, password);

            // Load the data map and run the db importer.
            final LoaderDelegate loaderDelegate = new LoaderDelegate();
            final DbLoader loader = new DbLoader(dataSource.getConnection(), adapterInst, loaderDelegate);
            loader.setCreatingMeaningfulPK(meaningfulPk);

            if (namingStrategy != null) {
                final NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(namingStrategy).newInstance();
                loader.setNamingStrategy(namingStrategyInst);
            }

            mapFile = new File(map);
            final DataMap dataMap = mapFile.exists() ? loadDataMap() : new DataMap();
            loader.loadDataMapFromDB(schemaName, tablePattern, dataMap);

            for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
                DeleteRuleUpdater.updateObjEntity(addedObjEntity);
            }

            if (importProcedures) {
                loader.loadProceduresFromDB(schemaName, procedurePattern, dataMap);
            }

            // Write the new DataMap out to disk.
            mapFile.delete();
            PrintWriter pw = new PrintWriter(mapFile);
View Full Code Here

    public DbLoaderHelper(ProjectController mediator, Connection connection,
            DbAdapter adapter, String dbUserName) {
        this.dbUserName = dbUserName;
        this.mediator = mediator;
        this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
    }
View Full Code Here

            // load driver taking custom CLASSPATH into account...
            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url, userName, password);

            // Load the data map and run the db importer.
            final LoaderDelegate loaderDelegate = new LoaderDelegate();
            final DbLoader loader = new DbLoader(dataSource.getConnection(), adapter, loaderDelegate);
            loader.setCreatingMeaningfulPK(meaningfulPk);

            if (namingStrategy != null) {
                final NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(namingStrategy).newInstance();
                loader.setNamingStrategy(namingStrategyInst);
            }

            final DataMap dataMap = map.exists() ? loadDataMap() : new DataMap();
            loader.loadDataMapFromDB(schemaName, tablePattern, dataMap);

            for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
                DeleteRuleUpdater.updateObjEntity(addedObjEntity);
            }

            if (importProcedures) {
                loader.loadProceduresFromDB(schemaName, procedurePattern, dataMap);
            }

            // Write the new DataMap out to disk.
            map.delete();
            PrintWriter pw = new PrintWriter(map);
View Full Code Here

    public DbLoaderHelper(ProjectController mediator, Connection connection,
            DbAdapter adapter, String dbUserName) {
        this.dbUserName = dbUserName;
        this.mediator = mediator;
        this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
    }
View Full Code Here

    public DbLoaderHelper(ProjectController mediator, Connection connection,
            DbAdapter adapter, String dbUserName) {
        this.dbUserName = dbUserName;
        this.mediator = mediator;
        this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
    }
View Full Code Here

            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(
                    driver).newInstance(), url, userName, password);

            // Load the data map and run the db importer.
            final LoaderDelegate loaderDelegate = new LoaderDelegate();
            final DbLoader loader = new DbLoader(
                    dataSource.getConnection(),
                    adapter,
                    loaderDelegate);
            loader.setCreatingMeaningfulPK(meaningfulPk);

            if (namingStrategy != null) {
                final NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(
                        namingStrategy).newInstance();
                loader.setNamingStrategy(namingStrategyInst);
            }

            final DataMap dataMap = map.exists() ? loadDataMap() : new DataMap();
            loader.loadDataMapFromDB(schemaName, tablePattern, dataMap);

            for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
                DeleteRuleUpdater.updateObjEntity(addedObjEntity);
            }

            if (importProcedures) {
                loader.loadProceduresFromDB(schemaName, procedurePattern, dataMap);
            }

            // Write the new DataMap out to disk.
            map.delete();
            PrintWriter pw = new PrintWriter(map);
View Full Code Here

TOP

Related Classes of org.apache.cayenne.access.DbLoader

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.