Skip to content

Commit

Permalink
Merge branch 'master' into OPENJPA-2817_PCClassFileTransformer-exclus…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
rmannibucau authored Jul 23, 2020
2 parents 96b2b12 + 093a547 commit 9e665c0
Show file tree
Hide file tree
Showing 21 changed files with 905 additions and 92 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for additional
# information regarding copyright ownership. The ASF 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.
#
name: Java CI
on: [push, pull_request]
env:
MAVEN_OPTS: -Dmaven.artifact.threads=256 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 'Set up JDK 1.8'
uses: actions/setup-java@v1
with:
java-version: '1.8'
- name: 'Cache Maven packages'
uses: actions/cache@v2
with:
path: ~/.m2
key: 'cache'
restore-keys: 'cache'
- name: 'Build with Maven'
run: mvn -B install --file pom.xml
- name: 'Remove Snapshots Before Caching'
run: find ~/.m2 -name '*SNAPSHOT' | xargs rm -Rf
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public JDBCConfigurationImpl(boolean derivations, boolean loadGlobals) {
"jdatastore", org.apache.openjpa.jdbc.sql.JDataStoreDictionary.class.getName(),
"mariadb", org.apache.openjpa.jdbc.sql.MariaDBDictionary.class.getName(),
"mysql", org.apache.openjpa.jdbc.sql.MySQLDictionary.class.getName(),
"herddb", org.apache.openjpa.jdbc.sql.HerdDBDictionary.class.getName(),
"oracle", org.apache.openjpa.jdbc.sql.OracleDictionary.class.getName(),
"pointbase", org.apache.openjpa.jdbc.sql.PointbaseDictionary.class.getName(),
"postgres", org.apache.openjpa.jdbc.sql.PostgresDictionary.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class DBIdentifier extends IdentifierImpl implements Cloneable, Identifier, Serializable {


private static final long serialVersionUID = 1L;

/**
Expand Down Expand Up @@ -754,16 +754,17 @@ public static DBIdentifier toUpper(DBIdentifier name, boolean force) {
if (DBIdentifier.isNull(name)) {
return name;
}
DBIdentifier sName = name.clone();
if (sName.getNameInternal() == null) {
return sName;
if (name.getNameInternal() == null) {
return name;
}
// Do not convert delimited names to upper case. They may have
// been delimited to preserve case.
if (force || !Normalizer.isDelimited(sName.getNameInternal())) {
if (force || !Normalizer.isDelimited(name.getNameInternal())) {
DBIdentifier sName = name.clone();
sName.setNameInternal(sName.getNameInternal().toUpperCase());
return sName;
}
return sName;
return name;
}

/**
Expand Down Expand Up @@ -861,16 +862,35 @@ public static DBIdentifier removeDelimiters(DBIdentifier name) {
if (DBIdentifier.isNull(name)) {
return name;
}
DBIdentifier sName = name.clone();
if (isEmpty(sName)) {
return sName;
if (!name.isDelimited()) {
return name;
}
String strName = sName.getNameInternal();
strName = Normalizer.removeDelimiters(strName);
String strName = Normalizer.removeDelimiters(name.getNameInternal());
DBIdentifier sName = name.clone();
sName.setNameInternal(strName);
return sName;
}

/**
* Combine {@link #removeDelimiters(org.apache.openjpa.jdbc.identifier.DBIdentifier) }
* with {@link #toUpper(org.apache.openjpa.jdbc.identifier.DBIdentifier, boolean) }
* in order to save allocations and CPU cycles.
* @param name
* @return
*/
public static DBIdentifier removeDelimitersAndMakeUpper(DBIdentifier name) {
if (DBIdentifier.isNull(name) || name.getNameInternal() == null) {
return name;
}
if (!name.isDelimited()) {
return toUpper(name, true);
}
String strName = Normalizer.removeDelimiters(name.getNameInternal());
DBIdentifier sName = name.clone();
sName.setNameInternal(strName.toUpperCase());
return sName;
}

/**
* Returns a new delimiter with leading and trailing spaces removed.
* @param name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.List;
import java.util.Set;

import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.sql.DataSource;

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

if (dropColumn(cols[k])) {
if (dbTable != null)
dbTable.removeColumn(col);
else
_log.warn(_loc.get("drop-col", cols[k], tabs[j]));
dbTable.removeColumn(col);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
* @author Abe White
* @author Stephen Kim
*/

public class Table
extends NameSet
implements Comparable<Object>, SourceTracker {

private static final long serialVersionUID = 1L;
private DBIdentifier _name = DBIdentifier.NULL;
private DBIdentifier _schemaName = DBIdentifier.NULL;
// all keys must be normalized with normalizeColumnKey
private Map<DBIdentifier, Column> _colMap = null;
private Map<DBIdentifier, Index> _idxMap = null;
private Collection<ForeignKey> _fkList = null;
Expand Down Expand Up @@ -312,12 +314,20 @@ public Column[] getRelationIdColumns() {
return _rels;
}

/**
* Return the list of column names, used only for informative (error) messages.
* @return
*/
public String[] getColumnNames() {
if (_colMap == null) {
return new String[0];
}
DBIdentifier[] sNames = _colMap.keySet().toArray(new DBIdentifier[_colMap.size()]);
return DBIdentifier.toStringArray(sNames);
return _colMap
.values()
.stream()
.map(Column::getIdentifier)
.map(DBIdentifier::getName)
.toArray(String[]::new);
}

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

public Column getColumn(DBIdentifier name) {
private Column internalGetColumn(DBIdentifier name) {
if (DBIdentifier.isNull(name) || _colMap == null)
return null;
return _colMap.get(DBIdentifier.toUpper(name));
DBIdentifier key = normalizeColumnKey(name);
return _colMap.get(key);
}

public Column getColumn(DBIdentifier name) {
return internalGetColumn(name);
}

private static DBIdentifier normalizeColumnKey(DBIdentifier name) {
return DBIdentifier.removeDelimitersAndMakeUpper(name);
}

public Column getColumn(DBIdentifier name, boolean create) {
Expand Down Expand Up @@ -375,8 +394,7 @@ public boolean containsColumn(DBIdentifier name, DBDictionary dict) {
if (DBIdentifier.isNull(name) || _colMap == null) {
return false;
}
DBIdentifier sName = DBIdentifier.toUpper(name);
return _colMap.containsKey(sName);
return _colMap.containsKey(normalizeColumnKey(name));
}

public boolean containsColumn(Column col) {
Expand Down Expand Up @@ -414,8 +432,7 @@ public Column addColumn(DBIdentifier name) {
}
if (_colMap == null)
_colMap = new LinkedHashMap<>();
DBIdentifier sName = DBIdentifier.toUpper(name);
_colMap.put(sName, col);
_colMap.put(normalizeColumnKey(name), col);
_cols = null;
return col;
}
Expand All @@ -440,8 +457,7 @@ public Column addColumn(DBIdentifier name, DBIdentifier validName) {
col = new Column(validName, this);
if (_colMap == null)
_colMap = new LinkedHashMap<>();
DBIdentifier sName = DBIdentifier.toUpper(name);
_colMap.put(sName, col);
_colMap.put(normalizeColumnKey(name), col);
_cols = null;
return col;
}
Expand Down Expand Up @@ -469,7 +485,7 @@ public boolean removeColumn(Column col) {
if (col == null || _colMap == null)
return false;

DBIdentifier sName = DBIdentifier.toUpper(col.getIdentifier());
DBIdentifier sName = normalizeColumnKey(col.getIdentifier());
Column cur = _colMap.get(sName);
if (!col.equals(cur))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static DBDictionary newDBDictionary(JDBCConfiguration conf,
/**
* Guess the dictionary class name to use based on the product string.
*/
private static String dictionaryClassForString(String prod, JDBCConfiguration conf) {
static String dictionaryClassForString(String prod, JDBCConfiguration conf) {
if (StringUtil.isEmpty(prod))
return null;
prod = prod.toLowerCase(Locale.ENGLISH);
Expand Down Expand Up @@ -270,6 +270,9 @@ private static String dictionaryClassForString(String prod, JDBCConfiguration co
if (prod.indexOf("sapdb") != -1) {
return dbdictionaryPlugin.unalias("maxdb");
}
if (prod.indexOf("herddb") != -1) {
return dbdictionaryPlugin.unalias("herddb");
}
// test h2 in a special way, because there's a decent chance the string
// h2 could appear in the URL of another database
if (prod.indexOf("jdbc:h2:") != -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.
*/
package org.apache.openjpa.jdbc.sql;

/**
* Dictionary for HerdDB.
*/
public class HerdDBDictionary
extends org.apache.openjpa.jdbc.sql.DBDictionary {

private static final String DELIMITER_BACK_TICK = "`";

public HerdDBDictionary() {
platform = "HerdDB";
databaseProductName = "HerdDB";
supportsForeignKeys = false;
supportsUniqueConstraints = false;
supportsCascadeDeleteAction = false;
schemaCase = SCHEMA_CASE_LOWER;
delimitedCase = SCHEMA_CASE_PRESERVE;

// make OpenJPA escape everything, because Apache Calcite has a lot of reserved words, like 'User', 'Value'...
setDelimitIdentifiers(true);
setSupportsDelimitedIdentifiers(true);
setLeadingDelimiter(DELIMITER_BACK_TICK);
setTrailingDelimiter(DELIMITER_BACK_TICK);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ private void collectOuterJoins(PathJoins pj) {
* Return the alias for the given table under the given joins.
* NOTE: WE RELY ON THESE INDEXES BEING MONOTONICALLY INCREASING FROM 0
*/
private int getTableIndex(Table table, PathJoins pj, boolean create) {
int getTableIndex(Table table, PathJoins pj, boolean create) {
// if we have a from select, then there are no table aliases
if (_from != null)
return -1;
Expand Down Expand Up @@ -2699,7 +2699,7 @@ private PathJoins getPreJoins() {
* Return the alias used to key on the column data, considering the
* given joins.
*/
private String getColumnAlias(Column col, PathJoins pj) {
String getColumnAlias(Column col, PathJoins pj) {
String alias;
if (_sel._from != null) {
alias = SelectImpl.toAlias(_sel._from.getTableIndex
Expand All @@ -2711,7 +2711,7 @@ private String getColumnAlias(Column col, PathJoins pj) {
return alias + "_" + col;
}
alias = SelectImpl.toAlias(_sel.getTableIndex(col.getTable(), pj, false));
return (alias == null) ? null : alias + "." + col;
return (alias == null) ? null : alias + "." + _sel._dict.getNamingUtil().toDBName(col.toString());
}

////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 Apache Software Foundation.
*
* 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.apache.openjpa.jdbc.sql;

import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;

public class DBDictionaryFactoryTest {

@Test
public void testDictionaryClassForString() {
JDBCConfiguration conf = new JDBCConfigurationImpl();

String[] aliases = new String[]{
"access", org.apache.openjpa.jdbc.sql.AccessDictionary.class.getName(),
"db2", org.apache.openjpa.jdbc.sql.DB2Dictionary.class.getName(),
"derby", org.apache.openjpa.jdbc.sql.DerbyDictionary.class.getName(),
"empress", org.apache.openjpa.jdbc.sql.EmpressDictionary.class.getName(),
"foxpro", org.apache.openjpa.jdbc.sql.FoxProDictionary.class.getName(),
"h2", org.apache.openjpa.jdbc.sql.H2Dictionary.class.getName(),
"hsql", org.apache.openjpa.jdbc.sql.HSQLDictionary.class.getName(),
"informix", org.apache.openjpa.jdbc.sql.InformixDictionary.class.getName(),
"ingres", org.apache.openjpa.jdbc.sql.IngresDictionary.class.getName(),
"jdatastore", org.apache.openjpa.jdbc.sql.JDataStoreDictionary.class.getName(),
"mariadb", org.apache.openjpa.jdbc.sql.MariaDBDictionary.class.getName(),
"mysql", org.apache.openjpa.jdbc.sql.MySQLDictionary.class.getName(),
"herddb", org.apache.openjpa.jdbc.sql.HerdDBDictionary.class.getName(),
"oracle", org.apache.openjpa.jdbc.sql.OracleDictionary.class.getName(),
"pointbase", org.apache.openjpa.jdbc.sql.PointbaseDictionary.class.getName(),
"postgres", org.apache.openjpa.jdbc.sql.PostgresDictionary.class.getName(),
"soliddb", org.apache.openjpa.jdbc.sql.SolidDBDictionary.class.getName(),
"sqlserver", org.apache.openjpa.jdbc.sql.SQLServerDictionary.class.getName(),
"sybase", org.apache.openjpa.jdbc.sql.SybaseDictionary.class.getName(),
"maxdb", MaxDBDictionary.class.getName(),
"jdbc:h2:", H2Dictionary.class.getName(),
"h2 database", H2Dictionary.class.getName()
};

for (int i = 0; i < aliases.length; i++) {
String key = aliases[i++];
String expected = aliases[i];
assertEquals(expected, DBDictionaryFactory.dictionaryClassForString(key, conf));
}
}

}
Loading

0 comments on commit 9e665c0

Please sign in to comment.