Package com.volantis.mcs.repository.jdbc

Examples of com.volantis.mcs.repository.jdbc.JDBCRepositoryConnection


        InternalJDBCRepository repository =
                factory.createRepository(
                        (InternalJDBCRepositoryConfiguration) configuration);

        JDBCRepositoryConnection connection = null;
        try {
            connection = (JDBCRepositoryConnection) repository.connect();
            connection.getConnection();

        } finally {
            connection.disconnect();
        }

        return repository;
    }
View Full Code Here


        locks = new HashMap();

        // Make sure that the connection is created.
        try {
            JDBCRepositoryConnection connection =
                    (JDBCRepositoryConnection) repository.connect();

            sqlConnection = connection.getConnection();

            // Turn auto commit off to enable atomic updates to be performed.
            sqlConnection.setAutoCommit(false);

            // Prepare all the statements.
View Full Code Here

    protected void closeConnection(RepositoryConnection connection)
            throws RepositoryException {

        // Cast the RepositoryConnection to a JDBCRepositoryConnectionImpl.
        JDBCRepositoryConnection jdbcConnection
                = (JDBCRepositoryConnection) connection;

        // Ask it to close the connection.
        jdbcConnection.closeConnection();
    }
View Full Code Here

        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {

                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, "#dp");
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultOrderedSetPolicyType type =
                        new DefaultOrderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "oset", descriptor);
                accessor.removePolicyDescriptor(connection, "oset");

                // Check the database contents are empty
                checkAllEmpty(conn);

                connection.disconnect();
                repository.terminate();
            }
        });
    }
View Full Code Here

        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {

                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, "#dp");
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultUnorderedSetPolicyType type =
                        new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "uset", descriptor);

                // Check the database contents
                checkCategoryRow(conn, null, 0, "category");
                checkPolicyTypeRow(conn, null, "uset", 0, 0);
                checkTypesRow(conn, "TYPE_INSTANCE_ID=0", 0, 6);
                // set row and dependent boolean type
                checkTypesSetRow(conn, null, 0, 1, true);
                checkTypesRow(conn, "TYPE_INSTANCE_ID=1", 1, 0);

                connection.disconnect();
                repository.terminate();
            }
        });
    }
View Full Code Here

        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {

                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, "#dp");
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultUnorderedSetPolicyType type =
                        new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "uset", descriptor);
                accessor.removePolicyDescriptor(connection, "uset");

                // Check the database contents are empty
                checkAllEmpty(conn);

                connection.disconnect();
                repository.terminate();
            }
        });
    }
