Skip to content

Commit 8306e7a

Browse files
Default h2 db support in ofbiz trunk (#1221)
Improved: OFBIZ-13412 - Removing Apache Derby support from the Apache OFBiz project and adding support of H2 database in the project. After the changes, I placed and completed a sales order. And then created a customer in the ofbiz backend. Everything seems to be working fine with h2 database.
1 parent 8e2e0f8 commit 8306e7a

14 files changed

Lines changed: 76 additions & 98 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,8 @@ task pullPlugin(group: ofbizPlugin, description: 'Download and install a plugin
966966
task cleanCatalina(group: cleanupGroup, description: 'Clean Catalina data in runtime/catalina/work') {
967967
doLast { delete "${rootDir}/runtime/catalina/work" }
968968
}
969-
task cleanData(group: cleanupGroup, description: 'Clean all DB data (Derby) under runtime/data') {
970-
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/data/", ['README', 'derby.properties']) }
969+
task cleanData(group: cleanupGroup, description: 'Clean all DB data (H2) under runtime/data') {
970+
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/data/", ['README', '.h2.server.properties']) }
971971
}
972972
task cleanDownloads(group: cleanupGroup, description: 'Clean all downloaded files') {
973973
doLast {

dependencies.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ dependencies {
9797
runtimeOnly 'org.apache.avalon.framework:avalon-framework-impl:4.3.1'
9898
runtimeOnly 'org.apache.axis2:axis2-transport-http:1.8.2'
9999
runtimeOnly 'org.apache.axis2:axis2-transport-local:1.8.2'
100-
runtimeOnly 'org.apache.derby:derby:10.16.1.1' // 10.17.x.x requires Java 21
101-
runtimeOnly 'org.apache.derby:derbytools:10.16.1.1' // 10.17.x.x requires Java 21
100+
runtimeOnly 'com.h2database:h2:2.2.224'
102101
runtimeOnly 'org.apache.geronimo.specs:geronimo-jaxrpc_1.1_spec:2.1'
103102
runtimeOnly 'org.apache.logging.log4j:log4j-1.2-api:2.25.4' // for external jars using the old log4j1.2: routes logging to log4j 2
104103
runtimeOnly 'org.apache.logging.log4j:log4j-jul:2.25.4' // for external jars using the java.util.logging: routes logging to log4j 2

docker/templates/postgres-entityengine.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ access. For a detailed description see the core/docs/entityconfig.html file.
5050

5151
<!-- Be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "gradlew loadAll" before running "gradlew testIntegration" -->
5252
<delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main">
53-
<group-map group-name="org.apache.ofbiz" datasource-name="localderby"/>
53+
<group-map group-name="org.apache.ofbiz" datasource-name="localpostgres"/>
5454
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localpostgresolap"/>
5555
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localpostgrestenant"/>
5656
</delegator>

framework/base/config/passwords.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# under the License.
1818
###############################################################################
1919

20-
jdbc-password.derby-ofbiz=ofbiz
21-
jdbc-password.derby-ofbizodbc=ofbiz
22-
jdbc-password.derby-ofbizolap=ofbiz
23-
jdbc-password.derby-ofbiztenant=ofbiz
20+
jdbc-password.h2-ofbiz=ofbiz
21+
jdbc-password.h2-ofbizodbc=ofbiz
22+
jdbc-password.h2-ofbizolap=ofbiz
23+
jdbc-password.h2-ofbiztenant=ofbiz

framework/entity/config/entityengine.xml

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ access. For a detailed description see the core/docs/entityconfig.html file.
5252
<debug-xa-resources value="false" /> <!-- see https://issues.apache.org/jira/browse/OFBIZ-4282 for more -->
5353

5454
<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
55-
<group-map group-name="org.apache.ofbiz" datasource-name="localderby"/>
56-
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localderbyolap"/>
57-
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localderbytenant"/>
55+
<group-map group-name="org.apache.ofbiz" datasource-name="localh2"/>
56+
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localh2olap"/>
57+
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localh2tenant"/>
5858
</delegator>
5959
<!-- May be used when you create a service that manages many data for massive imports, this for performance reason or to escape functional cases -->
6060
<delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
61-
<group-map group-name="org.apache.ofbiz" datasource-name="localderby"/>
62-
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localderbyolap"/>
63-
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localderbytenant"/>
61+
<group-map group-name="org.apache.ofbiz" datasource-name="localh2"/>
62+
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localh2olap"/>
63+
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localh2tenant"/>
6464
</delegator>
6565

6666
<!-- Be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "gradlew loadAll" before running "gradlew testIntegration" -->
6767
<delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main">
68-
<group-map group-name="org.apache.ofbiz" datasource-name="localderby"/>
69-
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localderbyolap"/>
70-
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localderbytenant"/>
68+
<group-map group-name="org.apache.ofbiz" datasource-name="localh2"/>
69+
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localh2olap"/>
70+
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localh2tenant"/>
7171
</delegator>
7272

7373
<!-- need to at least define a name for each component to use -->
@@ -98,7 +98,7 @@ access. For a detailed description see the core/docs/entityconfig.html file.
9898
<entity-data-reader name="ext-demo"/>
9999

100100
<field-type name="hsql" loader="fieldfile" location="fieldtypehsql.xml"/>
101-
<field-type name="derby" loader="fieldfile" location="fieldtypederby.xml"/>
101+
<field-type name="h2" loader="fieldfile" location="fieldtypeh2.xml"/>
102102
<field-type name="daffodil" loader="fieldfile" location="fieldtypedaffodil.xml"/>
103103
<field-type name="axion" loader="fieldfile" location="fieldtypeaxion.xml"/>
104104
<field-type name="mysql" loader="fieldfile" location="fieldtypemysql.xml"/>
@@ -157,12 +157,13 @@ access. For a detailed description see the core/docs/entityconfig.html file.
157157
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="localhsqlDataSource"/> --> <!-- Weblogic Style JNDI name -->
158158
</datasource>
159159

160-
<datasource name="localderby"
160+
<datasource name="localh2"
161161
helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
162162
schema-name="OFBIZ"
163-
field-type-name="derby"
163+
field-type-name="h2"
164164
check-on-start="true"
165165
add-missing-on-start="true"
166+
max-worker-pool-size="1"
166167
use-pk-constraint-names="false"
167168
use-indices-unique="false"
168169
alias-view-columns="false"
@@ -175,55 +176,61 @@ access. For a detailed description see the core/docs/entityconfig.html file.
175176
<read-data reader-name="ext"/>
176177
<read-data reader-name="ext-test"/>
177178
<read-data reader-name="ext-demo"/>
178-
<!-- beware use-indices-unique="false" is needed because of Derby bug with null values in a unique index -->
179+
179180
<inline-jdbc
180-
jdbc-driver="org.apache.derby.jdbc.EmbeddedDriver"
181-
jdbc-uri="jdbc:derby:ofbiz;create=true"
181+
jdbc-driver="org.h2.Driver"
182+
jdbc-uri="jdbc:h2:file:./runtime/data/h2/ofbiz;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000;INIT=CREATE SCHEMA IF NOT EXISTS OFBIZ"
182183
jdbc-username="ofbiz"
183-
jdbc-password-lookup="derby-ofbiz"
184+
jdbc-password-lookup="h2-ofbiz"
184185
isolation-level="ReadCommitted"
185-
pool-minsize="2"
186+
pool-minsize="0"
186187
pool-maxsize="250"
188+
pool-sleeptime="300000"
187189
test-on-borrow="true"
188-
pool-jdbc-test-stmt="values 1"
190+
pool-jdbc-test-stmt="SELECT 1"
189191
soft-min-evictable-idle-time-millis="600000"
190192
time-between-eviction-runs-millis="600000"/>
191-
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/DerbyDataSource" isolation-level="ReadCommitted"/> -->
193+
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/H2DataSource" isolation-level="ReadCommitted"/> -->
192194
</datasource>
193-
<datasource name="localderbyodbc"
195+
<datasource name="localh2odbc"
194196
helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
195-
schema-name="OFBIZ"
196-
field-type-name="derby"
197+
schema-name="ODBC"
198+
field-type-name="h2"
197199
check-on-start="true"
198200
add-missing-on-start="true"
201+
max-worker-pool-size="1"
199202
use-pk-constraint-names="false"
200203
use-indices-unique="false"
201204
alias-view-columns="false"
202205
use-order-by-nulls="true"
203206
offset-style="fetch">
204-
<!-- beware use-indices-unique="false" is needed because of Derby bug with null values in a unique index -->
207+
205208
<inline-jdbc
206-
jdbc-driver="org.apache.derby.jdbc.EmbeddedDriver"
207-
jdbc-uri="jdbc:derby:ofbizodbc;create=true"
209+
jdbc-driver="org.h2.Driver"
210+
jdbc-uri="jdbc:h2:file:./runtime/data/h2/ofbiz;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000;INIT=CREATE SCHEMA IF NOT EXISTS ODBC"
208211
jdbc-username="ofbiz"
209-
jdbc-password-lookup="derby-ofbizodbc"
212+
jdbc-password-lookup="h2-ofbizodbc"
210213
isolation-level="ReadCommitted"
211-
pool-minsize="2"
214+
pool-minsize="0"
212215
pool-maxsize="250"
213-
time-between-eviction-runs-millis="600000"/>
214-
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/DerbyDataSource" isolation-level="ReadCommitted"/> -->
216+
pool-sleeptime="300000"
217+
test-on-borrow="true"
218+
pool-jdbc-test-stmt="SELECT 1"
219+
time-between-eviction-runs-millis="600000"/>
220+
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/H2DataSource" isolation-level="ReadCommitted"/> -->
215221
</datasource>
216-
<datasource name="localderbyolap"
222+
<datasource name="localh2olap"
217223
helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
218-
schema-name="OFBIZ"
219-
field-type-name="derby"
224+
schema-name="OLAP"
225+
field-type-name="h2"
220226
check-on-start="true"
221227
add-missing-on-start="true"
228+
max-worker-pool-size="1"
222229
use-pk-constraint-names="false"
223230
use-indices-unique="false"
224231
alias-view-columns="false"
225232
use-order-by-nulls="true">
226-
<!-- beware use-indices-unique="false" is needed because of Derby bug with null values in a unique index -->
233+
227234
<read-data reader-name="tenant"/>
228235
<read-data reader-name="seed"/>
229236
<read-data reader-name="seed-initial"/>
@@ -232,22 +239,26 @@ access. For a detailed description see the core/docs/entityconfig.html file.
232239
<read-data reader-name="ext-test"/>
233240
<read-data reader-name="ext-demo"/>
234241
<inline-jdbc
235-
jdbc-driver="org.apache.derby.jdbc.EmbeddedDriver"
236-
jdbc-uri="jdbc:derby:ofbizolap;create=true"
242+
jdbc-driver="org.h2.Driver"
243+
jdbc-uri="jdbc:h2:file:./runtime/data/h2/ofbiz;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000;INIT=CREATE SCHEMA IF NOT EXISTS OLAP"
237244
jdbc-username="ofbiz"
238-
jdbc-password-lookup="derby-ofbizolap"
245+
jdbc-password-lookup="h2-ofbizolap"
239246
isolation-level="ReadCommitted"
240-
pool-minsize="2"
247+
pool-minsize="0"
241248
pool-maxsize="250"
249+
pool-sleeptime="300000"
250+
test-on-borrow="true"
251+
pool-jdbc-test-stmt="SELECT 1"
242252
time-between-eviction-runs-millis="600000"/>
243-
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/DerbyDataSource" isolation-level="ReadCommitted"/> -->
253+
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/H2DataSource" isolation-level="ReadCommitted"/> -->
244254
</datasource>
245-
<datasource name="localderbytenant"
255+
<datasource name="localh2tenant"
246256
helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
247-
schema-name="OFBIZ"
248-
field-type-name="derby"
257+
schema-name="TENANT"
258+
field-type-name="h2"
249259
check-on-start="true"
250260
add-missing-on-start="true"
261+
max-worker-pool-size="1"
251262
use-pk-constraint-names="false"
252263
use-indices-unique="false"
253264
alias-view-columns="false"
@@ -259,17 +270,20 @@ access. For a detailed description see the core/docs/entityconfig.html file.
259270
<read-data reader-name="ext"/>
260271
<read-data reader-name="ext-test"/>
261272
<read-data reader-name="ext-demo"/>
262-
<!-- beware use-indices-unique="false" is needed because of Derby bug with null values in a unique index -->
273+
263274
<inline-jdbc
264-
jdbc-driver="org.apache.derby.jdbc.EmbeddedDriver"
265-
jdbc-uri="jdbc:derby:ofbiztenant;create=true"
275+
jdbc-driver="org.h2.Driver"
276+
jdbc-uri="jdbc:h2:file:./runtime/data/h2/ofbiz;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000;INIT=CREATE SCHEMA IF NOT EXISTS TENANT"
266277
jdbc-username="ofbiz"
267-
jdbc-password-lookup="derby-ofbiztenant"
278+
jdbc-password-lookup="h2-ofbiztenant"
268279
isolation-level="ReadCommitted"
269-
pool-minsize="2"
280+
pool-minsize="0"
270281
pool-maxsize="250"
282+
pool-sleeptime="300000"
283+
test-on-borrow="true"
284+
pool-jdbc-test-stmt="SELECT 1"
271285
time-between-eviction-runs-millis="600000"/>
272-
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/DerbyDataSource" isolation-level="ReadCommitted"/> -->
286+
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/H2DataSource" isolation-level="ReadCommitted"/> -->
273287
</datasource>
274288

275289
<datasource name="localdaffodil"
@@ -810,12 +824,12 @@ access. For a detailed description see the core/docs/entityconfig.html file.
810824
time-between-eviction-runs-millis="600000"/>
811825
</datasource>
812826

813-
<!-- According to http://markmail.org/message/s75sf6zhtizzkqbv Since version V6R1 (AS/400, db2) there is no need for an own fieldtype.xml - just use the derby-fieldtypes like this: -->
827+
<!-- According to http://markmail.org/message/s75sf6zhtizzkqbv Since version V6R1 (AS/400, db2) there is no need for an own fieldtype.xml - just use the h2-fieldtypes like this: -->
814828
<!-- Beware use-indices-unique="false" is needed because of Derby bug with null values in a unique index, not sure it's needed with DB2 -->
815829
<datasource name="DB2"
816830
helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
817831
schema-name="OFBIZ"
818-
field-type-name="derby"
832+
field-type-name="h2"
819833
check-on-start="true"
820834
add-missing-on-start="true"
821835
use-pk-constraint-names="false"
File renamed without changes.

framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ public Element toGroupXmlElement(Document document, String packageName) {
21742174
public void writeEoModelText(PrintWriter writer, String entityPrefix, String helperName, Set<String> entityNameIncludeSet,
21752175
ModelReader entityModelReader) throws GenericEntityException {
21762176
if (entityPrefix == null) entityPrefix = "";
2177-
if (helperName == null) helperName = "localderby";
2177+
if (helperName == null) helperName = "localh2";
21782178

21792179
UtilPlist.writePlistPropertyMap(this.createEoModelMap(entityPrefix, helperName, entityNameIncludeSet, entityModelReader), 0, writer, false);
21802180
}

framework/entity/src/test/java/org/apache/ofbiz/entity/DelegatorUnitTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public class DelegatorUnitTests {
3939
@Before
4040
public void initialize() {
4141
System.setProperty("ofbiz.home", System.getProperty("user.dir"));
42-
System.setProperty("derby.system.home", "./runtime/data/derby");
4342
logErrorOn = Debug.isOn(Debug.ERROR); // save the current setting (to be restored after the tests)
4443
Debug.set(Debug.ERROR, false); // disable error logging
4544
}

framework/resources/templates/AdminNewTenantData-Derby.xml renamed to framework/resources/templates/AdminNewTenantData-H2.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ under the License.
2222
<Tenant tenantId="@tenantId@" tenantName="@tenantName@" />
2323
<TenantDomainName tenantId="@tenantId@" domainName="@domainName@" />
2424
<TenantDataSource tenantId="@tenantId@" entityGroupName="org.apache.ofbiz"
25-
jdbcUri="jdbc:derby:ofbiz_@tenantId@;create=true" jdbcUsername="ofbiz" jdbcPassword="ofbiz"/>
25+
jdbcUri="jdbc:h2:file:./runtime/data/h2/ofbiz_@tenantId@;AUTO_SERVER=TRUE" jdbcUsername="ofbiz" jdbcPassword="ofbiz"/>
2626
<TenantDataSource tenantId="@tenantId@" entityGroupName="org.apache.ofbiz.olap"
27-
jdbcUri="jdbc:derby:ofbizolap_@tenantId@;create=true" jdbcUsername="ofbiz" jdbcPassword="ofbiz"/>
28-
</entity-engine-xml>
27+
jdbcUri="jdbc:h2:file:./runtime/data/h2/ofbizolap_@tenantId@;AUTO_SERVER=TRUE" jdbcUsername="ofbiz" jdbcPassword="ofbiz"/>
28+
</entity-engine-xml>

framework/service/src/test/groovy/org/apache/ofbiz/service/ModelServiceTest.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class ModelServiceTest {
4646
@Before
4747
void initialize() {
4848
System.setProperty('ofbiz.home', System.getProperty('user.dir'))
49-
System.setProperty('derby.system.home', './runtime/data/derby')
5049
dispatcher = Mockito.mock(LocalDispatcher)
5150
Mockito.when(dispatcher.getDelegator()).thenReturn(DelegatorFactory.getDelegator('default'))
5251
}

0 commit comments

Comments
 (0)