本文整理汇总了Java中org.h2.tools.RunScript类的典型用法代码示例。如果您正苦于以下问题:Java RunScript类的具体用法?Java RunScript怎么用?Java RunScript使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RunScript类属于org.h2.tools包,在下文中一共展示了RunScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.h2.tools.RunScript; //导入依赖的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: initializeDatabase
import org.h2.tools.RunScript; //导入依赖的package包/类
@Before
public void initializeDatabase() {
Session session = entityManager.unwrap(Session.class);
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
try {
File script = new File(getClass().getResource("/data.sql").getFile());
RunScript.execute(connection, new FileReader(script));
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Database initialize script error");
}
}
});
}
示例3: prepareTables
import org.h2.tools.RunScript; //导入依赖的package包/类
public void prepareTables() throws Exception
{
Path ddlPath = Paths.get(ClassLoader.getSystemResource("sql").toURI());
try (Connection conn = xaConnectionManager.getConnection();)
{
Files.walk(ddlPath, 1)
.filter(path -> !Files.isDirectory(path)
&& (path.toString().endsWith("ddl")
|| path.toString().endsWith("idx")))
.forEach(path -> {
try
{
RunScript.execute(conn, Files.newBufferedReader(path));
}
catch (Exception e)
{
throw new RuntimeException("Exception at table initialization", e);
}
});
}
}
示例4: initDb
import org.h2.tools.RunScript; //导入依赖的package包/类
/**
* Initialize a database from a SQL script file.
*/
void initDb() throws Exception {
Class.forName("org.h2.Driver");
InputStream in = getClass().getResourceAsStream("script.sql");
if (in == null) {
System.out.println("Please add the file script.sql to the classpath, package "
+ getClass().getPackage().getName());
} else {
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
RunScript.execute(conn, new InputStreamReader(in));
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stat.close();
conn.close();
}
}
示例5: main
import org.h2.tools.RunScript; //导入依赖的package包/类
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
String targetDir = args.length == 0 ? "." : args[0];
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
InputStream in = Newsfeed.class.getResourceAsStream("newsfeed.sql");
ResultSet rs = RunScript.execute(conn, new InputStreamReader(in, "ISO-8859-1"));
in.close();
while (rs.next()) {
String file = rs.getString("FILE");
String content = rs.getString("CONTENT");
if (file.endsWith(".txt")) {
content = convertHtml2Text(content);
}
new File(targetDir).mkdirs();
FileOutputStream out = new FileOutputStream(targetDir + "/" + file);
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.write(content);
writer.close();
out.close();
}
conn.close();
}
示例6: TestServer
import org.h2.tools.RunScript; //导入依赖的package包/类
private TestServer() {
DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
try (Connection connection = ds.getConnection()) {
String schemaResourceName = "/create_h2.sql";
InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);
if (in == null) {
throw new RuntimeException("Failed to load resource: " + schemaResourceName);
}
InputStreamReader reader = new InputStreamReader(in, UTF_8);
RunScript.execute(connection, reader);
} catch (SQLException e) {
e.printStackTrace();
}
}
示例7: TestServer
import org.h2.tools.RunScript; //导入依赖的package包/类
private TestServer() {
DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
try (Connection connection = ds.getConnection()) {
String schemaResourceName = "/create_h2.sql";
InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);
if (in == null) {
throw new RuntimeException("Failed to load resource: " + schemaResourceName);
}
InputStreamReader reader = new InputStreamReader(in, UTF_8);
RunScript.execute(connection, reader);
} catch (SQLException e) {
e.printStackTrace();
}
}
示例8: TestServer
import org.h2.tools.RunScript; //导入依赖的package包/类
private TestServer() {
DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
try (Connection connection = ds.getConnection()) {
// Runscript doesn't work need to execute batch here.
String schemaResourceName = "/create_h2.sql";
InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);
if (in == null) {
throw new RuntimeException("Failed to load resource: " + schemaResourceName);
}
InputStreamReader reader = new InputStreamReader(in, UTF_8);
RunScript.execute(connection, reader);
} catch (SQLException e) {
e.printStackTrace();
}
}
示例9: runOnceBeforeClass
import org.h2.tools.RunScript; //导入依赖的package包/类
@BeforeClass
public static void runOnceBeforeClass() {
System.out.println("@BeforeClass - runOnceBeforeClass");
DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
try (Connection connection = ds.getConnection()) {
String schemaResourceName = "/create_h2.sql";
InputStream in = CacheStartupHookProviderTest.class.getResourceAsStream(schemaResourceName);
if (in == null) {
throw new RuntimeException("Failed to load resource: " + schemaResourceName);
}
InputStreamReader reader = new InputStreamReader(in, UTF_8);
RunScript.execute(connection, reader);
} catch (SQLException e) {
e.printStackTrace();
}
}
示例10: initDb
import org.h2.tools.RunScript; //导入依赖的package包/类
public DatabaseEngine initDb() {
try {
ResourceUtil ru = new ResourceUtil();
Class.forName("org.h2.Driver");
InputStream in = ru.getResourceAsStream("sql/create.sql");
InputStream in2 = ru.getResourceAsStream("sql/fill.sql");
if (in == null) {
System.out.println("Please add the file create.sql to the classpath, package "
+ getClass().getPackage().getName());
} else {
setConnection(DriverManager.getConnection(H2_DB_URL, "admin", "admin"));
RunScript.execute(connection, new InputStreamReader(in));
RunScript.execute(connection, new InputStreamReader(in2));
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return this;
}
示例11: initDb
import org.h2.tools.RunScript; //导入依赖的package包/类
/**
* Initialize a database from a SQL script file.
*/
void initDb() throws Exception {
ResourceUtil ru = new ResourceUtil();
Class.forName("org.h2.Driver");
InputStream in = ru.getResourceAsStream("sql/init.sql");
ru = null;
if (in == null) {
System.out.println("Please add the file script.sql to the classpath, package "
+ getClass().getPackage().getName());
} else {
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
RunScript.execute(conn, new InputStreamReader(in));
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stat.close();
conn.close();
}
}
示例12: H2CacheStoreStrategy
import org.h2.tools.RunScript; //导入依赖的package包/类
/**
* @throws IgniteCheckedException If failed.
*/
public H2CacheStoreStrategy() throws IgniteCheckedException {
Server srv = null;
try {
srv = Server.createTcpServer().start();
port = srv.getPort();
dataSrc = H2CacheStoreSessionListenerFactory.createDataSource(port);
try (Connection conn = connection()) {
RunScript.execute(conn, new StringReader(CREATE_CACHE_TABLE));
RunScript.execute(conn, new StringReader(CREATE_STATS_TABLES));
RunScript.execute(conn, new StringReader(POPULATE_STATS_TABLE));
}
}
catch (SQLException e) {
throw new IgniteCheckedException("Failed to set up cache store strategy" +
(srv == null ? "" : ": " + srv.getStatus()), e);
}
}
示例13: performScriptCommand
import org.h2.tools.RunScript; //导入依赖的package包/类
/**
* @param args2
* @throws SQLException
*/
private static void performScriptCommand(List<String> args)
{
try {
createUrl(args);
new RunScript() {
@Override
protected void showUsage()
{
showScriptUsage();
}
}.runTool(args.toArray(new String[0]));
} catch (SQLException x) {
System.err.println(x.getMessage() + "\n");
showScriptUsage();
}
}
示例14: runScript
import org.h2.tools.RunScript; //导入依赖的package包/类
public int runScript(InputStream script, String encoding) throws Exception {
ResultSet results = RunScript.execute(getConnection(), new InputStreamReader(script));
if (results != null)
results.close();
return 0;
}
示例15: loadDriverTest
import org.h2.tools.RunScript; //导入依赖的package包/类
@BeforeClass
public static void loadDriverTest() throws Exception {
Class.forName("org.h2.Driver");
activeConn = getConnection();
Connection conn = getConnection();
RunScript.execute(conn, new FileReader("src/test/resources/testdb.ddl"));
conn.close();
}