Package com.volantis.mcs.repository

Examples of com.volantis.mcs.repository.RepositoryEnumeration


        Map descriptors = new HashMap();

        // Now loop over all the source policy names, collecting the descriptor
        // for each policy namee.
        RepositoryEnumeration names = accessor.enumerateDevicePolicyNames();
        try {
            while (names.hasNext()) {
                String policyName = (String) names.next();
                PolicyDescriptor policyDescriptor;
                try {
                    policyDescriptor = accessor.retrievePolicyDescriptor(
                            policyName, Locale.getDefault());
                } catch (RepositoryException e) {
                    throw new RepositoryException(
                            exceptionLocalizer.format(
                                    "cannot-read-policy-descriptor",
                                    policyName),
                            e);
                }
                descriptors.put(policyName, policyDescriptor);
            }
        } finally {
            names.close();
        }

        // Now get a list of all the policies we found a descriptor for...
        List policyList = new ArrayList(descriptors.keySet());
        // And sort it for easy comparison purposes.
View Full Code Here


     */
    private List enumerateAllDevicesChildren(final String deviceName,
                                             final RepositoryConnection conn)
            throws RepositoryException {

        RepositoryEnumeration immediateChildren = null;

        try {
            Volantis volantis =
                    ApplicationInternals.getVolantisBean(application);
            immediateChildren =
                    volantis.getDeviceRepositoryAccessor().
                    enumerateDevicesChildren(conn, deviceName);

            // If there are no children, then an empty list is returned.
            final List allChildren =
                    immediateChildren.hasNext() ? new ArrayList() :
                    Collections.EMPTY_LIST;

            // Iterate over the device's immediate children.
            while (immediateChildren.hasNext()) {
                final String child = (String) immediateChildren.next();

                // Add the immediate child.
                allChildren.add(child);

                if (logger.isDebugEnabled()) {
                    logger.debug("Added child device for exclusion: " + child);
                }

                // Recursively add all the children of the immediate child.
                allChildren.addAll(enumerateAllDevicesChildren(child, conn));
            }
           
            return allChildren;

        } finally {
            // The RepositoryEnumeration must be closed after it has been read.
            if (immediateChildren != null) {
                immediateChildren.close();
            }
        }
    }
