Package com.volantis.mcs.devices.jdbc

Examples of com.volantis.mcs.devices.jdbc.JDBCDeviceRepositoryConfiguration


    // javadoc inherited.
    public DeviceRepository getDeviceRepository(DataSource datasource,
            String project) throws DeviceRepositoryException {

        JDBCDeviceRepositoryConfiguration config =
                new DefaultJDBCDeviceRepositoryConfiguration();
        config.setDataSource(datasource);
        config.setDefaultProject(project);
        config.setUseShortNames(false);
        configureDefaultCacheValues(config);
        return createDeviceRepository(config);
    }
View Full Code Here


    private DeviceRepository createJDBCDeviceRepository(
                final String repositoryURL,
                final String unknownDevicesLogFileName)
            throws DeviceRepositoryException {
        ensureDriverClassesLoaded();
        JDBCDeviceRepositoryConfiguration configuration =
                deviceRepositoryFactory.createJDBCDeviceRepositoryConfiguration();

        Map params = getJDBCURLParams(repositoryURL);
        String userName = (String) params.remove(JDBC_USERNAME);
        String password = (String) params.remove(JDBC_PASSWORD);
        String defaultProject = (String) params.remove(JDBC_DEFAULT_PROJECT);

        if (defaultProject == null) {
            throw new DeviceRepositoryException(EXCEPTION_LOCALIZER.
                    format(INVALID_JDBC_URL_KEY, new String [] {
                        repositoryURL, JDBC_URL_MESSAGE}));
        }

        // remove the processed parameters
        int paramStart = repositoryURL.indexOf("?");
        final String baseURL;
        if (paramStart != -1) {
            baseURL = repositoryURL.substring(0, paramStart);
        } else {
            baseURL = repositoryURL;
        }
        final StringBuffer baseURLBuffer = new StringBuffer(baseURL);
        boolean first = true;
        for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) {
            final Map.Entry entry = (Map.Entry) iter.next();
            if (first) {
                baseURLBuffer.append('?');
                first = false;
            } else {
                baseURLBuffer.append('&');
            }
            final String key = (String) entry.getKey();
            baseURLBuffer.append(key);
            final String value = (String) entry.getValue();
            if (value != null) {
                baseURLBuffer.append('=');
                baseURLBuffer.append(value);
            }
        }

        DataSource dataSource = new DriverDataSource(baseURLBuffer.toString());

        if (userName != null) {
            // Since we have a username lets use a confusingly
            // named AnonymousDataSource.
            dataSource = jdbcRepositoryFactory.createAnonymousDataSource(
                    dataSource, userName, password);
        }
        configuration.setDataSource(dataSource);
        configuration.setDefaultProject(defaultProject);
        configuration.setUnknownDevicesLogFileName(unknownDevicesLogFileName);

        return deviceRepositoryFactory.createDeviceRepository(configuration);
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.devices.jdbc.JDBCDeviceRepositoryConfiguration

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.