From 16e8184a2311bc14211a042b4b346957a728a434 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Wed, 1 Mar 2023 16:43:08 +0000 Subject: [PATCH] Batch processing Updates to support batch processing control --- src/PamModel/PamModel.java | 2 - src/PamView/component/DataBlockTableView.java | 59 +++++++++++++++---- src/generalDatabase/PamTableDefinition.java | 2 +- src/generalDatabase/PamTableItem.java | 5 +- src/generalDatabase/sqlite/SqliteSystem.java | 32 +++++++++- 5 files changed, 85 insertions(+), 15 deletions(-) diff --git a/src/PamModel/PamModel.java b/src/PamModel/PamModel.java index 38539cfe..4ce627dc 100644 --- a/src/PamModel/PamModel.java +++ b/src/PamModel/PamModel.java @@ -460,8 +460,6 @@ final public class PamModel implements PamModelInterface, PamSettings { mi.setModulesMenuGroup(utilitiesGroup); mi.setMaxNumber(1); - - /* * ************* End Utilities Group ******************* */ diff --git a/src/PamView/component/DataBlockTableView.java b/src/PamView/component/DataBlockTableView.java index 7000daa5..124addfc 100644 --- a/src/PamView/component/DataBlockTableView.java +++ b/src/PamView/component/DataBlockTableView.java @@ -5,6 +5,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; import javax.swing.JComponent; import javax.swing.JMenuItem; @@ -49,6 +50,14 @@ public abstract class DataBlockTableView { private SwingTableColumnWidths columnWidths; + /** + * Most work will run off a copy of the data. + * Makes it easier to include data selectors, etc. + */ + private ArrayList dataUnitCopy; + + private Object copySynch = new Object(); + public DataBlockTableView(PamDataBlock pamDataBlock, String displayName) { this.pamDataBlock = pamDataBlock; this.displayName = displayName; @@ -141,6 +150,9 @@ public abstract class DataBlockTableView { String tip = null; java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); + if (rowIndex < 0) { + return null; + } int colIndex = columnAtPoint(p); int realColumnIndex = convertColumnIndexToModel(colIndex); T dataUnit = getDataUnit(rowIndex); @@ -201,10 +213,14 @@ public abstract class DataBlockTableView { * @return data unit for the table row. */ private final T getDataUnit(int tableRow) { - synchronized (pamDataBlock.getSynchLock()) { + synchronized (copySynch) { int rowIndex = getDataIndexForRow(tableRow); if (rowIndex < 0) return null; - return pamDataBlock.getDataUnit(rowIndex, PamDataBlock.REFERENCE_CURRENT); + if (dataUnitCopy == null) { + return null; + } + return dataUnitCopy.get(tableRow); +// return pamDataBlock.getDataUnit(rowIndex, PamDataBlock.REFERENCE_CURRENT); } } @@ -212,10 +228,13 @@ public abstract class DataBlockTableView { * Get the number of rows in the table - default behaviour is the * number of rows in the datablock, but this may be overridded if * data are being selected in a different way. - * @return numer of table rows to show. + * @return number of table rows to show. */ public int getRowCount() { - return pamDataBlock.getUnitsCount(); + if (dataUnitCopy == null) { + return 0; + } + return dataUnitCopy.size(); } /** @@ -227,7 +246,10 @@ public abstract class DataBlockTableView { * @return */ public int getDataIndexForRow(int tableRow) { - int nRow = pamDataBlock.getUnitsCount(); + if (dataUnitCopy == null) { + return tableRow; + } + int nRow = dataUnitCopy.size(); if (!isViewer) { tableRow = nRow-tableRow-1; } @@ -244,12 +266,14 @@ public abstract class DataBlockTableView { @Override public void addData(PamObservable o, PamDataUnit arg) { - blockTableModel.fireTableDataChanged(); + DataBlockTableView.this.updatePamData(); +// blockTableModel.fireTableDataChanged(); } @Override public void updateData(PamObservable observable, PamDataUnit pamDataUnit) { - blockTableModel.fireTableDataChanged(); + DataBlockTableView.this.updatePamData(); +// blockTableModel.fireTableDataChanged(); } @Override @@ -258,6 +282,15 @@ public abstract class DataBlockTableView { } } + + private void updatePamData() { + synchronized (copySynch) { + dataUnitCopy = pamDataBlock.getDataCopy(); + } + blockTableModel.fireTableDataChanged(); + } + + private class MouseAction extends MouseAdapter { /* (non-Javadoc) @@ -304,7 +337,11 @@ public abstract class DataBlockTableView { * @return Array of multiple rows selected. */ public T[] getMultipleSelectedRows() { - synchronized(pamDataBlock.getSynchLock()) { + if (dataUnitCopy == null) { + return null; + } +// synchronized(pamDataBlock.getSynchLock()) { // synch not needed with data copy. + synchronized (copySynch) { int[] selRows = testTable.getSelectedRows(); if (selRows == null) { return null; @@ -337,12 +374,14 @@ public abstract class DataBlockTableView { @Override public void scrollValueChanged(AbstractPamScroller abstractPamScroller) { - blockTableModel.fireTableDataChanged(); +// blockTableModel.fireTableDataChanged(); + updatePamData(); } @Override public void scrollRangeChanged(AbstractPamScroller pamScroller) { - blockTableModel.fireTableDataChanged(); +// blockTableModel.fireTableDataChanged(); + updatePamData(); } } diff --git a/src/generalDatabase/PamTableDefinition.java b/src/generalDatabase/PamTableDefinition.java index 6456671d..e8a2b5dc 100644 --- a/src/generalDatabase/PamTableDefinition.java +++ b/src/generalDatabase/PamTableDefinition.java @@ -13,7 +13,7 @@ import PamUtils.PamCalendar; * tables. Also used to prepare Sql statements for writing and * reading back data. * - * I did a bit of redifining what columns are used for on 4 Oct, 2012. + * I did a bit of redefining what columns are used for on 4 Oct, 2012. * PCLocalTime was a UTC time from the PC of the time analysis took place. * When running in real time, this would be the same as the data in the UTC column * (give or take the odd second for data to get through the system). I've now defined diff --git a/src/generalDatabase/PamTableItem.java b/src/generalDatabase/PamTableItem.java index dc523083..e329cc9e 100644 --- a/src/generalDatabase/PamTableItem.java +++ b/src/generalDatabase/PamTableItem.java @@ -225,7 +225,10 @@ public class PamTableItem implements Cloneable { // } public String getDeblankedStringValue() { - if (sqlType != Types.CHAR || value == null) { +// if (sqlType != Types.CHAR || value == null) { +// return null; +// } + if (value instanceof String == false) { return null; } return ((String) value).trim(); diff --git a/src/generalDatabase/sqlite/SqliteSystem.java b/src/generalDatabase/sqlite/SqliteSystem.java index b41d71b8..3ba3e90f 100644 --- a/src/generalDatabase/sqlite/SqliteSystem.java +++ b/src/generalDatabase/sqlite/SqliteSystem.java @@ -103,7 +103,10 @@ public class SqliteSystem extends DBSystem implements PamSettings { if (commandName == null) { return; } - setDatabaseName(commandName); + File commandFile = new File(commandName); + // check the file end is of the right type. Some batch systems may not get this right. + commandFile = PamFileFilter.checkFileEnd(commandFile, "sqlite3", true); + setDatabaseName(commandFile.getAbsolutePath()); } /** @@ -303,6 +306,30 @@ public class SqliteSystem extends DBSystem implements PamSettings { return true; } + @Override + public boolean checkDatabaseExists(String dbName) { + String commandName = GlobalArguments.getParam(DBControl.GlobalDatabaseNameArg); + if (commandName != null) { + return checkCommandLineDatabase(); + } + return super.checkDatabaseExists(dbName); + } + + private boolean checkCommandLineDatabase() { + String commandName = GlobalArguments.getParam(DBControl.GlobalDatabaseNameArg); + if (commandName == null) { + return false; + } + File dbFile = new File(commandName); + dbFile = PamFileFilter.checkFileEnd(dbFile, ".sqlite3", true); + commandName = dbFile.getAbsolutePath(); + if (dbFile.exists() == false) { + // create a new database without asking. + createNewDatabase(commandName); + } + return dbFile.exists(); + } + @Override public String getDatabaseName() { /* @@ -311,6 +338,9 @@ public class SqliteSystem extends DBSystem implements PamSettings { */ String commandName = GlobalArguments.getParam(DBControl.GlobalDatabaseNameArg); if (commandName != null) { + File dbFile = new File(commandName); + dbFile = PamFileFilter.checkFileEnd(dbFile, ".sqlite3", true); + commandName = dbFile.getAbsolutePath(); return commandName; }