You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/01/26 22:02:29 UTC
[empire-db] branch version3 updated: EMPIREDB-367 DataList fixes
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch version3
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/version3 by this push:
new baf7823 EMPIREDB-367 DataList fixes
baf7823 is described below
commit baf7823da48f596c7f86d280f3fe2d4fe5336e66
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Wed Jan 26 23:02:26 2022 +0100
EMPIREDB-367 DataList fixes
---
.../org/apache/empire/data/list/DataListEntry.java | 17 +++++-
.../apache/empire/data/list/DataListFactory.java | 20 ++++++-
.../empire/data/list/DataListFactoryImpl.java | 56 ++++++++++++++----
.../org/apache/empire/data/list/DataListHead.java | 17 +++++-
.../main/java/org/apache/empire/db/DBUtils.java | 18 ++++--
.../apache/empire/db/list/DBRecordListFactory.java | 20 ++++++-
.../empire/db/list/DBRecordListFactoryImpl.java | 44 ++++++++++----
.../empire/db/validation/DBModelChecker.java | 67 +++++++++++-----------
.../empire/db/validation/DBModelErrorLogger.java | 4 +-
9 files changed, 194 insertions(+), 69 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
index 98a4ae3..fc4de83 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
@@ -1,5 +1,20 @@
/*
- * ESTEAM Software GmbH, 25.01.2022
+ * 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.empire.data.list;
diff --git a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactory.java b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactory.java
index d768721..965a40b 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactory.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactory.java
@@ -1,3 +1,21 @@
+/*
+ * 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.empire.data.list;
import java.util.List;
@@ -6,7 +24,7 @@ import org.apache.empire.data.RecordData;
public interface DataListFactory<T extends DataListEntry>
{
- void prepareQuery();
+ void prepareQuery(Object cmd, Object context);
List<T> newList(int capacity);
diff --git a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
index 980a7ae..fa666b5 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
@@ -1,3 +1,21 @@
+/*
+ * 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.empire.data.list;
import java.lang.reflect.Constructor;
@@ -5,6 +23,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.empire.commons.ClassUtils;
import org.apache.empire.data.ColumnExpr;
import org.apache.empire.data.RecordData;
import org.apache.empire.exceptions.InternalException;
@@ -12,24 +31,32 @@ import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.UnsupportedTypeException;
+/**
+ * DataListFactoryImpl
+ * Implements the DataListFactory
+ * @author rainer
+ */
public class DataListFactoryImpl<T extends DataListEntry> implements DataListFactory<T>
{
/**
- * findEntryConstructor
- * @param listEntryClass
- * @param listHeadClass
+ * Finds a constructor for listEntryClass
+ * @param listEntryClass the listEntryClass to instantiate
+ * @param listHeadClass the DataListHead class
* @return the constructor
*/
@SuppressWarnings("unchecked")
protected static <T extends DataListEntry> Constructor<T> findEntryConstructor(Class<?> listEntryClass, Class<? extends DataListHead> listHeadClass)
- {
- try
- { // Alternatively use ClassUtils.findMatchingAccessibleConstructor(listEntryClass, new Class<?>[] { listHeadClass, int.class, Object[].class });
+ { try
+ { // first try
return (Constructor<T>) listEntryClass.getDeclaredConstructor(listHeadClass, int.class, Object[].class);
}
catch (NoSuchMethodException | SecurityException e)
- {
- throw new UnsupportedTypeException(listEntryClass);
+ { // second try
+ Constructor<?> constructor = ClassUtils.findMatchingAccessibleConstructor(listEntryClass, new Class<?>[] { listHeadClass, int.class, Object[].class });
+ if (constructor==null)
+ throw new UnsupportedTypeException(listEntryClass);
+ // found
+ return (Constructor<T>)constructor;
}
}
@@ -37,9 +64,9 @@ public class DataListFactoryImpl<T extends DataListEntry> implements DataListFac
protected final DataListHead head;
/**
- * Constructs a DataListHead based on an DataListEntry constructor
+ * Constructs a DataListFactoryImpl based on a DateListEntry constructor and a DataListHead
* @param constructor the DataListEntry constructor
- * @param columns the list entry columns
+ * @param head the listHead object
*/
public DataListFactoryImpl(Constructor<T> constructor, DataListHead head)
{
@@ -47,13 +74,18 @@ public class DataListFactoryImpl<T extends DataListEntry> implements DataListFac
this.head = head;
}
+ /**
+ * Constructs a DataListFactoryImpl based on a DateListEntry class and a DataListHead
+ * @param listEntryClass the class of the DataListEntry
+ * @param head the listHead object
+ */
public DataListFactoryImpl(Class<T> listEntryClass, DataListHead head)
{
- this(findEntryConstructor(listEntryClass, DataListHead.class), head);
+ this(findEntryConstructor(listEntryClass, head.getClass()), head);
}
@Override
- public void prepareQuery()
+ public void prepareQuery(Object cmd, Object context)
{
/* Nothing */
}
diff --git a/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java b/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
index 174ad06..325858a 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
@@ -1,5 +1,20 @@
/*
- * ESTEAM Software GmbH, 25.01.2022
+ * 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.empire.data.list;
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
index 6b15117..56d7e24 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
@@ -654,6 +654,16 @@ public class DBUtils implements DBContextAware
{
return new DataListFactoryImpl<T>(entryClass, head);
}
+
+ /**
+ * Crates a default DataListHead for a DataListEntry class
+ * @param cmd the cmd for which to create the DataListHead
+ * @return the DataListHead instance
+ */
+ protected DataListHead createDefaultDataListHead(DBCommand cmd)
+ {
+ return new DataListHead(cmd.getSelectExprList());
+ }
/**
* Executes a query and returns a list of DataListEntry items
@@ -669,7 +679,7 @@ public class DBUtils implements DBContextAware
DBReader r = new DBReader(context);
try
{ // prepare
- factory.prepareQuery();
+ factory.prepareQuery(cmd, context);
// check pageSize
if (pageSize==0)
{ log.warn("PageSize must not be 0. Setting to -1 for all records!");
@@ -740,7 +750,7 @@ public class DBUtils implements DBContextAware
*/
public final <T extends DataListEntry> List<T> queryDataList(DBCommand cmd, Class<T> entryClass)
{
- return queryDataList(cmd, entryClass, new DataListHead(cmd.getSelectExprList()));
+ return queryDataList(cmd, entryClass, createDefaultDataListHead(cmd));
}
/**
@@ -757,7 +767,7 @@ public class DBUtils implements DBContextAware
*/
public final <T extends DataListEntry> T queryDataEntry(DBCommand cmd, Class<T> entryClass, boolean forceResult)
{
- DataListHead head = new DataListHead(cmd.getSelectExprList());
+ DataListHead head = createDefaultDataListHead(cmd);
List<T> dle = queryDataList(cmd, createDefaultDataListFactory(entryClass, head), 0, 1);
if (dle.isEmpty())
{ if (forceResult)
@@ -810,7 +820,7 @@ public class DBUtils implements DBContextAware
DBReader r = new DBReader(context);
try
{ // prepare
- factory.prepareQuery(cmd);
+ factory.prepareQuery(cmd, context);
// check pageSize
if (pageSize==0)
{ log.warn("PageSize must not be 0. Setting to -1 for all records!");
diff --git a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactory.java b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactory.java
index 731fa01..a5a4a7c 100644
--- a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactory.java
+++ b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactory.java
@@ -1,17 +1,33 @@
/*
- * ESTEAM Software GmbH, 26.01.2022
+ * 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.empire.db.list;
import java.util.List;
import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBContext;
import org.apache.empire.db.DBRecord;
import org.apache.empire.db.DBRecordData;
public interface DBRecordListFactory<T extends DBRecord>
{
- void prepareQuery(DBCommand cmd);
+ void prepareQuery(DBCommand cmd, DBContext context);
List<T> newList(int capacity);
diff --git a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
index b445886..17ef6f6 100644
--- a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
+++ b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
@@ -1,5 +1,20 @@
/*
- * ESTEAM Software GmbH, 26.01.2022
+ * 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.empire.db.list;
@@ -8,6 +23,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.empire.commons.ClassUtils;
import org.apache.empire.db.DBCommand;
import org.apache.empire.db.DBContext;
import org.apache.empire.db.DBRecord;
@@ -17,26 +33,32 @@ import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.UnsupportedTypeException;
/**
- * DBRecordListFactory
+ * DBRecordListFactoryImpl
+ * Implements the DBRecordListFactory interface
* @author rainer
*/
public class DBRecordListFactoryImpl<T extends DBRecord> implements DBRecordListFactory<T>
{
/**
- * findEntryConstructor
- * @param recordClass
- * @param listHeadClass
+ * Finds a constructor for recordClass
+ * @param recordClass the DBRecord class to instantiate
+ * @param contextClass the context param
+ * @param rowsetClass the rowset param
* @return the constructor
*/
+ @SuppressWarnings("unchecked")
protected static <T extends DBRecord> Constructor<T> findRecordConstructor(Class<T> recordClass, Class<? extends DBContext> contextClass, Class<? extends DBRowSet> rowsetClass)
{ try
{ // find the constructor
- // Alternatively use ClassUtils.findMatchingAccessibleConstructor()
return recordClass.getDeclaredConstructor(contextClass, rowsetClass);
}
catch (NoSuchMethodException | SecurityException e)
- {
- throw new UnsupportedTypeException(recordClass);
+ { // second try
+ Constructor<?> constructor = ClassUtils.findMatchingAccessibleConstructor(recordClass, new Class<?>[] { contextClass, rowsetClass });
+ if (constructor==null)
+ throw new UnsupportedTypeException(recordClass);
+ // found
+ return (Constructor<T>)constructor;
}
}
@@ -61,8 +83,8 @@ public class DBRecordListFactoryImpl<T extends DBRecord> implements DBRecordList
}
/**
- * Constructs a DBRecordListFactoryImpl based on an DBRecord constructor
- * @param recordClass the record Class to be created for this list
+ * Constructs a DBRecordListFactoryImpl based on an DBRecord class
+ * @param recordClass the record class to be created for this list
* @param context the database context
* @param rowset the rowset for the created records
*/
@@ -72,7 +94,7 @@ public class DBRecordListFactoryImpl<T extends DBRecord> implements DBRecordList
}
@Override
- public void prepareQuery(DBCommand cmd)
+ public void prepareQuery(DBCommand cmd, DBContext context)
{
if (cmd.hasSelectExpr())
{ // Already has select expressions.
diff --git a/empire-db/src/main/java/org/apache/empire/db/validation/DBModelChecker.java b/empire-db/src/main/java/org/apache/empire/db/validation/DBModelChecker.java
index 5f79538..ad09038 100644
--- a/empire-db/src/main/java/org/apache/empire/db/validation/DBModelChecker.java
+++ b/empire-db/src/main/java/org/apache/empire/db/validation/DBModelChecker.java
@@ -409,21 +409,19 @@ public class DBModelChecker
protected void checkTable(DBTable table, DBModelErrorHandler handler)
{
- DBRowSet remoteTable = getTable(table.getName());
+ DBTable remoteTable = remoteDb.getTable(table.getName()); // getTable(table.getName());
if (remoteTable == null)
- { // Not found
- handler.itemNotFound(table);
- return;
- }
- if (!(remoteTable instanceof DBTable))
- { // Not a DBTable
- handler.objectTypeMismatch(remoteTable, table.getName(), DBTable.class);
+ { // Check if it is a view instead
+ if (remoteDb.getView(table.getName())!=null)
+ handler.objectTypeMismatch(remoteTable, table.getName(), DBTable.class);
+ else
+ handler.itemNotFound(table);
return;
}
// Check primary Key
- checkPrimaryKey(table, (DBTable)remoteTable, handler);
+ checkPrimaryKey(table, remoteTable, handler);
// check foreign keys
- checkForeignKeys(table, (DBTable)remoteTable, handler);
+ checkForeignKeys(table, remoteTable, handler);
// Check Columns
for (DBColumn column : table.getColumns())
{
@@ -437,6 +435,30 @@ public class DBModelChecker
}
}
+ protected void checkView(DBView view, DBModelErrorHandler handler)
+ {
+ DBView remoteView = remoteDb.getView(view.getName());
+ if (remoteView == null)
+ { // Check if it is a table instead
+ if (remoteDb.getTable(view.getName())!=null)
+ handler.objectTypeMismatch(remoteView, view.getName(), DBView.class);
+ else
+ handler.itemNotFound(view);
+ return;
+ }
+ for (DBColumn column : view.getColumns())
+ {
+ DBColumn remoteColumn = remoteView.getColumn(column.getName());
+ if (remoteColumn == null)
+ {
+ handler.itemNotFound(column);
+ continue;
+ }
+ // checkColumn(column, remoteColumn, handler);
+ checkColumnType(column, remoteColumn, handler);
+ }
+ }
+
protected void checkPrimaryKey(DBTable table, DBTable remoteTable, DBModelErrorHandler handler)
{
if (table.getPrimaryKey() == null)
@@ -521,31 +543,6 @@ public class DBModelChecker
}
- protected void checkView(DBView view, DBModelErrorHandler handler)
- {
- DBRowSet remoteView = getTable(view.getName());
- if (remoteView == null)
- {
- handler.itemNotFound(view);
- return;
- }
- if (!(remoteView instanceof DBView))
- {
- handler.objectTypeMismatch(remoteView, view.getName(), DBView.class);
- }
- for (DBColumn column : view.getColumns())
- {
- DBColumn remoteColumn = remoteView.getColumn(column.getName());
- if (remoteColumn == null)
- {
- handler.itemNotFound(column);
- continue;
- }
- // checkColumn(column, remoteColumn, handler);
- checkColumnType(column, remoteColumn, handler);
- }
- }
-
protected void checkColumn(DBColumn column, DBColumn remoteColumn, DBModelErrorHandler handler)
{
switch (column.getDataType())
diff --git a/empire-db/src/main/java/org/apache/empire/db/validation/DBModelErrorLogger.java b/empire-db/src/main/java/org/apache/empire/db/validation/DBModelErrorLogger.java
index e6a889b..e77d17f 100644
--- a/empire-db/src/main/java/org/apache/empire/db/validation/DBModelErrorLogger.java
+++ b/empire-db/src/main/java/org/apache/empire/db/validation/DBModelErrorLogger.java
@@ -36,9 +36,9 @@ public class DBModelErrorLogger implements DBModelErrorHandler
{
private static final Logger log = LoggerFactory.getLogger(DBModelErrorLogger.class);
- private int errorCount;
+ protected int errorCount;
- private int warnCount;
+ protected int warnCount;
public int getErrorCount()
{