\r
import java.sql.Connection;\r
import java.sql.PreparedStatement;\r
-import java.sql.ResultSet;\r
import java.sql.SQLException;\r
import java.util.HashMap;\r
import java.util.List;\r
logger.error("Fetched " + list.size() + " " + parentPluralString + ".");\r
for (TaxonBase taxonBase : list) {\r
if (taxonBase.isInstanceOf(Taxon.class)) {\r
-\r
+ \r
// Set the current Taxon\r
taxon = CdmBase.deproxy(taxonBase, Taxon.class);\r
\r
\r
// Differentiate between descriptionElements with and without sources.\r
if (elementSources.size() == 0 && state.getDbId(descriptionElement) != null) {\r
- doCount(count++, modCount, pluralString);\r
- success &= mapping.invoke(descriptionElement);\r
+ if (neededValuesNotNull(descriptionElement, state)) {\r
+ doCount(count++, modCount, pluralString);\r
+ success &= mapping.invoke(descriptionElement);\r
+ }\r
} else {\r
for (DescriptionElementSource elementSource : elementSources) {\r
ReferenceBase reference = elementSource.getCitation();\r
\r
// Citations can be empty (null): Is it wrong data or just a normal case?\r
if (reference != null && state.getDbId(reference) != null) {\r
- doCount(count++, modCount, pluralString);\r
- success &= mapping.invoke(reference);\r
+ if (neededValuesNotNull(reference, state)) {\r
+ doCount(count++, modCount, pluralString);\r
+ success &= mapping.invoke(reference);\r
+ }\r
}\r
}\r
\r
}\r
\r
/**\r
- * Returns the identifier of the last occurrence committed to the database.\r
- * @param state\r
+ * Checks whether needed values for an entity are NULL.\r
* @return\r
*/\r
- private static Integer getLastOccurrenceId(PesiExportState state) {\r
- // Retrieve the identifier of the last stored record\r
- // Retrieve database identifier of the last created occurrence record.\r
- String lastRecordSql = "Select @@Identity From OccurrenceSource";\r
- Connection con = state.getConfig().getDestination().getConnection();\r
- PreparedStatement stmt = null;\r
- \r
- Integer occurrenceId = 0;\r
- try {\r
- stmt = con.prepareStatement(lastRecordSql);\r
- // stmt.setString(1, dbTableName);\r
- ResultSet resultSet = stmt.executeQuery();\r
- while (resultSet.next()) {\r
- // Count of this resultset should be 1\r
- occurrenceId = resultSet.getInt(1);\r
- }\r
- if (occurrenceId == 0) {\r
- throw new RuntimeException();\r
- }\r
- } catch (SQLException e) {\r
- logger.error("SQLException during getOccurrenceId invoke.");\r
- e.printStackTrace();\r
+ private boolean neededValuesNotNull(AnnotatableEntity entity, PesiExportState state) {\r
+ boolean result = true;\r
+ if (getTaxonFk(entity, state) == null) {\r
+ logger.error("TaxonFk is NULL, but is not allowed to be. Therefore no record was written to export database for this entity: " + entity.getUuid());\r
+ result = false;\r
}\r
-\r
- return occurrenceId;\r
+ if (getAreaFk(entity) == null) {\r
+ logger.error("AreaFk is NULL, but is not allowed to be. Therefore no record was written to export database for this entity: " + entity.getUuid());\r
+ result = false;\r
+ }\r
+ if (getOccurrenceStatusFk(entity) == null) {\r
+ logger.error("OccurrenceStatusFk is NULL, but is not allowed to be. Therefore no record was written to export database for this entity: " + entity.getUuid());\r
+ result = false;\r
+ }\r
+ return result;\r
}\r
\r
-\r
/**\r
* Creates the entries for the database table 'OccurrenceSource'.\r
* @param entity\r
* @return The <code>TaxonFk</code> attribute.\r
* @see MethodMapper\r
*/\r
- @SuppressWarnings("unused")\r
private static Integer getTaxonFk(AnnotatableEntity entity, PesiExportState state) {\r
// AnnotatableEntity parameter isn't needed, but the DbSingleAttributeExportMapperBase throws a type mismatch exception otherwise\r
// since it awaits two parameters if one of them is of instance DbExportStateBase.\r
* @return The <code>AreaFk</code> attribute.\r
* @see MethodMapper\r
*/\r
- @SuppressWarnings("unused")\r
private static Integer getAreaFk(AnnotatableEntity entity) {\r
Integer result = null;\r
if (getNamedArea() != null) {\r
* @throws UnknownCdmTypeException \r
* @see MethodMapper\r
*/\r
- @SuppressWarnings("unused")\r
private static Integer getOccurrenceStatusFk(AnnotatableEntity entity) {\r
Integer result = null;\r
if (getDistribution() != null) {\r