mirror of
https://github.com/Wisser/Jailer.git
synced 2026-05-20 02:55:00 -05:00
check primary key and columns
git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1564 3dd849cd-670e-4645-a7cd-dd197c8d0e81
This commit is contained in:
@@ -810,19 +810,23 @@ public class DataModel {
|
||||
public static class NoPrimaryKeyException extends RuntimeException {
|
||||
private static final long serialVersionUID = 4523935351640139649L;
|
||||
public final Table table;
|
||||
public NoPrimaryKeyException(Table table) {
|
||||
super("Table '" + table.getName() + "' has no primary key");
|
||||
public NoPrimaryKeyException(Table table, String message) {
|
||||
super("Table '" + table.getName() + "' " + message);
|
||||
this.table = table;
|
||||
}
|
||||
public NoPrimaryKeyException(Table table) {
|
||||
this(table, "has no primary key");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all tables in the closure of a given subject have primary keys.
|
||||
* @param hasRowID
|
||||
*
|
||||
* @param subject the subject
|
||||
* @throws NoPrimaryKeyException if a table has no primary key
|
||||
*/
|
||||
public void checkForPrimaryKey(Set<Table> subjects, boolean forDeletion) throws NoPrimaryKeyException {
|
||||
public void checkForPrimaryKey(Set<Table> subjects, boolean forDeletion, boolean hasRowID) throws NoPrimaryKeyException {
|
||||
Set<Table> checked = new HashSet<Table>();
|
||||
for (Table subject: subjects) {
|
||||
Set<Table> toCheck = new HashSet<Table>(subject.closure(checked, true));
|
||||
@@ -838,8 +842,13 @@ public class DataModel {
|
||||
toCheck.addAll(border);
|
||||
}
|
||||
for (Table table: toCheck) {
|
||||
if (table.primaryKey.getColumns().isEmpty()) {
|
||||
throw new NoPrimaryKeyException(table);
|
||||
if (!hasRowID) {
|
||||
if (table.primaryKey.getColumns().isEmpty()) {
|
||||
throw new NoPrimaryKeyException(table);
|
||||
}
|
||||
}
|
||||
if (table.getColumns().isEmpty()) {
|
||||
throw new NoPrimaryKeyException(table, "has no column");
|
||||
}
|
||||
}
|
||||
checked.addAll(toCheck);
|
||||
|
||||
@@ -1353,11 +1353,9 @@ public class SubsettingEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (session.dbms.getRowidName() == null || executionContext.getNoRowid() || !insertOnly || deleteScriptFileName != null) {
|
||||
toCheck.add(extractionModel.subject);
|
||||
extractionModel.dataModel.checkForPrimaryKey(toCheck, deleteScriptFileName != null);
|
||||
}
|
||||
|
||||
toCheck.add(extractionModel.subject);
|
||||
extractionModel.dataModel.checkForPrimaryKey(toCheck, deleteScriptFileName != null, !(session.dbms.getRowidName() == null || executionContext.getNoRowid() || !insertOnly || deleteScriptFileName != null));
|
||||
|
||||
subjectCondition = ParameterHandler.assignParameterValues(subjectCondition, executionContext.getParameters());
|
||||
|
||||
if (!executionContext.getParameters().isEmpty()) {
|
||||
|
||||
@@ -1094,7 +1094,7 @@ public class ExtractionModelFrame extends javax.swing.JFrame {
|
||||
Session session = SessionForUI.createSession(dataSource, dataSource.dbms, this);
|
||||
|
||||
if (session != null) {
|
||||
if (extractionModelEditor.dataModel != null && session.dbms.getRowidName() == null) {
|
||||
if (extractionModelEditor.dataModel != null) {
|
||||
Set<Table> toCheck = new HashSet<Table>();
|
||||
if (extractionModelEditor.extractionModel != null) {
|
||||
if (extractionModelEditor.extractionModel.additionalSubjects != null) {
|
||||
@@ -1104,7 +1104,7 @@ public class ExtractionModelFrame extends javax.swing.JFrame {
|
||||
}
|
||||
}
|
||||
toCheck.add(extractionModelEditor.subject);
|
||||
extractionModelEditor.dataModel.checkForPrimaryKey(toCheck, false);
|
||||
extractionModelEditor.dataModel.checkForPrimaryKey(toCheck, false, session.dbms.getRowidName() != null);
|
||||
}
|
||||
|
||||
ExportDialog exportDialog = new ExportDialog(this, extractionModelEditor.dataModel, extractionModelEditor.getSubject(), extractionModelEditor.getSubjectCondition(), extractionModelEditor.extractionModel.additionalSubjects, session, args, dbConnectionDialog.getUser(), dbConnectionDialog.getPassword(), checkRI, dbConnectionDialog, extractionModelEditor.extractionModelFile, executionContext);
|
||||
|
||||
Reference in New Issue
Block a user