Skip to content

Commit 9e665c0

Browse files
authored
Merge branch 'master' into OPENJPA-2817_PCClassFileTransformer-exclusions
2 parents 96b2b12 + 093a547 commit 9e665c0

File tree

21 files changed

+905
-92
lines changed

21 files changed

+905
-92
lines changed

.github/workflows/pr-validation.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
3+
# license agreements. See the NOTICE file distributed with this work for additional
4+
# information regarding copyright ownership. The ASF licenses this file to you
5+
# under the Apache License, Version 2.0 (the # "License"); you may not use this
6+
# file except in compliance with the License. You may obtain a copy of the License
7+
# at:
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
#
16+
name: Java CI
17+
on: [push, pull_request]
18+
env:
19+
MAVEN_OPTS: -Dmaven.artifact.threads=256 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: 'Set up JDK 1.8'
26+
uses: actions/setup-java@v1
27+
with:
28+
java-version: '1.8'
29+
- name: 'Cache Maven packages'
30+
uses: actions/cache@v2
31+
with:
32+
path: ~/.m2
33+
key: 'cache'
34+
restore-keys: 'cache'
35+
- name: 'Build with Maven'
36+
run: mvn -B install --file pom.xml
37+
- name: 'Remove Snapshots Before Caching'
38+
run: find ~/.m2 -name '*SNAPSHOT' | xargs rm -Rf

openjpa-jdbc/nbproject/project.properties

