Java Code Examples for org.h2.jdbcx.JdbcConnectionPool

The following examples show how to use org.h2.jdbcx.JdbcConnectionPool. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "", "");

    eventLog = mock(EventLog.class);
    repository = new EmbeddedJdbcPaymentRepository(eventLog,
            new Topic("payments"),
            pool);
    ref = repository.nextIdentity();
    payment = Payment.builder()
            .ref(ref)
            .amount(Amount.of(10, 0))
            .paymentProcessor(mock(PaymentProcessor.class))
            .eventLog(eventLog)
            .build();
}
 
Example 2
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "", "");

    eventLog = InProcessEventLog.instance();
    repository = new EmbeddedJdbcPaymentRepository(eventLog,
            new Topic("payments"),
            pool);
    ref = repository.nextIdentity();
    payment = Payment.builder()
            .ref(ref)
            .amount(Amount.of(10, 0))
            .paymentProcessor(mock(PaymentProcessor.class))
            .eventLog(eventLog)
            .build();
}
 
Example 3
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    eventLog = mock(EventLog.class);
    repository = new EmbeddedJdbcDeliveryOrderRepository(eventLog,
            new Topic("delivery_orders"),
            pool);
    ref = repository.nextIdentity();
    deliveryOrder = DeliveryOrder.builder()
            .ref(ref)
            .kitchenOrderRef(new KitchenOrderRef(RefStringGenerator.generateRefString()))
            .onlineOrderRef(new OnlineOrderRef(RefStringGenerator.generateRefString()))
            .pizza(DeliveryOrder.Pizza.builder().size(DeliveryOrder.Pizza.Size.MEDIUM).build())
            .eventLog(eventLog)
            .build();
}
 
Example 4
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    eventLog = InProcessEventLog.instance();
    repository = new EmbeddedJdbcOnlineOrderRepository(eventLog,
            new Topic("ordering"),
            pool);
    ref = repository.nextIdentity();
    onlineOrder = OnlineOrder.builder()
            .ref(ref)
            .type(OnlineOrder.Type.PICKUP)
            .eventLog(eventLog)
            .build();
    pizza = Pizza.builder().size(Pizza.Size.MEDIUM).build();
}
 
Example 5
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "", "");

    eventLog = mock(EventLog.class);
    repository = new EmbeddedJdbcKitchenOrderRepository(eventLog,
            new Topic("kitchen_orders"),
            pool);
    ref = repository.nextIdentity();
    kitchenOrder = KitchenOrder.builder()
            .ref(ref)
            .onlineOrderRef(new OnlineOrderRef())
            .pizza(KitchenOrder.Pizza.builder().size(KitchenOrder.Pizza.Size.MEDIUM).build())
            .eventLog(eventLog)
            .build();
}
 
Example 6
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    eventLog = InProcessEventLog.instance();
    repository = new EmbeddedJdbcPizzaRepository(eventLog,
            new Topic("pizzas"),
            pool);
    ref = repository.nextIdentity();
    pizza = Pizza.builder()
            .ref(ref)
            .size(Pizza.Size.MEDIUM)
            .kitchenOrderRef(new KitchenOrderRef(RefStringGenerator.generateRefString()))
            .eventLog(eventLog)
            .build();
}
 
Example 7
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    eventLog = InProcessEventLog.instance();
    repository = new EmbeddedJdbcKitchenOrderRepository(eventLog,
            new Topic("kitchen_orders"),
            pool);
    ref = repository.nextIdentity();
    kitchenOrder = KitchenOrder.builder()
            .ref(ref)
            .onlineOrderRef(new OnlineOrderRef(RefStringGenerator.generateRefString()))
            .pizza(KitchenOrder.Pizza.builder().size(KitchenOrder.Pizza.Size.MEDIUM).build())
            .eventLog(eventLog)
            .build();
}
 
