Example usage for org.apache.ibatis.io Resources getResourceURL

List of usage examples for org.apache.ibatis.io Resources getResourceURL

Introduction

In this page you can find the example usage for org.apache.ibatis.io Resources getResourceURL.

Prototype

public static URL getResourceURL(String resource) throws IOException 

Source Link

Document

Returns the URL of the resource on the classpath

Usage

From source file:com.axemblr.provisionr.core.templates.PoolTemplateInstallerTest.java

License:Apache License

private File getPathToCdh3Template() throws URISyntaxException, IOException {
    return new File(Resources.getResourceURL("com/axemblr/provisionr/core/templates/cdh3.xml").toURI());
}

From source file:com.daemon.DaemonPropertiesTest.java

License:Open Source License

@BeforeClass
public static void before() throws IOException {
    URL url = Resources.getResourceURL("daemon.properties");
    _props = new DaemonProperties(URLDecoder.decode(url.getFile(), "UTF-8"));
}

From source file:com.daemon.MinionTest.java

License:Open Source License

@Test
public void testMinionCalculateIntervalLength() {
    SearchTerm term1 = new SearchTerm("test1", new DateTime());
    term1.setPriority(0);/*  w  w w  .ja v  a 2 s.  co m*/
    SearchTermMetaData data1 = new SearchTermMetaData(term1);
    data1.setTweetCount(20);
    data1.setOldestTweetDate(new DateTime(2013, 12, 13, 14, 20, 34));
    data1.setNewestTweetDate(new DateTime(2013, 12, 13, 14, 42, 12));

    double timeDiff = Localization.DURATION_FORMATTER.parsePeriod("00:21:38").toStandardDuration().getMillis()
            / 60000d;
    double tpm = ((double) data1.getTweetCount()) / timeDiff;
    int intervalLengthInMin = (int) ((1 / tpm) * 0.9 * 100);
    Duration intervalLength = new Duration(intervalLengthInMin * 60000L);

    try {
        URL url = Resources.getResourceURL("daemon.properties");
        DaemonProperties props = new DaemonProperties(URLDecoder.decode(url.getFile(), "UTF-8"));

        assertTrue(
                "Minion.calculateIntervalLength(data1) returned "
                        + Minion.calculateIntervalLength(data1, null, props, null).getMillis() + ", expected "
                        + intervalLength.getMillis() + ".",
                Minion.calculateIntervalLength(data1, null, props, null).getMillis() == intervalLength
                        .getMillis());

    } catch (IOException ex) {
        fail(ex.getMessage());
    }
}

From source file:com.daemon.MinionTest.java

License:Open Source License

@Test
public void testMinionMaxIntervalLength() {
    SearchTerm term1 = new SearchTerm("test1", new DateTime());
    term1.setPriority(0);//from w  w w .  ja v a 2  s.c om
    SearchTermMetaData data1 = new SearchTermMetaData(term1);
    data1.setTweetCount(2);
    data1.setOldestTweetDate(new DateTime(2011, 12, 13, 14, 20, 34));
    data1.setNewestTweetDate(new DateTime(2013, 12, 13, 14, 42, 12));

    Duration intervalLength = Localization.DURATION_FORMATTER.parsePeriod("156:00:00").toStandardDuration();

    try {
        URL url = Resources.getResourceURL("daemon.properties");
        DaemonProperties props = new DaemonProperties(URLDecoder.decode(url.getFile(), "UTF-8"));

        assertTrue(
                "Minion.calculateIntervalLength(data1) returned "
                        + Minion.calculateIntervalLength(data1, null, props, null).getMillis() + ", expected "
                        + intervalLength.getMillis() + ".",
                Minion.calculateIntervalLength(data1, null, props, null).getMillis() == intervalLength
                        .getMillis());

    } catch (IOException ex) {
        fail(ex.getMessage());
    }
}

From source file:com.daemon.TransactorTest.java

License:Open Source License