Whitespace-only changes.

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public JDBCConfigurationImpl(boolean derivations, boolean loadGlobals) {
215215
"jdatastore", org.apache.openjpa.jdbc.sql.JDataStoreDictionary.class.getName(),
216216
"mariadb", org.apache.openjpa.jdbc.sql.MariaDBDictionary.class.getName(),
217217
"mysql", org.apache.openjpa.jdbc.sql.MySQLDictionary.class.getName(),
218+
"herddb", org.apache.openjpa.jdbc.sql.HerdDBDictionary.class.getName(),
218219
"oracle", org.apache.openjpa.jdbc.sql.OracleDictionary.class.getName(),
219220
"pointbase", org.apache.openjpa.jdbc.sql.PointbaseDictionary.class.getName(),
220221
"postgres", org.apache.openjpa.jdbc.sql.PostgresDictionary.class.getName(),

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifier.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public class DBIdentifier extends IdentifierImpl implements Cloneable, Identifier, Serializable {
3232

33-
33+
3434
private static final long serialVersionUID = 1L;
3535

3636
/**
@@ -754,16 +754,17 @@ public static DBIdentifier toUpper(DBIdentifier name, boolean force) {
754754
if (DBIdentifier.isNull(name)) {
755755
return name;
756756
}
757-
DBIdentifier sName = name.clone();
758-
if (sName.getNameInternal() == null) {
759-
return sName;
757+
if (name.getNameInternal() == null) {
758+
return name;
760759
}
761760
// Do not convert delimited names to upper case. They may have
762761
// been delimited to preserve case.
763-
if (force || !Normalizer.isDelimited(sName.getNameInternal())) {
762+
if (force || !Normalizer.isDelimited(name.getNameInternal())) {
763+
DBIdentifier sName = name.clone();
764764
sName.setNameInternal(sName.getNameInternal().toUpperCase());
765+
return sName;
765766
}
766-
return sName;
767+
return name;
767768
}
768769

769770
/**
@@ -861,16 +862,35 @@ public static DBIdentifier removeDelimiters(DBIdentifier name) {
861862
if (DBIdentifier.isNull(name)) {
862863
return name;
863864
}
864-
DBIdentifier sName = name.clone();
865-
if (isEmpty(sName)) {
866-
return sName;
865+
if (!name.isDelimited()) {
866+
return name;
867867
}
868-
String strName = sName.getNameInternal();
869-
strName = Normalizer.removeDelimiters(strName);
868+
String strName = Normalizer.removeDelimiters(name.getNameInternal());
869+
DBIdentifier sName = name.clone();
870870
sName.setNameInternal(strName);
871871
return sName;
872872
}
873873

874+
/**
875+
* Combine {@link #removeDelimiters(org.apache.openjpa.jdbc.identifier.DBIdentifier) }
876+
* with {@link #toUpper(org.apache.openjpa.jdbc.identifier.DBIdentifier, boolean) }
877+
* in order to save allocations and CPU cycles.
878+
* @param name
879+
* @return
880+
*/
881+
public static DBIdentifier removeDelimitersAndMakeUpper(DBIdentifier name) {
882+
if (DBIdentifier.isNull(name) || name.getNameInternal() == null) {
883+
return name;
884+
}
885+
if (!name.isDelimited()) {
886+
return toUpper(name, true);
887+
}
888+
String strName = Normalizer.removeDelimiters(name.getNameInternal());
889+
DBIdentifier sName = name.clone();
890+
sName.setNameInternal(strName.toUpperCase());
891+
return sName;
892+
}
893+
874894
/**
875895
* Returns a new delimiter with leading and trailing spaces removed.
876896
* @param name

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.List;
4141
import java.util.Set;
4242

43+
import java.util.stream.Collectors;
44+
import java.util.stream.Stream;
4345
import javax.sql.DataSource;
4446

4547
import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -1030,10 +1032,7 @@ private void drop(SchemaGroup db, SchemaGroup repos, boolean considerDatabaseSta
10301032
continue;
10311033

10321034
if (dropColumn(cols[k])) {
1033-
if (dbTable != null)
1034-
dbTable.removeColumn(col);
1035-
else
1036-
_log.warn(_loc.get("drop-col", cols[k], tabs[j]));
1035+
dbTable.removeColumn(col);
10371036
}
10381037
}
10391038
}

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
* @author Abe White
3939
* @author Stephen Kim
4040
*/
41+
4142
public class Table
4243
extends NameSet
4344
implements Comparable<Object>, SourceTracker {
4445

4546
private static final long serialVersionUID = 1L;
4647
private DBIdentifier _name = DBIdentifier.NULL;
4748
private DBIdentifier _schemaName = DBIdentifier.NULL;
49+
// all keys must be normalized with normalizeColumnKey
4850
private Map<DBIdentifier, Column> _colMap = null;
4951
private Map<DBIdentifier, Index> _idxMap = null;
5052
private Collection<ForeignKey> _fkList = null;
@@ -312,12 +314,20 @@ public Column[] getRelationIdColumns() {
312314
return _rels;
313315
}
314316

317+
/**
318+
* Return the list of column names, used only for informative (error) messages.
319+
* @return
320+
*/
315321
public String[] getColumnNames() {
316322
if (_colMap == null) {
317323
return new String[0];
318324
}
319-
DBIdentifier[] sNames = _colMap.keySet().toArray(new DBIdentifier[_colMap.size()]);
320-
return DBIdentifier.toStringArray(sNames);
325+
return _colMap
326+
.values()
327+
.stream()
328+
.map(Column::getIdentifier)
329+
.map(DBIdentifier::getName)
330+
.toArray(String[]::new);
321331
}
322332

323333
/**
@@ -329,10 +339,19 @@ public Column getColumn(String name) {
329339
return getColumn(DBIdentifier.newIdentifier(name, DBIdentifierType.COLUMN, true));
330340
}
331341

332-
public Column getColumn(DBIdentifier name) {
342+
private Column internalGetColumn(DBIdentifier name) {
333343
if (DBIdentifier.isNull(name) || _colMap == null)
334344
return null;
335-
return _colMap.get(DBIdentifier.toUpper(name));
345+
DBIdentifier key = normalizeColumnKey(name);
346+
return _colMap.get(key);
347+
}
348+
349+
public Column getColumn(DBIdentifier name) {
350+
return internalGetColumn(name);
351+
}
352+
353+
private static DBIdentifier normalizeColumnKey(DBIdentifier name) {
354+
return DBIdentifier.removeDelimitersAndMakeUpper(name);
336355
}
337356

338357
public Column getColumn(DBIdentifier name, boolean create) {
@@ -375,8 +394,7 @@ public boolean containsColumn(DBIdentifier name, DBDictionary dict) {
375394
if (DBIdentifier.isNull(name) || _colMap == null) {
376395
return false;
377396
}
378-
DBIdentifier sName = DBIdentifier.toUpper(name);
379-
return _colMap.containsKey(sName);
397+
return _colMap.containsKey(normalizeColumnKey(name));
380398
}
381399

382400
public boolean containsColumn(Column col) {
@@ -414,8 +432,7 @@ public Column addColumn(DBIdentifier name) {
414432
}
415433
if (_colMap == null)
416434
_colMap = new LinkedHashMap<>();
417-
DBIdentifier sName = DBIdentifier.toUpper(name);
418-
_colMap.put(sName, col);
435+
_colMap.put(normalizeColumnKey(name), col);
419436
_cols = null;
420437
return col;
421438
}
@@ -440,8 +457,7 @@ public Column addColumn(DBIdentifier name, DBIdentifier validName) {
440457
col = new Column(validName, this);
441458
if (_colMap == null)
442459
_colMap = new LinkedHashMap<>();
443-
DBIdentifier sName = DBIdentifier.toUpper(name);
444-
_colMap.put(sName, col);
460+
_colMap.put(normalizeColumnKey(name), col);
445461
_cols = null;
446462
return col;
447463
}
@@ -469,7 +485,7 @@ public boolean removeColumn(Column col) {
469485
if (col == null || _colMap == null)
470486
return false;
471487

472-
DBIdentifier sName = DBIdentifier.toUpper(col.getIdentifier());
488+
DBIdentifier sName = normalizeColumnKey(col.getIdentifier());
473489
Column cur = _colMap.get(sName);
474490
if (!col.equals(cur))
475491
return false;

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private static DBDictionary newDBDictionary(JDBCConfiguration conf,
217217
/**
218218
* Guess the dictionary class name to use based on the product string.
219219
*/
220-
private static String dictionaryClassForString(String prod, JDBCConfiguration conf) {
220+
static String dictionaryClassForString(String prod, JDBCConfiguration conf) {
221221
if (StringUtil.isEmpty(prod))
222222
return null;
223223
prod = prod.toLowerCase(Locale.ENGLISH);
@@ -270,6 +270,9 @@ private static String dictionaryClassForString(String prod, JDBCConfiguration co
270270
if (prod.indexOf("sapdb") != -1) {
271271
return dbdictionaryPlugin.unalias("maxdb");
272272
}
273+
if (prod.indexOf("herddb") != -1) {
274+
return dbdictionaryPlugin.unalias("herddb");
275+
}
273276
// test h2 in a special way, because there's a decent chance the string
274277
// h2 could appear in the URL of another database
275278
if (prod.indexOf("jdbc:h2:") != -1)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.openjpa.jdbc.sql;
20+
21+
/**
22+
* Dictionary for HerdDB.
23+
*/
24+
public class HerdDBDictionary
25+
extends org.apache.openjpa.jdbc.sql.DBDictionary {
26+
27+
private static final String DELIMITER_BACK_TICK = "`";
28+
29+
public HerdDBDictionary() {
30+
platform = "HerdDB";
31+
databaseProductName = "HerdDB";
32+
supportsForeignKeys = false;
33+
supportsUniqueConstraints = false;
34+
supportsCascadeDeleteAction = false;
35+
schemaCase = SCHEMA_CASE_LOWER;
36+
delimitedCase = SCHEMA_CASE_PRESERVE;
37+
38+
// make OpenJPA escape everything, because Apache Calcite has a lot of reserved words, like 'User', 'Value'...
39+
setDelimitIdentifiers(true);
40+
setSupportsDelimitedIdentifiers(true);
41+
setLeadingDelimiter(DELIMITER_BACK_TICK);
42+
setTrailingDelimiter(DELIMITER_BACK_TICK);
43+
}
44+
45+
}
46+

openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ private void collectOuterJoins(PathJoins pj) {
21542154
* Return the alias for the given table under the given joins.
21552155
* NOTE: WE RELY ON THESE INDEXES BEING MONOTONICALLY INCREASING FROM 0
21562156
*/
2157-
private int getTableIndex(Table table, PathJoins pj, boolean create) {
2157+
int getTableIndex(Table table, PathJoins pj, boolean create) {
21582158
// if we have a from select, then there are no table aliases
21592159
if (_from != null)
21602160
return -1;
@@ -2699,7 +2699,7 @@ private PathJoins getPreJoins() {
26992699
* Return the alias used to key on the column data, considering the
27002700
* given joins.
27012701
*/
2702-
private String getColumnAlias(Column col, PathJoins pj) {
2702+
String getColumnAlias(Column col, PathJoins pj) {
27032703
String alias;
27042704
if (_sel._from != null) {
27052705
alias = SelectImpl.toAlias(_sel._from.getTableIndex
@@ -2711,7 +2711,7 @@ private String getColumnAlias(Column col, PathJoins pj) {
27112711
return alias + "_" + col;
27122712
}
27132713
alias = SelectImpl.toAlias(_sel.getTableIndex(col.getTable(), pj, false));
2714-
return (alias == null) ? null : alias + "." + col;
2714+
return (alias == null) ? null : alias + "." + _sel._dict.getNamingUtil().toDBName(col.toString());
27152715
}
27162716

27172717
////////////////////////////
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2020 Apache Software Foundation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.openjpa.jdbc.sql;
17+
18+
import org.junit.Test;
19+
import static org.junit.Assert.*;
20+
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
21+
import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
22+
23+
public class DBDictionaryFactoryTest {
24+
25+
@Test
26+
public void testDictionaryClassForString() {
27+
JDBCConfiguration conf = new JDBCConfigurationImpl();
28+
29+
String[] aliases = new String[]{
30+
"access", org.apache.openjpa.jdbc.sql.AccessDictionary.class.getName(),
31+
"db2", org.apache.openjpa.jdbc.sql.DB2Dictionary.class.getName(),
32+
"derby", org.apache.openjpa.jdbc.sql.DerbyDictionary.class.getName(),
33+
"empress", org.apache.openjpa.jdbc.sql.EmpressDictionary.class.getName(),
34+
"foxpro", org.apache.openjpa.jdbc.sql.FoxProDictionary.class.getName(),
35+
"h2", org.apache.openjpa.jdbc.sql.H2Dictionary.class.getName(),
36+
"hsql", org.apache.openjpa.jdbc.sql.HSQLDictionary.class.getName(),
37+
"informix", org.apache.openjpa.jdbc.sql.InformixDictionary.class.getName(),
38+
"ingres", org.apache.openjpa.jdbc.sql.IngresDictionary.class.getName(),
39+
"jdatastore", org.apache.openjpa.jdbc.sql.JDataStoreDictionary.class.getName(),
40+
"mariadb", org.apache.openjpa.jdbc.sql.MariaDBDictionary.class.getName(),
41+
"mysql", org.apache.openjpa.jdbc.sql.MySQLDictionary.class.getName(),
42+
"herddb", org.apache.openjpa.jdbc.sql.HerdDBDictionary.class.getName(),
43+
"oracle", org.apache.openjpa.jdbc.sql.OracleDictionary.class.getName(),
44+
"pointbase", org.apache.openjpa.jdbc.sql.PointbaseDictionary.class.getName(),
45+
"postgres", org.apache.openjpa.jdbc.sql.PostgresDictionary.class.getName(),
46+
"soliddb", org.apache.openjpa.jdbc.sql.SolidDBDictionary.class.getName(),
47+
"sqlserver", org.apache.openjpa.jdbc.sql.SQLServerDictionary.class.getName(),
48+
"sybase", org.apache.openjpa.jdbc.sql.SybaseDictionary.class.getName(),
49+
"maxdb", MaxDBDictionary.class.getName(),
50+
"jdbc:h2:", H2Dictionary.class.getName(),
51+
"h2 database", H2Dictionary.class.getName()
52+
};
53+
54+
for (int i = 0; i < aliases.length; i++) {
55+
String key = aliases[i++];
56+
String expected = aliases[i];
57+
assertEquals(expected, DBDictionaryFactory.dictionaryClassForString(key, conf));
58+
}
59+
}
60+
61+
}

0 commit comments

Comments
 (0)