Example 8
@Before
public void setUp() {
    eventLog = InProcessEventLog.instance();
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");
    kitchenOrderRepository = new EmbeddedJdbcKitchenOrderRepository(eventLog,
            new Topic("kitchen_orders"), pool);
    pizzaRepository = new EmbeddedJdbcPizzaRepository(eventLog,
            new Topic("pizzas"), pool);
    orderingService = mock(OrderingService.class);
    kitchenService = new DefaultKitchenService(eventLog, kitchenOrderRepository, pizzaRepository, orderingService);
    kitchenOrderRef = kitchenOrderRepository.nextIdentity();
    kitchenOrder = KitchenOrder.builder()
            .ref(kitchenOrderRef)
            .onlineOrderRef(new OnlineOrderRef(RefStringGenerator.generateRefString()))
            .eventLog(eventLog)
            .pizza(KitchenOrder.Pizza.builder().size(KitchenOrder.Pizza.Size.MEDIUM).build())
            .pizza(KitchenOrder.Pizza.builder().size(KitchenOrder.Pizza.Size.LARGE).build())
            .build();
    kitchenOrderRepository.add(kitchenOrder);
}
 
Example 9
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    eventLog = mock(EventLog.class);
    repository = new EmbeddedJdbcPizzaRepository(eventLog,
            new Topic("pizzas"),
            pool);
    ref = repository.nextIdentity();
    pizza = Pizza.builder()
            .ref(ref)
            .size(Pizza.Size.MEDIUM)
            .kitchenOrderRef(new KitchenOrderRef())
            .eventLog(eventLog)
            .build();
}
 
Example 10
Source Project: dew   Source File: H2ClusterHA.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init(HAConfig haConfig) throws SQLException {
    String url = "jdbc:h2:" + haConfig.getStoragePath() + haConfig.getStorageName() + ";DB_CLOSE_ON_EXIT=FALSE";
    jdbcConnectionPool = JdbcConnectionPool
            .create(url,
                    haConfig.getAuthUsername() == null ? "" : haConfig.getAuthUsername(),
                    haConfig.getAuthPassword() == null ? "" : haConfig.getAuthPassword());
    try (Connection conn = jdbcConnectionPool.getConnection(); Statement stmt = conn.createStatement()) {
        stmt.execute("CREATE TABLE IF NOT EXISTS MQ_MSG("
                + "ADDR VARCHAR(1024),"
                + "MSG_ID VARCHAR(32),"
                + "MSG TEXT,"
                + "CREATED_TIME TIMESTAMP ,"
                + "PRIMARY KEY(MSG_ID)"
                + ")");
    }
}
 
Example 11
@Test
public void initialize_database() {
    JdbcConnectionPool jdbcConnectionPool = JdbcConnectionPool.create("jdbc:h2:mem:", "sa", "");

    PipelineMavenPluginH2Dao dao = new PipelineMavenPluginH2Dao(jdbcConnectionPool) {
        @Override
        protected MigrationStep.JenkinsDetails getJenkinsDetails() {
            return new MigrationStep.JenkinsDetails() {
                @Override
                public String getMasterLegacyInstanceId() {
                    return "123456";
                }

                @Override
                public String getMasterRootUrl() {
                    return "https://jenkins.mycompany.com/";
                }
            };
        }
    };
}
 
Example 12
@Test
public void initialize_database() {
    JdbcConnectionPool jdbcConnectionPool = JdbcConnectionPool.create("jdbc:h2:mem:;MODE=MYSQL", "sa", "");

    AbstractPipelineMavenPluginDao dao = new PipelineMavenPluginMySqlDao(jdbcConnectionPool) {
        @Override
        protected MigrationStep.JenkinsDetails getJenkinsDetails() {
            return new MigrationStep.JenkinsDetails() {
                @Override
                public String getMasterLegacyInstanceId() {
                    return "123456";
                }

                @Override
                public String getMasterRootUrl() {
                    return "https://jenkins.mycompany.com/";
                }
            };
        }
    };
}
 
Example 13
Source Project: jsonde   Source File: Client.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
    }
 
