refactor: switching to h2 datasource

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
pull/453/head
Ilya Buziuk 2023-02-21 09:45:49 +01:00 committed by Ilya Buziuk
parent 47184c4953
commit dcb0884fe0
4 changed files with 62 additions and 2 deletions

View File

@ -187,6 +187,10 @@
<groupId>org.eclipse.che.core</groupId> <groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-db</artifactId> <artifactId>che-core-db</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-db-vendor-h2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.che.core</groupId> <groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-db-vendor-postgresql</artifactId> <artifactId>che-core-db-vendor-postgresql</artifactId>
@ -455,6 +459,7 @@
<dep>org.everrest:everrest-core</dep> <dep>org.everrest:everrest-core</dep>
<dep>io.jsonwebtoken:jjwt-jackson</dep> <dep>io.jsonwebtoken:jjwt-jackson</dep>
<dep>io.jsonwebtoken:jjwt-impl</dep> <dep>io.jsonwebtoken:jjwt-impl</dep>
<dep>org.eclipse.che.core:che-core-db-vendor-h2</dep>
</ignoredUnusedDeclaredDependencies> </ignoredUnusedDeclaredDependencies>
</configuration> </configuration>
</execution> </execution>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (c) 2012-2021 Red Hat, Inc. Copyright (c) 2012-2023 Red Hat, Inc.
This program and the accompanying materials are made This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0 available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/ which is available at https://www.eclipse.org/legal/epl-2.0/
@ -16,5 +16,5 @@
<Resource name="jdbc/che" auth="Container" <Resource name="jdbc/che" auth="Container"
type="javax.sql.DataSource" type="javax.sql.DataSource"
factory="org.eclipse.che.core.db.postgresql.PostgreSQLJndiDataSourceFactory"/> factory="org.eclipse.che.core.db.h2.jpa.eclipselink.H2SQLJndiDataSourceFactory"/>
</Context> </Context>

View File

@ -22,6 +22,14 @@
<artifactId>che-core-db-vendor-h2</artifactId> <artifactId>che-core-db-vendor-h2</artifactId>
<name>Che Core :: Commons :: DB :: Vendor H2</name> <name>Che Core :: Commons :: DB :: Vendor H2</name>
<dependencies> <dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.che.core</groupId> <groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-db</artifactId> <artifactId>che-core-db</artifactId>

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2012-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.db.h2.jpa.eclipselink;
import static com.google.common.base.MoreObjects.firstNonNull;
import org.eclipse.che.core.db.JNDIDataSourceFactory;
public class H2SQLJndiDataSourceFactory extends JNDIDataSourceFactory {
private static final String DEFAULT_USERNAME = "username";
private static final String DEFAULT_PASSWORD = "password";
private static final String DEFAULT_URL = "jdbc:h2:file:/data/h2";
private static final String DEFAULT_DRIVER__CLASS__NAME = "org.h2.Driver";
private static final String DEFAULT_MAX__TOTAL = "20";
private static final String DEFAULT_MAX__IDLE = "2";
private static final String DEFAULT_MAX__WAIT__MILLIS = "-1";
public H2SQLJndiDataSourceFactory() throws Exception {
super(
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_USERNAME")), DEFAULT_USERNAME),
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_PASSWORD")), DEFAULT_PASSWORD),
firstNonNull(nullStringToNullReference(System.getenv("CHE_JDBC_H2_URL")), DEFAULT_URL),
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_DRIVER__CLASS__NAME")),
DEFAULT_DRIVER__CLASS__NAME),
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__TOTAL")), DEFAULT_MAX__TOTAL),
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__IDLE")), DEFAULT_MAX__IDLE),
firstNonNull(
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__WAIT__MILLIS")),
DEFAULT_MAX__WAIT__MILLIS));
;
}
}