本文整理匯總了Java中org.h2.jdbcx.JdbcConnectionPool.create方法的典型用法代碼示例。如果您正苦於以下問題:Java JdbcConnectionPool.create方法的具體用法?Java JdbcConnectionPool.create怎麽用?Java JdbcConnectionPool.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.h2.jdbcx.JdbcConnectionPool
的用法示例。
在下文中一共展示了JdbcConnectionPool.create方法的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();
}
示例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);
}
示例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();
}
示例4: 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);
}
示例5: 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();
}
示例6: 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
示例7: 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;
}
示例8: 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);
}
示例9: 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();
}
示例10: 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");
}
};
}
示例11: onEnable
import org.h2.jdbcx.JdbcConnectionPool; //導入方法依賴的package包/類
@Override
public void onEnable() {
config = new DatabaseConfiguration(this.getDataFolder());
config.load();
String path;
try {
path = getDataFolder().getCanonicalPath();
} catch (IOException e) {
path = getDataFolder().getPath();
}
final String connUrl = DatabaseConfiguration.CONNECTION_STRING.getString().replaceAll(Pattern.quote("${plugin_data_dir}"), Matcher.quoteReplacement(path));
final String user = DatabaseConfiguration.USERNAME.getString();
getLogger().info("Attempting to connect to " + connUrl + ", with user [" + user + "]");
pool = JdbcConnectionPool.create(connUrl, user, DatabaseConfiguration.PASSWORD.getString());
pool.setMaxConnections(DatabaseConfiguration.POOL_SIZE.getInt());
getEngine().getEventManager().registerEvents(new DataEventListener(this), this);
getLogger().info("enabled.");
}
示例12: testSuspendResume
import org.h2.jdbcx.JdbcConnectionPool; //導入方法依賴的package包/類
@Test
public void testSuspendResume() throws IOException {
AmberDb adb = new AmberDb(JdbcConnectionPool.create("jdbc:h2:"+folder.getRoot()+"persist;DATABASE_TO_UPPER=false","per","per"), folder.getRoot().getAbsolutePath());
Long sessId;
Long bookId;
Work book;
try (AmberSession db = adb.begin()) {
book = db.addWork();
bookId = book.getId();
book.setTitle("Test book");
sessId = db.suspend();
}
AmberDb adb2 = new AmberDb(JdbcConnectionPool.create("jdbc:h2:"+folder.getRoot()+"persist;DATABASE_TO_UPPER=false","per","per"), folder.getRoot().getAbsolutePath());
try (AmberSession db = adb2.resume(sessId)) {
// now, can we retrieve the files ?
Work book2 = db.findWork(bookId);
assertEquals(book, book2);
db.close();
}
}
示例13: getDataSource
import org.h2.jdbcx.JdbcConnectionPool; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource getDataSource() {
if (connectionPool == null) {
// locate the repository directory
final String repositoryDirectoryPath = properties.getDatabaseDirectory();
// ensure the repository directory is specified
if (repositoryDirectoryPath == null) {
throw new NullPointerException("Database directory must be specified.");
}
// create a handle to the repository directory
final File repositoryDirectory = new File(repositoryDirectoryPath);
// get a handle to the database file
final File databaseFile = new File(repositoryDirectory, DATABASE_FILE_NAME);
// format the database url
String databaseUrl = "jdbc:h2:" + databaseFile + ";AUTOCOMMIT=OFF;DB_CLOSE_ON_EXIT=FALSE;LOCK_MODE=3";
String databaseUrlAppend = properties.getDatabaseUrlAppend();
if (StringUtils.isNotBlank(databaseUrlAppend)) {
databaseUrl += databaseUrlAppend;
}
// create the pool
connectionPool = JdbcConnectionPool.create(databaseUrl, DB_USERNAME_PASSWORD, DB_USERNAME_PASSWORD);
connectionPool.setMaxConnections(MAX_CONNECTIONS);
}
return connectionPool;
}
示例14: testShutdown
import org.h2.jdbcx.JdbcConnectionPool; //導入方法依賴的package包/類
private void testShutdown() throws SQLException {
String url = getURL("connectionPool2", true), user = getUser();
String password = getPassword();
JdbcConnectionPool cp = JdbcConnectionPool.create(url, user, password);
StringWriter w = new StringWriter();
cp.setLogWriter(new PrintWriter(w));
Connection conn1 = cp.getConnection();
Connection conn2 = cp.getConnection();
conn1.close();
conn2.createStatement().execute("shutdown immediately");
cp.dispose();
assertTrue(w.toString().length() > 0);
cp.dispose();
}
示例15: testWrongUrl
import org.h2.jdbcx.JdbcConnectionPool; //導入方法依賴的package包/類
private void testWrongUrl() {
JdbcConnectionPool cp = JdbcConnectionPool.create(
"jdbc:wrong:url", "", "");
try {
cp.getConnection();
} catch (SQLException e) {
assertEquals(8001, e.getErrorCode());
}
cp.dispose();
}