View Full Code Here

    public void testEnumerateCategoryNames() throws Exception {
        try {
            final InternalJDBCRepository repository = createRepository(defaultProject);
            final JDBCDeviceRepositoryAccessor accessor =
                new JDBCDeviceRepositoryAccessor(repository, location);
            RepositoryEnumeration enumeration =
                accessor.enumerateCategoryNames(connection);
            assertFalse("Should find nothing", enumeration.hasNext());

            // Populate with one value.
            Connection sqlConnection =
                    ((JDBCRepositoryConnection) connection).getConnection();
            final Statement st = sqlConnection.createStatement();
            execute(st, "insert into VMPOLICY_CATEGORY values " +
                    "(" + "'" + defaultProject + "',0,'CategoryName', " +
                        "'<default>')");
            execute(st, "insert into VMPOLICY_CATEGORY values " +
                    "(" + "'" + defaultProject + "',0,'Category name', 'en_GB_')");
            st.close();

            // Retrieve the unknown value shouldn't find a match.
            enumeration = accessor.enumerateCategoryNames(connection);
            assertTrue("Should find category", enumeration.hasNext());
            assertEquals("CategoryName", enumeration.next());
            assertFalse(enumeration.hasNext());
            final CategoryDescriptor categoryDescriptor =
                accessor.retrieveCategoryDescriptor(
                    connection, "CategoryName", new Locale("en", "GB"));
            assertEquals("Category name",
                categoryDescriptor.getCategoryDescriptiveName());
View Full Code Here

    public void testEnumeratePolicyNames() throws Exception {
        try {
            InternalJDBCRepository repository = createRepository(defaultProject);
            JDBCDeviceRepositoryAccessor accessor =
                    new JDBCDeviceRepositoryAccessor(repository, location);
            RepositoryEnumeration repositoryEnumeration =
                    accessor.enumeratePolicyNames(connection);
            assertNotNull("Repository enumeration expected", repositoryEnumeration);
            assertFalse("No values expected in enumeration.",
                    repositoryEnumeration.hasNext());

            // Populate with one value.
            Connection sqlConnection =
                    ((JDBCRepositoryConnection) connection).getConnection();

            Statement st = sqlConnection.createStatement();
            execute(st, "insert into VMPOLICY_TYPE values " +
                    "(" + "'" + defaultProject + "', 'PolicyName1', 0, 0)");
            st.close();

            repositoryEnumeration = accessor.enumeratePolicyNames(connection);
            assertNotNull("Values expected", repositoryEnumeration);
            assertTrue("Values expected in enumeration.",
                    repositoryEnumeration.hasNext());
            String result = (String)repositoryEnumeration.next();
            assertEquals("Result should match", "PolicyName1", result);

            assertFalse("Only one value expected.",
                    repositoryEnumeration.hasNext());
        } finally {
            removeRepository();
        }
    }
View Full Code Here

    public void testEnumeratePolicyNamesWithCategory() throws Exception {
        try {
            InternalJDBCRepository repository = createRepository(defaultProject);
            JDBCDeviceRepositoryAccessor accessor =
                    new JDBCDeviceRepositoryAccessor(repository, location);
            RepositoryEnumeration repositoryEnumeration =
                    accessor.enumeratePolicyNames(connection, "unknown");
            assertNotNull("Repository enumeration expected", repositoryEnumeration);
            assertFalse("No values expected in enumeration.",
                    repositoryEnumeration.hasNext());

            // Populate with one value.
            Connection sqlConnection =
                    ((JDBCRepositoryConnection) connection).getConnection();

            Statement st = sqlConnection.createStatement();
            execute(st, "insert into VMPOLICY_TYPE values " +
                "(" + "'" + defaultProject + "', 'PolicyName1', 0, 0)");
            execute(st, "insert into VMPOLICY_CATEGORY values " +
                "(" + "'" + defaultProject + "',0,'CategoryName', " +
                    "'<default>')");
            st.close();

            // Retrieve the unknown value shouldn't find a match.
            repositoryEnumeration = accessor.enumeratePolicyNames(connection,
                    "unknown");
            assertNotNull("Repository enumeration expected", repositoryEnumeration);
            assertFalse("No values expected in enumeration.",
                    repositoryEnumeration.hasNext());

            // Retrieve the PolicyName with the matching category name should
            // find a match.
            repositoryEnumeration = accessor.enumeratePolicyNames(connection,
                    "CategoryName");
            assertNotNull("Values expected", repositoryEnumeration);
            assertTrue("Values expected in enumeration.",
                    repositoryEnumeration.hasNext());
            String result = (String)repositoryEnumeration.next();
            assertEquals("Result should match", "PolicyName1", result);

            assertFalse("Only one value expected.",
                    repositoryEnumeration.hasNext());
        } finally {
            removeRepository();
        }
    }
View Full Code Here

                        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: ",
View Full Code Here

        try {
           
            outputKeys = new HashSet();
            // NOTE: might be slow; this may require caching to be enabled
            // as mentioned in the constructor.
            RepositoryEnumeration inputKeys =
                    accessor.enumerateDeviceNames(connection);
            while (inputKeys.hasNext()) {
                String deviceName = (String) inputKeys.next();
                outputKeys.add(deviceName);
            }
            // Translate empty back to null as per the contract.
            if (outputKeys.size() == 0) {
                outputKeys = null;
View Full Code Here

          logger.debug (sql);
      }

      ResultSet rs = stmt.executeQuery (sql);

      RepositoryEnumeration e = new StringPairEnumeration (rs);

      // From this point on the statement should not be closed as it is owned
      // by the RepositoryEnumeration.
      stmt = null;
View Full Code Here

          logger.debug (sql);
      }

      ResultSet rs = stmt.executeQuery (sql);

      RepositoryEnumeration e = new StringEnumeration(rs);

      // From this point on the statement should not be closed as it is owned
      // by the RepositoryEnumeration.
      stmt = null;
View Full Code Here

        if (devicePatternCache == null) {
            devicePatternCache = new DevicePatternCache();
        }

        RepositoryEnumeration enumeration = enumerateDevicePatterns(connection);
        // count the number of items we add to the cache.
        // Remember duplicate items will be discarded
        int count = 0;
        try {
            while (enumeration.hasNext()) {
                String[] pair = (String[]) enumeration.next();
                String deviceName = pair[0];
                String pattern = normalizePattern(pair[1]);

                try {
                    devicePatternCache.mapPatternAndDevice(pattern.trim(),
                                                           deviceName.intern());
                    count++;
                } catch (IllegalArgumentException e) {
                    enumeration.close();
                    throw new RepositoryException(
                            exceptionLocalizer.format(
                                    "unexpected-illegal-argument-exception"),
                            e);
                }
            }
        } finally {
            enumeration.close();
        }

        int cacheSize = devicePatternCache.size();
        if (logger.isDebugEnabled()) {
            logger.debug("Initialized devicePatternCache with " +
View Full Code Here

TOP

Related Classes of com.volantis.mcs.repository.RepositoryEnumeration

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.