當前位置: 首頁>>代碼示例>>Java>>正文


Java JdbcConnectionPool類代碼示例

本文整理匯總了Java中org.h2.jdbcx.JdbcConnectionPool的典型用法代碼示例。如果您正苦於以下問題:Java JdbcConnectionPool類的具體用法?Java JdbcConnectionPool怎麽用?Java JdbcConnectionPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JdbcConnectionPool類屬於org.h2.jdbcx包,在下文中一共展示了JdbcConnectionPool類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUp

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  registry = RegistryService.getMetricRegistry();

  String sqlId = new StringUniqueIdService().getUniqueId(SELECT_QUERY);
  executeStatementName = JdbcRuleHelper.EXECUTE_STATEMENT_NAME.withTags("sql", sqlId);

  presetElements = IntStream.range(0, 1000).boxed()
      .collect(Collectors.toMap(i -> UUID.randomUUID().toString(), i -> i));
  presetElementKeys = new ArrayList<>(presetElements.keySet());

  StringBuilder sb = new StringBuilder(CREATE_TABLE_STRING);
  presetElements.forEach((s, o) -> {
    sb.append("\nINSERT INTO TEST VALUES('").append(s).append("', ").append(o).append(");");
  });

  String dbName = "JDBCInstrumentationTest." + UUID.randomUUID();
  datasource = JdbcConnectionPool.create("jdbc:h2:mem:" + dbName, "h2", "h2");
  ((JdbcConnectionPool) datasource).setMaxConnections(POOL_SIZE);
  datasource.setLoginTimeout(-1);
  Connection conn = datasource.getConnection();
  RunScript.execute(conn, new StringReader(sb.toString()));
  conn.close();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:25,代碼來源:JDBCInstrumentationTest.java

