当前位置: 首页>>代码示例>>Java>>正文


Java RunScript类代码示例

本文整理汇总了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();
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:25,代码来源:JDBCInstrumentationTest.java

示例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");
			}
		}
	});
}
 
开发者ID:joaquimsn,项目名称:query-search,代码行数:18,代码来源:BaseJpaTest.java

示例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);
            }
        });
    }
}
 
开发者ID:komsit37,项目名称:reladomo-scala,代码行数:23,代码来源:H2ConnectionManager.java

示例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();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:InitDatabaseFromJar.java

示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:Newsfeed.java

示例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();
    }
}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:17,代码来源:TestServer.java

示例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();
    }

}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:18,代码来源:TestServer.java

示例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();
    }
}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:18,代码来源:TestServer.java

示例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();
    }

}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:20,代码来源:CacheStartupHookProviderTest.java

示例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;
}
 
开发者ID:nuclearthinking,项目名称:rpg,代码行数:21,代码来源:DatabaseEngine.java

示例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();
    }
}
 
开发者ID:nuclearthinking,项目名称:rpg,代码行数:25,代码来源:InitDbForJar.java

示例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);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:25,代码来源:H2CacheStoreStrategy.java

示例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();
	}

}
 
开发者ID:shesse,项目名称:h2ha,代码行数:25,代码来源:H2HaServer.java

示例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;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:9,代码来源:TPCC.java

示例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();
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:10,代码来源:QueryDataSourceTest.java


注:本文中的org.h2.tools.RunScript类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。