Package org.apache.cayenne.di

Examples of org.apache.cayenne.di.Injector


                binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
                binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);

        final Map<String, String> properties = new HashMap<String, String>();

        properties.put(PropertyDataSourceFactory.JDBC_DRIVER_PROPERTY, "x");
        properties.put(PropertyDataSourceFactory.JDBC_URL_PROPERTY, "y");
        DefaultDataSourceFactoryLoader factoryLoader = new DefaultDataSourceFactoryLoader() {

            @Override
            protected String getProperty(String key) {
                return properties.get(key);
            }
        };
        injector.injectMembers(factoryLoader);

        DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);
View Full Code Here


    protected boolean attachToRuntimeIfNeeded() {
        if (channel != null) {
            return false;
        }

        Injector injector = CayenneRuntime.getThreadInjector();
        if (injector == null) {
            throw new CayenneRuntimeException("Can't attach to Cayenne runtime. "
                    + "Null injector returned from CayenneRuntime.getThreadInjector()");
        }
View Full Code Here

    protected boolean createFK = true;

    @Override
    public void execute() {
       
        Injector injector = DIBootstrap.createInjector(new ToolModule());
        AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);

        // prepare defaults
        if (adapter == null) {
            adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
        }
View Full Code Here

    protected Main(String[] args) {
        this.args = args;
    }

    protected void launch() {
        final Injector injector = DIBootstrap
                .createInjector(appendModules(new ArrayList<Module>()));

        logger.info("Starting CayenneModeler.");
        logger.info("JRE v."
                + System.getProperty("java.version")
                + " at "
                + System.getProperty("java.home"));

        // init look and feel before starting any Swing classes...
        injector.getInstance(PlatformInitializer.class).initLookAndFeel();

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {

                Application application = injector.getInstance(Application.class);
                Application.setInstance(application);
                application.startup();

                // start initial project AFTER the app startup, as we need Application
                // preferences to be bootstrapped.
View Full Code Here

     *
     * @param adapter The db adapter to set.
     */
    public void setAdapter(String adapter) {
        if (adapter != null) {
            Injector injector = DIBootstrap.createInjector(new ToolModule());
            AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
           
            this.adapter = objectFactory.newInstance(DbAdapter.class, adapter);
        }
    }
View Full Code Here

                binder.bind(ConfigurationNameMapper.class).to(
                        DefaultConfigurationNameMapper.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);
        injector.injectMembers(loader);

        String testConfigName = "PROJECT1";
        String baseUrl = getClass().getPackage().getName().replace('.', '/');
        URL url = getClass().getClassLoader().getResource(
                baseUrl + "/cayenne-" + testConfigName + ".xml");
View Full Code Here

                        DefaultConfigurationNameMapper.class);
            }
        };

        FileProjectSaver saver = new FileProjectSaver();
        Injector injector = DIBootstrap.createInjector(testModule);
        injector.injectMembers(saver);

        DataChannelDescriptor rootNode = new DataChannelDescriptor();
        rootNode.setName("test");

        // add maps and nodes in reverse alpha order. Check that they are saved in alpha
View Full Code Here

                binder.bind(ConfigurationNameMapper.class).to(
                        DefaultConfigurationNameMapper.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);
        injector.injectMembers(saver);

        String testConfigName = "PROJECT2";
        String baseUrl = getClass().getPackage().getName().replace('.', '/');
        URL url = getClass().getClassLoader().getResource(
                baseUrl + "/cayenne-" + testConfigName + ".xml");

        Resource source = new URLResource(url);
        Project project = injector.getInstance(ProjectLoader.class).loadProject(source);

        File outFile = setupTestDirectory("testSave");

        saver.saveAs(project, new URLResource(outFile.toURL()));
View Full Code Here

                binder.bind(ConfigurationNameMapper.class).to(
                        DefaultConfigurationNameMapper.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);
        injector.injectMembers(saver);

        String testConfigName = "PROJECT2";
        String baseUrl = getClass().getPackage().getName().replace('.', '/');
        URL url = getClass().getClassLoader().getResource(
                baseUrl + "/cayenne-" + testConfigName + ".xml");

        Resource source = new URLResource(url);
        Project project = injector.getInstance(ProjectLoader.class).loadProject(source);

        File outFile = setupTestDirectory("testSaveAs_RecoverFromSaveError");
        assertEquals(0, outFile.list().length);

        try {
View Full Code Here

public class CayenneRuntimeTest extends TestCase {

    public void testBindThreadInjector() {

        Injector injector = mock(Injector.class);

        assertNull(CayenneRuntime.getThreadInjector());

        try {
            CayenneRuntime.bindThreadInjector(injector);
View Full Code Here

TOP

Related Classes of org.apache.cayenne.di.Injector

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.