示例2: initialize

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Override
public Addon initialize(ServiceConfig serviceConfig) {
    String databaseName = unitTest ? "" : ! isNullOrEmpty(name) ? name : "test";

    DataSource dataSource = JdbcConnectionPool.create("jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1", "user", "password");
    scripts.forEach(script -> {

        try {
            Connection conn = dataSource.getConnection();
            conn.createStatement().executeUpdate(script);
            conn.close();
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    });

    return this.withDataSource(dataSource);
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:19,代碼來源:H2InMemoryDatasourceAddon.java

示例3: testPerformance

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
private void testPerformance() throws SQLException {
    String url = getURL("connectionPool", true), user = getUser();
    String password = getPassword();
    JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
    Connection conn = man.getConnection();
    int len = 1000;
    long time = System.currentTimeMillis();
    for (int i = 0; i < len; i++) {
        man.getConnection().close();
    }
    man.dispose();
    trace((int) (System.currentTimeMillis() - time));
    time = System.currentTimeMillis();
    for (int i = 0; i < len; i++) {
        DriverManager.getConnection(url, user, password).close();
    }
    trace((int) (System.currentTimeMillis() - time));
    conn.close();
}
 
開發者ID:vdr007,項目名稱:ThriftyPaxos,代碼行數:20,代碼來源:TestConnectionPool.java

示例4: init

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Override
public void init(DbConnection connection) throws Exception {
    JdbcConnectionPool pool = JdbcConnectionPool.create(connection.uri, connection.username, connection.password);

    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("jdblender", transactionFactory, pool);

    Configuration cfg = new Configuration(environment);
    cfg.setMapUnderscoreToCamelCase(true);
    cfg.addMapper(BrandsMapper.class);
    cfg.addMapper(SeriesMapper.class);
    cfg.addMapper(ModelsMapper.class);
    cfg.addMapper(SparesMapper.class);

    //Create session
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(cfg);
}
 
開發者ID:rumatoest,項目名稱:jdblender,代碼行數:18,代碼來源:RunnerMybatis.java

示例5: init

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Override
public void init() throws Exception {
    File dir = new File(this.dbPath);
    if (dir.exists()) {
        FileUtils.cleanDirectory(dir);
    }
    this.connPool = JdbcConnectionPool.create("jdbc:h2:" + this.dbPath + SYS_CONFIG.getExecId(), "sa", "sa");
    connPool.setMaxConnections(Integer.MAX_VALUE);
    try (Connection conn = this.getConnection()) {
        try {
            conn.prepareStatement("SELECT * FROM case_result WHERE 0;").executeQuery();
        } catch (SQLException ex) {
            LOG.warn("{}", ex.getMessage());
            this.initSchema();
        }
    }
}
 
開發者ID:tascape,項目名稱:reactor,代碼行數:18,代碼來源:H2Handler.java

示例6: DLNAMediaDatabase

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
public DLNAMediaDatabase(String name) {
	dbName = name;
	File profileFolder = new File(configuration.getProfileFolder());
	dbDir = new File(profileFolder.isDirectory() ? profileFolder : null, "database").getAbsolutePath();
	boolean logDB = configuration.getDatabaseLogging();
	url = Constants.START_URL + dbDir + File.separator + dbName + (logDB ? ";TRACE_LEVEL_FILE=4" : "");
	LOGGER.debug("Using database URL: {}", url);
	LOGGER.info("Using database located at: \"{}\"", dbDir);
	if (logDB) {
		LOGGER.info("Database logging is enabled");
	} else if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("Database logging is disabled");
	}

	try {
		Class.forName("org.h2.Driver");
	} catch (ClassNotFoundException e) {
		LOGGER.error(null, e);
	}

	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL(url);
	ds.setUser("sa");
	ds.setPassword("");
	cp = JdbcConnectionPool.create(ds);
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:27,代碼來源:DLNAMediaDatabase.java

示例7: PipelineMavenPluginH2Dao

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
public PipelineMavenPluginH2Dao(File rootDir) {
    rootDir.getClass(); // check non null

    File databaseFile = new File(rootDir, "jenkins-jobs");
    String jdbcUrl = "jdbc:h2:file:" + databaseFile.getAbsolutePath() + ";AUTO_SERVER=TRUE;MULTI_THREADED=1";
    if(LOGGER.isLoggable(Level.FINEST)) {
        jdbcUrl += ";TRACE_LEVEL_SYSTEM_OUT=3";
    } else if (LOGGER.isLoggable(Level.FINE)) {
        jdbcUrl += ";TRACE_LEVEL_SYSTEM_OUT=2";
    }
    LOGGER.log(Level.INFO, "Open database {0}", jdbcUrl);
    jdbcConnectionPool = JdbcConnectionPool.create(jdbcUrl, "sa", "sa");

    initializeDatabase();
    testDatabase();
}
 
開發者ID:jenkinsci,項目名稱:pipeline-maven-plugin,代碼行數:17,代碼來源:PipelineMavenPluginH2Dao.java

示例8: init

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
static void init() {
    long maxCacheSize = Nhz.getIntProperty("nhz.dbCacheKB");
    if (maxCacheSize == 0) {
        maxCacheSize = Runtime.getRuntime().maxMemory() / (1024 * 2);
    }
    String dbUrl = Constants.isTestnet ? Nhz.getStringProperty("nhz.testDbUrl") : Nhz.getStringProperty("nhz.dbUrl");
    if (! dbUrl.contains("CACHE_SIZE=")) {
        dbUrl += ";CACHE_SIZE=" + maxCacheSize;
    }
    Logger.logDebugMessage("Database jdbc url set to: " + dbUrl);
    cp = JdbcConnectionPool.create(dbUrl, "sa", "sa");
    cp.setMaxConnections(Nhz.getIntProperty("nhz.maxDbConnections"));
    cp.setLoginTimeout(Nhz.getIntProperty("nhz.dbLoginTimeout"));
    int defaultLockTimeout = Nhz.getIntProperty("nhz.dbDefaultLockTimeout") * 1000;
    try (Connection con = cp.getConnection();
         Statement stmt = con.createStatement()) {
        stmt.executeUpdate("SET DEFAULT_LOCK_TIMEOUT " + defaultLockTimeout);
    } catch (SQLException e) {
        throw new RuntimeException(e.toString(), e);
    }
    DbVersion.init();
}
 
開發者ID:atcsecure,項目名稱:horizon-blocknet,代碼行數:23,代碼來源:Db.java

示例9: initialize

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@BeforeClass
public static void initialize() throws ClassNotFoundException, SQLException {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "sa", "");

    Connection connection = getConnection();
    try {
        Statement statement = connection.createStatement();
        statement.execute("CREATE TABLE users (" +
                "userId INT PRIMARY KEY, " +
                "name VARCHAR(255), " +
                "birthyear INT, " +
                "employeeType VARCHAR(16)) " +
                "AS SELECT * FROM CSVREAD('src/test/resources/META-INF/qltest/jdbc/users.csv')");
    } finally {
        closeQuietly(connection);
    }
}
 
開發者ID:kwon37xi,項目名稱:freemarker-dynamic-ql-builder,代碼行數:18,代碼來源:FreemarkerDynamicQlBuilderJdbcTest.java

示例10: initConnectionPool

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
/**
 *
 *
 * @return
 * @throws ClassNotFoundException
 */
public H2Database initConnectionPool(boolean force) throws ClassNotFoundException {
  Class.forName(JDBC_EMBEDDED_DRIVER);

  if (force && connectionPool != null) {
    connectionPool.dispose();
  }

  if (connectionPool == null || force) {
    // *INDENT-OFF*
    connectionPool = JdbcConnectionPool.create(
        "jdbc:h2:"
        + dataPath.getAbsolutePath()
        + ";CREATE=TRUE", "sa", "sa");
    // *INDENT-ON*
    connectionPool.setMaxConnections(50);
  }

  return this;
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:26,代碼來源:H2Database.java

示例11: Client

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
public Client(String databaseFileName, String address, int port) {

        online = true;

        jdbcConnectionPool = JdbcConnectionPool.create(
                "jdbc:h2:" + databaseFileName + ";" + DB_CONNECTION_MODIFIERS,
                "sa", "sa");
        jdbcConnectionPool.setMaxConnections(100);
        jdbcConnectionPool.setLoginTimeout(0);

        try {

            DaoFactory.initialize(
                    jdbcConnectionPool
            );

            DaoFactory.createSchema();

        } catch (DaoException e) {
            e.printStackTrace();
        }
        networkClient = new NetworkClientImpl(address, port);
    }
 
開發者ID:bedrin,項目名稱:jsonde,代碼行數:24,代碼來源:Client.java

示例12: init

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
static void init()
{
  long l = Nxt.getIntProperty("nxt.dbCacheKB");
  if (l == 0L) {
    l = Runtime.getRuntime().maxMemory() / 2048L;
  }
  String str = Nxt.getStringProperty("nxt.dbUrl");
  if (!str.contains("CACHE_SIZE=")) {
    str = str + ";CACHE_SIZE=" + l;
  }
  Logger.logDebugMessage("Database jdbc url set to: " + str);
  cp = JdbcConnectionPool.create(str, "sa", "sa");
  cp.setMaxConnections(Nxt.getIntProperty("nxt.maxDbConnections"));
  cp.setLoginTimeout(Nxt.getIntProperty("nxt.dbLoginTimeout"));
  DbVersion.init();
}
 
開發者ID:stevedoe,項目名稱:nxt-client,代碼行數:17,代碼來源:Db.java

示例13: testGetDataSource

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Test
public void testGetDataSource() throws Exception {
    // Create initial context
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    // already tried System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
    InitialContext ic = new InitialContext();

    ic.createSubcontext("java:");
    ic.createSubcontext("java:/comp");
    ic.createSubcontext("java:/comp/env");
    ic.createSubcontext("java:/comp/env/jdbc");

    JdbcConnectionPool ds = JdbcConnectionPool.create("jdbc:h2:file:/tmp/test.db;FILE_LOCK=NO;MVCC=TRUE;DB_CLOSE_ON_EXIT=TRUE", "sa", "sasasa");

    String jndiName = "java:/mydatasource";
    ic.bind(jndiName, ds);


    DataSource dataSource = RDBMSUtils.getDataSource(jndiName);
    assertEquals("org.h2.jdbcx.JdbcConnectionPool",dataSource.getClass().getCanonicalName());

}
 
開發者ID:lightblue-platform,項目名稱:lightblue-rdbms,代碼行數:24,代碼來源:RDBMSUtilsTest.java

示例14: createRouteBuilder

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:" + getTestMethodName(), "sa", "sa");
    assertThatTableDoesNotExist("repository");
    RepositoryManagerFactory repositoryManagerFactory = new RepositoryManagerFactory();
    repositoryManagerFactory.setDataSource(dataSource);
    messageStore = new JDBCMessageStore();
    messageStore.setUuidGenerator(new UUIDGenerator());
    messageStore.setRepositoryManager(repositoryManagerFactory.createRepositoryManager());
    messageStore.init();
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(MessageStore.DEFAULT_MESSAGE_STORE_ENDPOINT)
                .bean(messageStore,"store")
                .bean(messageStore,"storeMessage")
            .routeId("testPostsgresMessageStore");
        }
    };
}
 