Example 14
Source Project: jsonde   Source File: Client.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Client(String databaseFileName) {

        online = false;

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

        try {

            DaoFactory.initialize(
                    jdbcConnectionPool
            );

        } catch (DaoException e) {
            e.printStackTrace();
        }
    }
 
Example 15
Source Project: quarkus-http   Source File: JDBCLogDatabaseTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws SQLException {
    ds = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "user", "password");
    Connection conn = null;
    Statement statement = null;
    try {
        conn = ds.getConnection();
        conn.setAutoCommit(true);
        statement = conn.createStatement();
        statement.executeUpdate("CREATE TABLE PUBLIC.ACCESS (" +
                " id SERIAL NOT NULL," +
                " remoteHost CHAR(15) NOT NULL," +
                " userName CHAR(15)," +
                " timestamp TIMESTAMP NOT NULL," +
                " virtualHost VARCHAR(64)," +
                " method VARCHAR(8)," +
                " query VARCHAR(255) NOT NULL," +
                " status SMALLINT UNSIGNED NOT NULL," +
                " bytes INT UNSIGNED NOT NULL," +
                " referer VARCHAR(128)," +
                " userAgent VARCHAR(128)," +
                " PRIMARY KEY (id)" +
                " );");
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (conn != null) {
            conn.close();
        }

    }

}
 
Example 16
@Before
public void setUp() {
    eventLog = InProcessEventLog.instance();
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "", "");
    repository = new EmbeddedJdbcPaymentRepository(eventLog,
            new Topic("payments"), pool);
    processor = mock(PaymentProcessor.class);
    new DefaultPaymentService(processor,
            repository,
            eventLog);
}
 
Example 17
public EmbeddedJdbcDeliveryOrderRepository(EventLog eventLog, Topic topic, JdbcConnectionPool pool) {
    this.eventLog = eventLog;
    this.topic = topic;
    this.pool = pool;

    try (Connection connection = pool.getConnection()) {
        PreparedStatement statement = connection.prepareStatement("CREATE TABLE DELIVERY_ORDERS (REF VARCHAR(255), KITCHEN_ORDER_REF VARCHAR(255), ONLINE_ORDER_REF VARCHAR(255), STATE INT)");
        statement.execute();

        statement = connection.prepareStatement("CREATE TABLE DELIVERY_ORDER_PIZZAS (REF VARCHAR(255), INDEX INT, SIZE INT)");
        statement.execute();
    } catch (SQLException e) {
        throw new RuntimeException("Unable to initialize KITCHEN_ORDERS table: ", e);
    }
}
 
Example 18
@Before
public void setUp() {
    eventLog = InProcessEventLog.instance();
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");

    DeliveryOrderRepository deliveryOrderRepository = new EmbeddedJdbcDeliveryOrderRepository(eventLog,
            new Topic("delivery_orders"),
            pool);
    orderingService = mock(OrderingService.class);
    kitchenService = mock(KitchenService.class);
    deliveryService = new DeliveryService(eventLog, deliveryOrderRepository, orderingService, kitchenService);
}
 
Example 19
@Before
public void setUp() {
    eventLog = InProcessEventLog.instance();
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test;MVCC=FALSE", "", "");
    repository = new EmbeddedJdbcOnlineOrderRepository(eventLog,
            new Topic("ordering"), pool);
    new DefaultOrderingService(eventLog, repository, mock(PaymentService.class));
}
 
Example 20
@Before
public void setUp() {
    pool = JdbcConnectionPool.create("jdbc:h2:mem:test", "", "");

    eventLog = mock(EventLog.class);
    repository = new EmbeddedJdbcOnlineOrderRepository(eventLog,
            new Topic("ordering"),
            pool);
    ref = repository.nextIdentity();
    onlineOrder = OnlineOrder.builder()
            .ref(ref)
            .type(OnlineOrder.Type.PICKUP)
            .eventLog(eventLog)
            .build();
}
 
Example 21
Source Project: syndesis   Source File: SqlJsonDBIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
public void prepare() {
    bus = mock(EventBus.class);

    final DataSource dataSource = JdbcConnectionPool.create("jdbc:h2:mem:", "sa", "password");
    final DBI dbi = new DBI(dataSource);
    jsonDB = new SqlJsonDB(dbi, bus);
    jsonDB.createTables();
}
 