@BeforeClass
public static void beforeClass() {
    try {//from   w  w  w . j a va 2  s  . c  om
        _dbPath = Transactor.DATABASE_PROPERTY_PATH;
        URL url = Resources.getResourceURL("database.properties");
        Transactor.DATABASE_PROPERTY_PATH = URLDecoder.decode(url.getFile(), "UTF-8");
        _trans = new Transactor();
        _trans.connect();

        // Prepare database
        Reader reader = Resources.getResourceAsReader("DaemonDump.sql");

        ScriptRunner sr = new ScriptRunner(_trans.getConnection());

        sr.setDelimiter(";");
        sr.setLogWriter(null);
        sr.setErrorLogWriter(null);
        sr.runScript(reader);

        _trans.getConnection().commit();
        reader.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.daemon.TransactorTest.java

License:Open Source License

@Test
public void testUpdateSearchTerm() throws IOException {
    // Restore old value at end
    SearchTerm copy = null;/*from w ww.j ava  2  s  . c  o m*/
    String dbPath = SearchTerm.DATABASE_PROPERTY_PATH;
    try {
        URL url = Resources.getResourceURL("database.properties");
        SearchTerm.DATABASE_PROPERTY_PATH = URLDecoder.decode(url.getFile(), "UTF-8");
        copy = SearchTerm.load(1);
        SearchTerm term = SearchTerm.load(1);

        term.setCurrentStart(new DateTime(2013, 12, 04, 13, 40, 30));
        term.setOldStart(new DateTime(2013, 12, 03, 23, 40, 30));
        term.setIntervalLength(SearchTerm.DURATION_FORMATTER.parsePeriod("01:00:00").toStandardDuration());
        term.setTimeLastFetched(null);
        term.setLastFetchedTweetId(null);
        term.setLastFetchedTweetCount(null);

        _trans.updateSearchTerm(term);

        term = null;
        term = SearchTerm.load(1);

        assertTrue(
                "term.getCurrentStart().getMillis() returned " + term.getCurrentStart().getMillis()
                        + ", expected " + new DateTime(2013, 12, 04, 13, 40, 30).getMillis() + ".",
                term.getCurrentStart().getMillis() == new DateTime(2013, 12, 04, 13, 40, 30).getMillis());
        assertTrue(
                "term.getOldStart().getMillis() returned " + term.getOldStart().getMillis() + ", expected "
                        + new DateTime(2013, 12, 03, 23, 40, 30).getMillis() + ".",
                term.getOldStart().getMillis() == new DateTime(2013, 12, 03, 23, 40, 30).getMillis());
        assertTrue("term.getIntervalLength().getMillis() returned " + term.getIntervalLength().getMillis()
                + ", expected 3600000.", term.getIntervalLength().getMillis() == 3600000);
        assertTrue("term.getTimeLastFetched() returned " + term.getTimeLastFetched() + ", expected null.",
                term.getTimeLastFetched() == null);
        assertTrue("term.getLastFetchedTweetId() returned " + term.getLastFetchedTweetId() + ", expected null.",
                term.getLastFetchedTweetId() == null);
        assertTrue("term.getLastFetchedTweetCount() returned " + term.getLastFetchedTweetCount()
                + ", expected null.", term.getLastFetchedTweetCount() == null);
    } catch (SQLException ex) {
        fail("SQL Exception" + ex.getMessage());
        ex.printStackTrace();
    } finally {
        SearchTerm.DATABASE_PROPERTY_PATH = dbPath;
        if (copy != null) {
            _trans.updateSearchTerm(copy);
        }
    }
}

From source file:org.apache.provisionr.core.templates.PoolTemplateInstallerTest.java

License:Apache License

private File getPathToTestTemplate() throws URISyntaxException, IOException {
    return new File(Resources.getResourceURL("templates/test.xml").toURI());
}

From source file:org.fastcatsearch.analytics.db.CommonDBHandler.java

License:Open Source License

public boolean load() {

    if (driverProperties == null) {
        driverProperties = new Properties();
    }//from  w ww  . j  a v  a  2s .  co m

    String dbType = settings.getString("type");
    driverProperties.setProperty("user", settings.getString("user"));
    driverProperties.setProperty("password", settings.getString("password"));
    driverProperties.setProperty("driver.encoding", "UTF-8");

    boolean isAutoCommit = settings.getBoolean("autocommit", true);
    boolean usePooling = settings.getBoolean("usePooling", true);

    DataSource dataSource = null;
    if (usePooling) {
        PooledDataSource pooledDataSource = new PooledDataSource(settings.getString("driver"),
                settings.getString("url"), driverProperties);
        boolean poolPingEnabled = settings.getBoolean("poolPingEnabled", true);
        String poolPingQuery = settings.getString("poolPingQuery");
        int poolPingConnectionsNotUsedFor = settings.getInt("poolPingConnectionsNotUsedFor", -1);
        int poolTimeToWait = settings.getInt("poolTimeToWait", -1);
        int poolMaximumActiveConnections = settings.getInt("poolMaximumActiveConnections", -1);
        int poolMaximumIdleConnections = settings.getInt("poolMaximumIdleConnections", -1);

        pooledDataSource.setPoolPingEnabled(poolPingEnabled);

        if (poolPingQuery != null) {
            pooledDataSource.setPoolPingQuery(poolPingQuery);
        }
        if (poolPingConnectionsNotUsedFor != -1) {
            pooledDataSource.setPoolPingConnectionsNotUsedFor(poolPingConnectionsNotUsedFor);
        }
        if (poolTimeToWait != -1) {
            pooledDataSource.setPoolTimeToWait(poolTimeToWait);
        }
        if (poolMaximumActiveConnections != -1) {
            pooledDataSource.setPoolMaximumActiveConnections(poolMaximumActiveConnections);
        }
        if (poolMaximumIdleConnections != -1) {
            pooledDataSource.setPoolMaximumIdleConnections(poolMaximumIdleConnections);
        }
        //autocommit
        pooledDataSource.setDefaultAutoCommit(isAutoCommit);

        dataSource = pooledDataSource;

    } else {
        UnpooledDataSource unpooledDataSource = new UnpooledDataSource(settings.getString("driver"),
                settings.getString("url"), driverProperties);
        unpooledDataSource.setAutoCommit(isAutoCommit);
        dataSource = unpooledDataSource;
    }

    org.apache.ibatis.mapping.Environment environment = new org.apache.ibatis.mapping.Environment("ID",
            new JdbcTransactionFactory(), dataSource);
    Configuration configuration = new Configuration(environment);
    if (globalParam != null) {
        configuration.getVariables().putAll(globalParam);
    }

    if (mapperList != null) {
        List<URL> mapperFileList = new ArrayList<URL>();
        for (Class<?> mapperDAO : mapperList) {
            try {
                String mapperFilePath = mapperDAO.getName().replace('.', '/') + "_" + dbType + ".xml";
                URL mapperFile = Resources.getResourceURL(mapperFilePath);
                mapperFileList.add(mapperFile);
            } catch (IOException e) {
                logger.error("error load MapperFile", e);
            }
        }

        for (URL mapperFile : mapperFileList) {
            addSqlMappings(configuration, mapperFile);
        }
    }

    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    return true;
}

From source file:org.fastcatsearch.db.AbstractDBService.java

License:Open Source License

public AbstractDBService(String dbPath, Class<?>[] mapperList, Environment environment, Settings settings,
        ServiceManager serviceManager) {
    super(environment, settings, serviceManager);
    this.mapperList = mapperList;
    String absoluteDbPath = environment.filePaths().file(dbPath).getAbsolutePath();
    // system mapper.
    List<URL> mapperFileList = new ArrayList<URL>();
    for (Class<?> mapperDAO : mapperList) {
        try {/* w  w  w.  j  a va2 s .  c o m*/
            String mapperFilePath = mapperDAO.getName().replace('.', '/') + ".xml";
            URL mapperFile = Resources.getResourceURL(mapperFilePath);
            mapperFileList.add(mapperFile);
        } catch (IOException e) {
            logger.error("error load MapperFile", e);
        }
    }
    internalDBModule = new InternalDBModule(absoluteDbPath, mapperFileList, environment, settings);

}

From source file:org.fastcatsearch.plugin.analysis.AnalysisPlugin.java

@Override
protected void addMapperFile(List<URL> mapperFileList) {

    try {//from   w w  w . j a va  2s.c  o  m
        URL mapperFile = Resources.getResourceURL(defaultDictionaryMapperFilePath);
        mapperFileList.add(mapperFile);
    } catch (IOException e) {
        logger.error("error load defaultDictionaryMapperFile", e);
    }
    try {
        URL statusMapperURL = Resources.getResourceURL(defaultDictionaryStatusMapperFilePath);
        mapperFileList.add(statusMapperURL);
    } catch (IOException e) {
        logger.error("error load defaultDictionaryStatusMapperFile", e);
    }
}