開發者ID:jentrata,項目名稱:jentrata,代碼行數:21,代碼來源:JDBCMessageStoreTest.java

示例15: openAmberDb

import org.h2.jdbcx.JdbcConnectionPool; //導入依賴的package包/類
public static AmberSession openAmberDb(String dbUrl, String dbUser, String dbPassword, String rootPath) throws InstantiationException, IllegalAccessException,
        ClassNotFoundException, SQLException {
    DataSource ds = null;
    AmberSession sess = null;

    try {
        MysqlDataSource mds = new MysqlDataSource();
        mds.setURL(dbUrl);
        mds.setUser(dbUser);
        mds.setPassword(dbPassword);
        ds = mds;
        sess = openAmberDb(ds, rootPath);
    } catch (Throwable e) {
        h2Test = true;
        // This is for build integration site which does not have
        // direct access to the mysql data source.
        DriverManager.registerDriver(new org.h2.Driver());
        dbUrl = "jdbc:h2:" + Paths.get(".").resolve("graph") + ";MVCC=true;DATABASE_TO_UPPER=false";
        dbUser = "garfield";
        dbPassword = "odde";
        ds = JdbcConnectionPool.create(dbUrl, dbUser, dbPassword);
        sess = openAmberDb(ds, rootPath);
    }

    return sess;
}
 
開發者ID:nla,項目名稱:amberdb,代碼行數:27,代碼來源:AmberDbFactory.java


注:本文中的org.h2.jdbcx.JdbcConnectionPool類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。