Example 22
Source Project: nifi-registry   Source File: LegacyDataSourceFactory.java    License: Apache License 2.0 5 votes vote down vote up
public DataSource getDataSource() {
    if (connectionPool == null) {
        final String databaseUrl = getDatabaseUrl(properties);
        connectionPool = JdbcConnectionPool.create(databaseUrl, DB_USERNAME_PASSWORD, DB_USERNAME_PASSWORD);
        connectionPool.setMaxConnections(MAX_CONNECTIONS);
    }

    return connectionPool;
}
 
Example 23
public void createConnectionPool(String connectString, String userName, String pwd) throws OpenAS2Exception {
    // Check that a connection pool is not already running
    if (cp != null) {
        throw new OpenAS2Exception("Connection pool already initialized. Cannot create a new connection pool. Stop current one first. DB connect string:" + connectString + " :: Active pool connect string: " + this.connectString);
    }
    this.connectString = connectString;

    cp = JdbcConnectionPool.create(connectString, userName, pwd);
}
 
Example 24
Source Project: ignite   Source File: H2CacheStoreStrategy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Connection pool
 */
static JdbcConnectionPool createDataSource(int port) {
    JdbcConnectionPool pool = JdbcConnectionPool.create("jdbc:h2:tcp://localhost:" + port +
        "/mem:TestDb;LOCK_MODE=0", "sa", "");

    pool.setMaxConnections(Integer.getInteger("H2_JDBC_CONNECTIONS", 100));
    return pool;
}
 
Example 25
/** {@inheritDoc} */
@Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
    return new Factory<CacheStoreSessionListener>() {
        @Override public CacheStoreSessionListener create() {
            CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();

            lsnr.setDataSource(JdbcConnectionPool.create(URL, "", ""));

            return lsnr;
        }
    };
}
 
Example 26
Source Project: ignite   Source File: DbH2ServerStartup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Populate sample database.
 *
 * @throws SQLException if
 */
public static void populateDatabase() throws SQLException {
    // Try to connect to database TCP server.
    JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");

    // Create Person table in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));

    // Populates Person table with sample data in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
}
 
Example 27
Source Project: ignite   Source File: DbH2ServerStartup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Start H2 database TCP server.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If start H2 database TCP server failed.
 */
public static void main(String[] args) throws IgniteException {
    try {
        // Start H2 database TCP server in order to access sample in-memory database from other processes.
        Server.createTcpServer("-tcpDaemon").start();

        populateDatabase();

        // Try to connect to database TCP server.
        JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");

        // Create Person table in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));

        // Populates Person table with sample data in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
    }
    catch (SQLException e) {
        throw new IgniteException("Failed to start database TCP server", e);
    }

    try {
        do {
            System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
        }
        while ('q' != System.in.read());
    }
    catch (IOException ignored) {
        // No-op.
    }
}
 
Example 28
Source Project: magarena   Source File: H2Database.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JdbcConnectionPool getConnectionPool() {
    // http://www.h2database.com/html/features.html#trace_options
    String traceLevel = "TRACE_LEVEL_FILE=0"; // 0=OFF, 1=ERROR
    return JdbcConnectionPool.create(
        "jdbc:h2:file:" + getDatabaseFile() + ";" + traceLevel,
        "sa", ""
    );
}
 
Example 29
Source Project: jsonde   Source File: MethodDaoTest.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    testDataSource =
            JdbcConnectionPool.create("jdbc:h2:target/test-database/db", "sa", "sa");
    methodDao =
            new MethodDao(testDataSource);

    methodDao.createTable();

}
 
Example 30
Source Project: jsonde   Source File: ClazzDaoTest.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    testDataSource =
            JdbcConnectionPool.create("jdbc:h2:target/test-database/db", "sa", "sa");
    clazzDao =
            new ClazzDao(testDataSource);

    clazzDao.createTable();

}