Package org.apache.tuscany.das.rdb

Examples of org.apache.tuscany.das.rdb.ConfigHelper


    }

    public void testCreateEmptyGraphAndAddCustomer() throws Exception {
        String typeUri = "http:///org.apache.tuscany.das.rdb.test/customer.xsd";
        SDOUtil.registerStaticTypes(CustomerFactory.class);
        ConfigHelper helper = new ConfigHelper();
        helper.setDataObjectModel(typeUri);
        helper.addTable("CUSTOMER", "Customer");
        helper.addPrimaryKey("CUSTOMER.ID");

        DataObject graph = new GraphMerger().emptyGraph(helper.getConfig());
        Customer c = (Customer) graph.createDataObject("Customer");
        c.setID(4000);
        c.setLastName("Smith");
        c.setAddress("400 Fourth Street");

        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
        das.applyChanges(graph);

        Command cmd = das.createCommand("select * from CUSTOMER order by ID desc");
        graph = cmd.executeQuery();
        assertEquals(6, graph.getList("Customer").size());
View Full Code Here


    }

    public void testProvidedConfig() throws Exception {
        // Create config programmatically
        Config config = ConfigFactory.INSTANCE.createConfig();
        ConfigHelper helper = new ConfigHelper(config);
        helper.addPrimaryKey("BOOK.BOOK_ID");
        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());

        // Read a book instance
        Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
View Full Code Here

   
    protected DAS initializeDAS(String config, ConnectionInfo connectionInfo, String table, String pkColumns) throws MissingConfigFileException {
        //load the config file
        //System.out.println("Initializing DAS");
       
        ConfigHelper configHelper;
       
        if(config == null) {
            //no config information
            configHelper = new ConfigHelper();   
        } else {
            //initialize the config helper by loading config file
            configHelper = new ConfigHelper(this.getConfigStream(config));
        }
       
        //add additional connectionInfo if provided in the SCA Composite file
        if( connectionInfo != null) {
            String dataSource = connectionInfo.getDataSource();
            if(dataSource != null && dataSource.length() > 0) {
                configHelper.addConnectionInfo(dataSource);
            } else {
                String driverClass = connectionInfo.getConnectionProperties().getDriverClass();
                String connectionURL = connectionInfo.getConnectionProperties().getDatabaseURL();
                String userName = connectionInfo.getConnectionProperties().getUsername();
                String password = connectionInfo.getConnectionProperties().getPassword();
                int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout();

                configHelper.addConnectionInfo(driverClass, connectionURL, userName, password, loginTimeout);
            }
           
        }
       
        if(table != null && pkColumns != null) {
            MappingWrapper configWrapper = new MappingWrapper(configHelper.getConfig());
            List<String> pkColsList = DataAccessEngine.getKeys(pkColumns);
            for(int i=0; i<pkColsList.size(); i++) {
              configWrapper.addPrimaryKey(table+"."+pkColsList.get(i), pkColsList.get(i));
            }                 
        }
       
        DAS das = DAS.FACTORY.createDAS(configHelper.getConfig());
       
        return das;     
    }
View Full Code Here

    public void testCreateEmptyGraph() throws Exception {
        String typeUri = "http:///org.apache.tuscany.das.rdb.test/customer.xsd";
        HelperContext context = HelperProvider.getDefaultContext();
        CustomerFactory.INSTANCE.register(context)
        ConfigHelper helper = new ConfigHelper();
        helper.setDataObjectModel(typeUri);
        DataObject graph = new GraphMerger().emptyGraph(helper.getConfig());
        assertEquals(0, graph.getList("Customer").size());
        assertEquals(0, graph.getList("AnOrder").size());

    }
View Full Code Here

    public void testCreateEmptyGraphAndAddCustomer() throws Exception {
        String typeUri = "http:///org.apache.tuscany.das.rdb.test/customer.xsd";
        HelperContext context = HelperProvider.getDefaultContext();
        CustomerFactory.INSTANCE.register(context);
        ConfigHelper helper = new ConfigHelper();
        helper.setDataObjectModel(typeUri);
        helper.addTable("CUSTOMER", "Customer");
        helper.addPrimaryKey("CUSTOMER.ID");

        DataObject graph = new GraphMerger().emptyGraph(helper.getConfig());
        Customer c = (Customer) graph.createDataObject("Customer");
        c.setID(4000);
        c.setLastName("Smith");
        c.setAddress("400 Fourth Street");

        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
        das.applyChanges(graph);

        Command cmd = das.createCommand("select * from CUSTOMER order by ID desc");
        graph = cmd.executeQuery();
        assertEquals(6, graph.getList("Customer").size());
View Full Code Here

        super.tearDown();
    }
   
    //<Config> useGetGeneratedKeys set to TRUE - Company
    public void testInsert() throws Exception {
      ConfigHelper helper = new ConfigHelper();
        Config config = helper.getConfig();
        config.setGeneratedKeysSupported("true");
       
        DAS das = DAS.FACTORY.createDAS(config, getConnection());
        Command insert = das.createCommand("insert into COMPANY (NAME) values (?)");
        insert.setParameter(1, "AAA Rental");
View Full Code Here

        assertEquals(key, root.get("COMPANY[1]/ID"));
    }

    //<Config> useGetGeneratedKeys not set - Company (should work as default TRUE)
    public void testInsert1() throws Exception {
        ConfigHelper helper = new ConfigHelper();
        Config config = helper.getConfig();
     
        DAS das = DAS.FACTORY.createDAS(config, getConnection());
        Command insert = das.createCommand("insert into COMPANY (NAME) values (?)");
        insert.setParameter(1, "AAA Rental");
        insert.execute();
View Full Code Here

    }
   
    //<Config> useGetGeneratedKeys set to FALSE - Company -
    // exception as insert.getGen..Keys will throw RuntimeException
    public void testInsert2() throws Exception {
        ConfigHelper helper = new ConfigHelper();
        Config config = helper.getConfig();
        config.setGeneratedKeysSupported("false");

        DAS das = DAS.FACTORY.createDAS(config, getConnection());
        Command insert = das.createCommand("insert into COMPANY (NAME) values (?)");
        insert.setParameter(1, "AAA Rental");
View Full Code Here

    }

    public void testProvidedConfig() throws SQLException  {
        // Create config programmatically
        Config config = ConfigFactory.INSTANCE.createConfig();
        ConfigHelper helper = new ConfigHelper(config);
        helper.addPrimaryKey("BOOK.BOOK_ID");
        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());

        // Read a book instance
        Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
View Full Code Here

    /**
     * Simple unit test for ConnectionInfo
     * @throws Exception
     */
    public void testConnectionInfo2() throws Exception {
        ConfigHelper helper = new ConfigHelper();
        helper.addConnectionInfo("jdbc/adatasource", false);

        Config config = helper.getConfig();
        ConnectionInfo info = config.getConnectionInfo();
        assertEquals(info.getDataSource(), "jdbc/adatasource");
        assertEquals(info.isManagedtx(), false);
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.das.rdb.ConfigHelper

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.