Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new H2 version #990

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions h2-engine/2.2.220.wso2v1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>org.wso2.orbit.com.h2database</groupId>
<artifactId>h2-engine</artifactId>
<version>2.2.220.wso2v1</version>
<packaging>bundle</packaging>
<modelVersion>4.0.0</modelVersion>
<name>WSO2 Carbon Orbit - H2 OSGi Database Service</name>

<distributionManagement>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.9.1.v20130814-1242</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
</dependencies>

<properties>
<h2.engine.orbit.version>2.2.220.wso2v1</h2.engine.orbit.version>
</properties>

<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>org.h2.*</Private-Package>
<Export-Package>
org.wso2.carbon.h2.osgi.*;version="${h2.engine.orbit.version}",
</Export-Package>
<_exportcontents>org.h2.*;version=2.2.220.wso2v1</_exportcontents>
<Bundle-Activator>org.wso2.carbon.h2.osgi.H2DatabaseServiceActivator</Bundle-Activator>
<Import-Package>
org.apache.lucene.analysis;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.analysis.standard;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.document;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.index;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.queryParser;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.search;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.store;version="[3.6.2,4.0.0)";resolution:=optional,
org.apache.lucene.util;version="[3.6.2,4.0.0)";resolution:=optional,
com.vividsolutions.jts.geom;version="1.14.0";resolution:=optional,
com.vividsolutions.jts.io;version="1.14.0";resolution:=optional,
org.h2;version="[${project.version},2.3.0)",
org.h2.api;version="[${project.version},2.3.0)",
org.h2.fulltext;version="[${project.version},2.3.0)",
org.h2.jdbcx;version="[${project.version},2.3.0)",
org.h2.util;version="[${project.version},2.3.0)",
org.h2.value;version="[${project.version},2.3.0)",
org.osgi.framework,
org.osgi.service.jdbc;resolution:=optional,
org.slf4j;version="[1.6.0,1.7.0)";resolution:=optional
</Import-Package>
<Embed-Dependency>
h2;scope=compile|runtime;inline=false;
</Embed-Dependency>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.h2.osgi;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.wso2.carbon.h2.osgi.database.H2DatabaseManager;

/**
* This class is used to activate and deactivate the H2 database service.
*/
public class H2DatabaseServiceActivator implements BundleActivator {

public void start(BundleContext arg0) {

H2DatabaseManager.getInstance().initialize();
}

public void stop(BundleContext arg0) {

H2DatabaseManager.getInstance().terminate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.h2.osgi.database;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.h2.Driver;
import org.h2.engine.Database;
import org.h2.engine.Engine;
import org.wso2.carbon.h2.osgi.utils.H2Constants;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* H2 Database Manager.
*/
public class H2DatabaseManager {

private static final H2DatabaseManager instance = new H2DatabaseManager();
private static final Log log = LogFactory.getLog(H2DatabaseManager.class);

private H2DatabaseManager() {
}

public synchronized static H2DatabaseManager getInstance() {

return instance;
}

public void initialize() {

Driver.load();
}

public void terminate() {

closeAllOpenDatabases();
}

private void closeAllOpenDatabases() {

Field fields[] = Engine.class.getDeclaredFields();

for (Field var : fields) {
if ((var.getType() == HashMap.class) && (var.getName().equals(H2Constants.ENGINE_VAR_DATABASES))) {
var.setAccessible(true);
Object pass = new Object();
try {
Object fieldValue = var.get(pass);
if (fieldValue instanceof HashMap) {
Map<String, Database> databases = (HashMap<String, Database>) fieldValue;

List<Database> openDatabases = new ArrayList<Database>();
openDatabases.addAll(databases.values());

for (Iterator iterator = openDatabases.iterator(); iterator.hasNext(); ) {
Database database = (Database) iterator.next();
Method declaredMethod = null;
try {
declaredMethod = database.getClass().getDeclaredMethod(H2Constants.ENGINE_METHOD_CLOSE,
new Class[]{boolean.class});
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
declaredMethod.invoke(database, new Object[]{true});
} else {
log.error("Database close method not found in class " +
database.getClass().getName());
}
} catch (InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error("Error when closing H2 database", e);
}
}
}
} catch (IllegalAccessException | IllegalArgumentException e) {
log.error("Error when closing H2 database", e);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.h2.osgi.utils;

/**
* Holds the H2 DB related constants.
*/
public class H2Constants {

public static final String ENGINE_VAR_DATABASES = "DATABASES";
public static final String ENGINE_METHOD_CLOSE = "close";

}