Skip to content

Commit

Permalink
added option "include tables associated with a subject table"
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisser committed May 2, 2024
1 parent 45cdaac commit 2d7f962
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/engine/net/sf/jailer/JailerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class JailerVersion {
/**
* The Jailer version.
*/
public static final String VERSION = "16.1.2-json";
public static final String VERSION = "16.1.2-closure";

/**
* The Jailer working tables version.
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ private void generateDDLMenuItemActionPerformed(java.awt.event.ActionEvent evt)
return;
}
}
DDLScriptGeneratorPanel.open(this, null, extractionModelEditor.dataModel, theSession, dbConnectionDialog.getExecutionContext());
DDLScriptGeneratorPanel.open(this, null, extractionModelEditor.dataModel, extractionModelEditor.getCurrentSubjectClosure(), theSession, dbConnectionDialog.getExecutionContext());
}
}//GEN-LAST:event_generateDDLMenuItemActionPerformed

Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3917,7 +3917,7 @@ private void importMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GE
}//GEN-LAST:event_importMenuItemActionPerformed

private void generateDDLMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateDDLMenuItemActionPerformed
DDLScriptGeneratorPanel.open(this, null, datamodel.get(), session, dbConnectionDialog.getExecutionContext());
DDLScriptGeneratorPanel.open(this, null, datamodel.get(), null, session, dbConnectionDialog.getExecutionContext());
}//GEN-LAST:event_generateDDLMenuItemActionPerformed

private void newWindowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_newWindowMenuItemActionPerformed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ public void mouseClicked(MouseEvent evt) {
ddl.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DDLScriptGeneratorPanel.open(SwingUtilities.getWindowAncestor(MetaDataPanel.this), preselectedSchema, dataModel, metaDataSource.getSession(), executionContext);
DDLScriptGeneratorPanel.open(SwingUtilities.getWindowAncestor(MetaDataPanel.this), preselectedSchema, dataModel, null, metaDataSource.getSession(), executionContext);
}
});
popup.add(ddl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="10" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="scriptFileTextField">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="10" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
<GridBagConstraints gridX="2" gridY="2" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand All @@ -51,7 +51,7 @@
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="4" gridY="10" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="2" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="4" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="2" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand Down Expand Up @@ -214,6 +214,43 @@
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="includeLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Include "/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JRadioButton" name="includeAllButton">
<Properties>
<Property name="text" type="java.lang.String" value="All tables"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="includeAllButtonActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="4" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JRadioButton" name="includeClosureButton">
<Properties>
<Property name="text" type="java.lang.String" value="Tables associated with a subject table"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;Generate DDL statements only for the tables that are directly or indirectly associated with a subject table. (the &lt;i&gt;Closure&lt;/i&gt;)&lt;/html&gt;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="includeClosureButtonActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="6" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="2" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import net.sf.jailer.ui.util.ConcurrentTaskControl;
import net.sf.jailer.ui.util.UISettings;
import net.sf.jailer.util.LogUtil;
import net.sf.jailer.util.Quoting;
import net.sf.jailer.util.SqlUtil;

/**
Expand All @@ -135,6 +136,11 @@ public DDLScriptGeneratorPanel() {
buttonGroup.add(createAndDropRadioButton);
buttonGroup.add(dropRadioButton);
createRadioButton.setSelected(true);

buttonGroup = new ButtonGroup();
buttonGroup.add(includeAllButton);
buttonGroup.add(includeClosureButton);
includeAllButton.setSelected(true);

okButton.setIcon(UIUtil.scaleIcon(okButton, okIcon));
closeButton.setIcon(UIUtil.scaleIcon(closeButton, cancelIcon));
Expand Down Expand Up @@ -183,7 +189,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde

private Window owner;

public static void open(Window owner, String preselectedSchema, DataModel dataModel, Session session, ExecutionContext executionContext) {
public static void open(Window owner, String preselectedSchema, DataModel dataModel, Set<Table> closure, Session session, ExecutionContext executionContext) {
EscapableDialog dialog = owner instanceof Dialog? new EscapableDialog((Dialog) owner) {
} : new EscapableDialog((Frame) owner) {
};
Expand All @@ -196,6 +202,12 @@ protected void close() {
ddlScriptGeneratorPanel.owner = owner;
ddlScriptGeneratorPanel.session = session;
ddlScriptGeneratorPanel.initTargetDBMS(session);
ddlScriptGeneratorPanel.closure = closure;

ddlScriptGeneratorPanel.includeClosureButton.setEnabled(closure != null);
if (closure != null) {
ddlScriptGeneratorPanel.includeClosureButton.setText(ddlScriptGeneratorPanel.includeClosureButton.getText() + " (" + closure.size() + " Table" + (closure.size() == 1? "" : "s") + ")");
}

if (executionContext.getCurrentModelSubfolder() != null) {
ddlScriptGeneratorPanel.scriptFileTextField.setText((preselectedSchema != null? preselectedSchema : executionContext.getCurrentModelSubfolder()) + "-ddl.sql");
Expand Down Expand Up @@ -577,17 +589,28 @@ public void generateChangeLog(Liquibase liquibase, Database database, CatalogAnd
new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema)
}, finalCompareTypes);

new CommandScope(GenerateChangelogCommandStep.COMMAND_NAME[0])
CommandScope commandScope = new CommandScope(GenerateChangelogCommandStep.COMMAND_NAME[0])
.addArgumentValue(GenerateChangelogCommandStep.CHANGELOG_FILE_ARG, liquibase.getChangeLogFile())
.addArgumentValue(PreCompareCommandStep.COMPARE_CONTROL_ARG, compareControl)
.addArgumentValue(DbUrlConnectionArgumentsCommandStep.DATABASE_ARG, liquibase.getDatabase())
.addArgumentValue(PreCompareCommandStep.SNAPSHOT_TYPES_ARG, null)
.setOutput(System.out)
.addArgumentValue(PreCompareCommandStep.SNAPSHOT_TYPES_ARG, null);
if (includeClosureButton.isSelected() && closure != null) {
String tablesList = closure
.stream()
.map(t -> Quoting.staticUnquote(t.getUnqualifiedName()))
.map(name -> "\\Q" + (name.replace(",", "\\E.\\Q")) + "\\E") // ',' would split the regEx
.collect(Collectors.joining(","));
commandScope.addArgumentValue(PreCompareCommandStep.INCLUDE_OBJECTS_ARG, tablesList);
// TODO
System.out.println(tablesList);
}
commandScope.setOutput(System.out)
.execute();
}

private String defaultSchema;
private Session session;
private Set<Table> closure;

protected boolean readSchemas(String preselectedSchema, Session session, DataModel dataModel, EscapableDialog dialog) {
AtomicBoolean ok = new AtomicBoolean(false);
Expand Down Expand Up @@ -710,6 +733,9 @@ private void initComponents() {
createRadioButton = new javax.swing.JRadioButton();
createAndDropRadioButton = new javax.swing.JRadioButton();
dropRadioButton = new javax.swing.JRadioButton();
includeLabel = new javax.swing.JLabel();
includeAllButton = new javax.swing.JRadioButton();
includeClosureButton = new javax.swing.JRadioButton();
jPanel3 = new javax.swing.JPanel();
closeButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
Expand All @@ -722,13 +748,13 @@ private void initComponents() {
jLabel1.setText("Script file ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 10;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
jPanel1.add(jLabel1, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 10;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
Expand All @@ -743,7 +769,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 10;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(4, 2, 0, 0);
jPanel1.add(fileFindButton, gridBagConstraints);

Expand Down Expand Up @@ -864,6 +890,42 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
jPanel1.add(dropRadioButton, gridBagConstraints);

includeLabel.setText("Include ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
jPanel1.add(includeLabel, gridBagConstraints);

includeAllButton.setText("All tables");
includeAllButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
includeAllButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(6, 4, 0, 0);
jPanel1.add(includeAllButton, gridBagConstraints);

includeClosureButton.setText("Tables associated with a subject table");
includeClosureButton.setToolTipText("<html>Generate DDL statements only for the tables that are directly or indirectly associated with a subject table. (the <i>Closure</i>)</html>");
includeClosureButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
includeClosureButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 0);
jPanel1.add(includeClosureButton, gridBagConstraints);

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
Expand Down Expand Up @@ -1006,6 +1068,12 @@ private void fileFindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
}
}//GEN-LAST:event_fileFindButtonActionPerformed

private void includeAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_includeAllButtonActionPerformed
}//GEN-LAST:event_includeAllButtonActionPerformed

private void includeClosureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_includeClosureButtonActionPerformed
}//GEN-LAST:event_includeClosureButtonActionPerformed

private String toFileName(String f) {
if (!new File(f).isAbsolute()) {
return Environment.newFile(f).getAbsolutePath();
Expand All @@ -1020,6 +1088,9 @@ private String toFileName(String f) {
private javax.swing.JComboBox<DBMS> dbmsComboBox;
private javax.swing.JRadioButton dropRadioButton;
private javax.swing.JButton fileFindButton;
private javax.swing.JRadioButton includeAllButton;
private javax.swing.JRadioButton includeClosureButton;
private javax.swing.JLabel includeLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
Expand Down

0 comments on commit 2d7f962

Please sign in to comment.