org.h2.jdbcx.JdbcConnectionPool Java Examples

The following examples show how to use org.h2.jdbcx.JdbcConnectionPool. 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
Source File: EmbeddedJdbcPaymentRepositoryTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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
Source File: Client.java    From jsonde with 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 #3
Source File: Client.java    From jsonde with 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 #4
Source File: PipelineMavenPluginMySqlDaoInitializationTest.java    From pipeline-maven-plugin with MIT License 6 votes vote down vote up
@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 #5
Source File: PipelineMavenPluginH2DaoInitializationTest.java    From pipeline-maven-plugin with MIT License 6 votes vote down vote up
@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 #6
Source File: H2ClusterHA.java    From dew with 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 #7
Source File: EmbeddedJdbcPizzaRepositoryTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #8
Source File: DefaultKitchenServiceWithJdbcIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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
Source File: EmbeddedJdbcKitchenOrderRepositoryIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #10
Source File: EmbeddedJdbcPizzaRepositoryIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #11
Source File: EmbeddedJdbcOnlineOrderRepositoryIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #12
Source File: EmbeddedJdbcKitchenOrderRepositoryTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #13
Source File: EmbeddedJdbcDeliveryOrderRepositoryTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #14
Source File: EmbeddedJdbcPaymentRepositoryIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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 #15
Source File: LegacyDataSourceFactory.java    From nifi-registry with 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 #16
Source File: DbH2ServerStartup.java    From ignite with 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 #17
Source File: DbH2ServerStartup.java    From ignite with 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 #18
Source File: CacheJdbcStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@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 #19
Source File: H2CacheStoreStrategy.java    From ignite with 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 #20
Source File: EmbeddedDBHandler.java    From OpenAs2App with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #21
Source File: H2Database.java    From magarena with 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 #22
Source File: DefaultPaymentServiceWithJdbcIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 5 votes vote down vote up
@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 #23
Source File: JDBCLogDatabaseTestCase.java    From quarkus-http with 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 #24
Source File: MethodDaoTest.java    From jsonde with 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 #25
Source File: EmbeddedJdbcDeliveryOrderRepository.java    From pizza-shop-example with Do What The F*ck You Want To Public License 5 votes vote down vote up
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 #26
Source File: ClazzDaoTest.java    From jsonde with 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();

}
 
Example #27
Source File: SqlJsonDBIntegrationTest.java    From syndesis with 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 #28
Source File: MethodCallSummaryDaoTest.java    From jsonde with 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:mem:testMethodCallSummary", "sa", "sa");

    DaoFactory.initialize(testDataSource);
    DaoFactory.createSchema();

}
 
Example #29
Source File: DeliveryServiceWithJdbcIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 5 votes vote down vote up
@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 #30
Source File: DefaultOrderingServiceWithJdbcIntegrationTests.java    From pizza-shop-example with Do What The F*ck You Want To Public License 5 votes vote down vote up
@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));
}