View Full Code Here

        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {

                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, "#dp");
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();

                // boolean
                descriptor.setCategory("category1");
                descriptor.setPolicyType(new DefaultBooleanPolicyType());
                accessor.addPolicyDescriptor(connection, "bool1", descriptor);
                accessor.addPolicyDescriptor(connection, "bool2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // int
                descriptor.setPolicyType(new DefaultIntPolicyType());
                accessor.addPolicyDescriptor(connection, "int1", descriptor);
                accessor.addPolicyDescriptor(connection, "int2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // range
                descriptor.setPolicyType(new DefaultRangePolicyType(6, 9));
                accessor.addPolicyDescriptor(connection, "range1", descriptor);
                accessor.addPolicyDescriptor(connection, "range2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                typesRangeCount+=2;
                checkCounts(conn);

                // selection
                descriptor.setCategory("category2");
                DefaultSelectionPolicyType selection =
                        new DefaultSelectionPolicyType();
                selection.addKeyword("keyword1");
                selection.addKeyword("keyword2");
                selection.complete();
                descriptor.setPolicyType(selection);
                accessor.addPolicyDescriptor(connection, "selection1", descriptor);
                accessor.addPolicyDescriptor(connection, "selection2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=2;
                typesSelectionCount+=4;
                checkCounts(conn);

                // text
                descriptor.setPolicyType(new DefaultTextPolicyType());
                accessor.addPolicyDescriptor(connection, "text1", descriptor);
                accessor.addPolicyDescriptor(connection, "text2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // ordered set
                PolicyType oset = new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(oset);
                accessor.addPolicyDescriptor(connection, "oset1", descriptor);
                accessor.addPolicyDescriptor(connection, "oset2", descriptor);
                policyTypeCount+=2;
                typesCount+=4;
                typesSetCount+=2;
                checkCounts(conn);

                // unordered set
                descriptor.setCategory("category3");
                PolicyType uset = new DefaultUnorderedSetPolicyType(
                                new DefaultIntPolicyType());
                descriptor.setPolicyType(uset);
                accessor.addPolicyDescriptor(connection, "uset1", descriptor);
                accessor.addPolicyDescriptor(connection, "uset2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=4;
                typesSetCount+=2;
                checkCounts(conn);

                // structure
                DefaultStructurePolicyType type =
                        new DefaultStructurePolicyType();
                type.addFieldType("field1", new DefaultBooleanPolicyType());
                type.addFieldType("field2", new DefaultRangePolicyType(2, 99));
                type.complete();
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "structure1", descriptor);
                accessor.addPolicyDescriptor(connection, "structure2", descriptor);
                policyTypeCount+=2;
                typesCount+=6;
                typesStructureCount+=4;
                typesRangeCount+=2;
                checkCounts(conn);

                accessor.removePolicyDescriptor(connection, "bool1");
                accessor.removePolicyDescriptor(connection, "bool2");
                accessor.removePolicyDescriptor(connection, "int1");
                accessor.removePolicyDescriptor(connection, "int2");
                accessor.removePolicyDescriptor(connection, "range1");
                accessor.removePolicyDescriptor(connection, "range2");
                accessor.removePolicyDescriptor(connection, "selection1");
                accessor.removePolicyDescriptor(connection, "selection2");
                accessor.removePolicyDescriptor(connection, "text1");
                accessor.removePolicyDescriptor(connection, "text2");
                accessor.removePolicyDescriptor(connection, "oset1");
                accessor.removePolicyDescriptor(connection, "oset2");
                accessor.removePolicyDescriptor(connection, "uset1");
                accessor.removePolicyDescriptor(connection, "uset2");
                accessor.removePolicyDescriptor(connection, "structure1");
                accessor.removePolicyDescriptor(connection, "structure2");

                checkAllEmpty(conn);

                connection.disconnect();
                repository.terminate();
            }
        });
    }
View Full Code Here

        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {

                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, defaultProject);
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                RepositoryEnumeration enumeration =
                        accessor.enumerateDeviceTACs(connection);
                assertFalse("No TACs expected", enumeration.hasNext());

                // Now test with lots of tacs.
                int tacCount = populateWithTACs(conn);
                enumeration = accessor.enumerateDeviceTACs(connection);
                int actual = 0;
                while(enumeration.hasNext()) {
                    DeviceTACPair pair =
                            (DeviceTACPair) enumeration.next();
                    if (pair.getTAC() == 350612) {
                        assertEquals("Device 350612 should be Nokia-6210",
                                "Nokia-6210", pair.getDeviceName());
                    } else {
                        assertEquals("Name should match: ",
                              "device-" + pair.getTAC(), pair.getDeviceName());
                    }
                    ++actual;
                }
                assertEquals("Number of tacs should  match", tacCount, actual);

                // Check the database contents are empty
                checkAllEmpty(conn);

                connection.disconnect();
                repository.terminate();
            }
        });
    }
View Full Code Here

        InternalJDBCRepositoryConfiguration configuration =
                new JDBCRepositoryConfigurationImpl();
        configuration.setDataSource(dataSource);
        JDBCRepositoryImpl repository = new JDBCRepositoryImpl(configuration);

        JDBCRepositoryConnection connection = new
                JDBCRepositoryConnectionImpl(repository, false, "user",
                                         "password", true);
        connection.getConnection();

        assertTrue("Repository login should have been attempted using" +
                   "username and password", dataSource.wasConnectedUserPass());

        assertTrue("Repository login should have been attempted using" +
                   "username and password",
                   !dataSource.wasConnectedAnonymously());

        dataSource.reset();
       
        connection = new
                JDBCRepositoryConnectionImpl(repository, true, "user", "password", true);
        connection.getConnection();
        assertTrue("Repository login should have been attempted anonymously",
                   !dataSource.wasConnectedUserPass());
        assertTrue("Repository login should have been anonymously",
                   dataSource.wasConnectedAnonymously());
    }
View Full Code Here

                HypersonicManager.IN_MEMORY_SOURCE);
        hypersonicMgr.useCleanupWith(new Executor() {
            public void execute() throws Exception {
                InternalJDBCRepository repository = createRepository(
                        hypersonicMgr.getSource(), null, defaultProject);
                JDBCRepositoryConnection connection =
                        (JDBCRepositoryConnection) repository.connect();
                JDBCDeviceRepositoryAccessor accessor =
                        new JDBCDeviceRepositoryAccessor(repository, location);
                Connection conn = connection.getConnection();
                createTables(conn);
                populateWithPolicies(conn);
                populateWithPatterns(conn);
                populateWithTACs(conn);
                test.runTest(accessor, connection);
View Full Code Here

TOP

Related Classes of com.volantis.mcs.repository.jdbc.JDBCRepositoryConnection

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.