From 77ffbe5ff565f7e8e381792e7112916234c4cfca Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Fri, 2 Feb 2024 12:35:27 +0100 Subject: [PATCH] net-sf-ucanaccess-fork: Updates for code style --- .../ucanaccess/commands/CompositeCommand.java | 10 +- .../commands/CreateForeignKeyCommand.java | 8 +- .../commands/CreateIndexCommand.java | 6 +- .../commands/CreatePrimaryKeyCommand.java | 4 +- .../commands/CreateTableCommand.java | 4 +- .../ucanaccess/commands/DeleteCommand.java | 8 +- .../commands/DropForeignKeyCommand.java | 4 +- .../ucanaccess/commands/DropTableCommand.java | 4 +- .../ucanaccess/commands/IndexSelector.java | 6 +- .../ucanaccess/commands/InsertCommand.java | 10 +- .../ucanaccess/commands/UpdateCommand.java | 22 +- .../net/ucanaccess/complex/ComplexBase.java | 2 +- .../java/net/ucanaccess/console/Main.java | 18 +- .../net/ucanaccess/converters/DFunction.java | 2 +- .../net/ucanaccess/converters/LoadJet.java | 10 +- .../net/ucanaccess/converters/Metadata.java | 2 +- .../converters/ParametricQuery.java | 4 +- .../ucanaccess/converters/Persist2Jet.java | 10 +- .../java/net/ucanaccess/converters/Pivot.java | 2 +- .../ucanaccess/converters/SQLConverter.java | 104 ++++----- .../net/ucanaccess/converters/TypesMap.java | 6 +- .../converters/UcanaccessTable.java | 4 +- .../net/ucanaccess/jdbc/AbstractExecute.java | 3 +- .../java/net/ucanaccess/jdbc/DBReference.java | 10 +- .../ucanaccess/jdbc/DBReferenceSingleton.java | 4 +- .../net/ucanaccess/jdbc/UcanaccessBlob.java | 6 +- .../ucanaccess/jdbc/UcanaccessConnection.java | 44 ++-- .../ucanaccess/jdbc/UcanaccessDataSource.java | 2 +- .../jdbc/UcanaccessDatabaseMetadata.java | 221 +++++++++--------- .../net/ucanaccess/jdbc/UcanaccessDriver.java | 5 +- .../jdbc/UcanaccessPreparedStatement.java | 6 +- .../ucanaccess/jdbc/UcanaccessResultSet.java | 8 +- .../jdbc/UcanaccessResultSetMetaData.java | 2 +- .../ucanaccess/jdbc/UcanaccessSavepoint.java | 2 +- .../ucanaccess/jdbc/UcanaccessStatement.java | 10 +- src/main/java/net/ucanaccess/log/Logger.java | 6 +- .../net/ucanaccess/jdbc/AlterTableTest.java | 2 +- .../net/ucanaccess/jdbc/CreateTableTest.java | 8 +- .../jdbc/ExternalResourcesTest.java | 2 +- .../java/net/ucanaccess/jdbc/FolderTest.java | 2 +- 40 files changed, 291 insertions(+), 302 deletions(-) diff --git a/src/main/java/net/ucanaccess/commands/CompositeCommand.java b/src/main/java/net/ucanaccess/commands/CompositeCommand.java index f0beffda..c2d32952 100644 --- a/src/main/java/net/ucanaccess/commands/CompositeCommand.java +++ b/src/main/java/net/ucanaccess/commands/CompositeCommand.java @@ -9,11 +9,11 @@ import java.util.*; public class CompositeCommand implements ICommand { - private List composite = new ArrayList<>(); - private Map currentRow; - private String execId; - private IndexSelector indexSelector; - private List rollbackCache = new ArrayList<>(); + private final List composite = new ArrayList<>(); + private Map currentRow; + private String execId; + private IndexSelector indexSelector; + private final List rollbackCache = new ArrayList<>(); public boolean add(ICursorCommand c4io) { if (indexSelector == null) { diff --git a/src/main/java/net/ucanaccess/commands/CreateForeignKeyCommand.java b/src/main/java/net/ucanaccess/commands/CreateForeignKeyCommand.java index 1578307f..af1c8392 100644 --- a/src/main/java/net/ucanaccess/commands/CreateForeignKeyCommand.java +++ b/src/main/java/net/ucanaccess/commands/CreateForeignKeyCommand.java @@ -8,10 +8,10 @@ public class CreateForeignKeyCommand implements ICommand { - private String tableName; - private String referencedTable; - private String execId; - private String relationshipName; + private final String tableName; + private final String referencedTable; + private final String execId; + private final String relationshipName; public CreateForeignKeyCommand(String _tableName, String _referencedTable, String _execId, String _relationshipName) { tableName = _tableName; diff --git a/src/main/java/net/ucanaccess/commands/CreateIndexCommand.java b/src/main/java/net/ucanaccess/commands/CreateIndexCommand.java index 8a6e9102..fbd1f417 100644 --- a/src/main/java/net/ucanaccess/commands/CreateIndexCommand.java +++ b/src/main/java/net/ucanaccess/commands/CreateIndexCommand.java @@ -7,9 +7,9 @@ import java.sql.SQLException; public class CreateIndexCommand implements ICommand { - private String indexName; - private String tableName; - private String execId; + private final String indexName; + private final String tableName; + private final String execId; public CreateIndexCommand(String _indexName, String _tableName, String _execId) { indexName = _indexName; diff --git a/src/main/java/net/ucanaccess/commands/CreatePrimaryKeyCommand.java b/src/main/java/net/ucanaccess/commands/CreatePrimaryKeyCommand.java index 9f338c84..67aadffb 100644 --- a/src/main/java/net/ucanaccess/commands/CreatePrimaryKeyCommand.java +++ b/src/main/java/net/ucanaccess/commands/CreatePrimaryKeyCommand.java @@ -7,8 +7,8 @@ import java.sql.SQLException; public class CreatePrimaryKeyCommand implements ICommand { - private String tableName; - private String execId; + private final String tableName; + private final String execId; public CreatePrimaryKeyCommand(String _tableName, String _execId) { tableName = _tableName; diff --git a/src/main/java/net/ucanaccess/commands/CreateTableCommand.java b/src/main/java/net/ucanaccess/commands/CreateTableCommand.java index 1e975d2b..59a4bdc9 100644 --- a/src/main/java/net/ucanaccess/commands/CreateTableCommand.java +++ b/src/main/java/net/ucanaccess/commands/CreateTableCommand.java @@ -9,8 +9,8 @@ import java.util.Objects; public class CreateTableCommand implements ICommand { - private String execId; - private String tableName; + private final String execId; + private final String tableName; private String[] types; private String[] defaults; private Boolean[] notNulls; diff --git a/src/main/java/net/ucanaccess/commands/DeleteCommand.java b/src/main/java/net/ucanaccess/commands/DeleteCommand.java index e1297b90..7c7bac50 100644 --- a/src/main/java/net/ucanaccess/commands/DeleteCommand.java +++ b/src/main/java/net/ucanaccess/commands/DeleteCommand.java @@ -11,10 +11,10 @@ import java.util.Map; public class DeleteCommand extends AbstractCursorCommand { - private String execId; - private IndexSelector indexSelector; - private Map rowPattern; - private Table table; + private final String execId; + private final IndexSelector indexSelector; + private final Map rowPattern; + private final Table table; public DeleteCommand(Table _table, Map _rowPattern, String _execId) { indexSelector = new IndexSelector(_table); diff --git a/src/main/java/net/ucanaccess/commands/DropForeignKeyCommand.java b/src/main/java/net/ucanaccess/commands/DropForeignKeyCommand.java index 78e32037..c51bd5a4 100644 --- a/src/main/java/net/ucanaccess/commands/DropForeignKeyCommand.java +++ b/src/main/java/net/ucanaccess/commands/DropForeignKeyCommand.java @@ -8,8 +8,8 @@ public class DropForeignKeyCommand implements ICommand { - private String execId; - private String relationshipName; + private final String execId; + private final String relationshipName; public DropForeignKeyCommand(String _execId, String _relationshipName) { execId = _execId; diff --git a/src/main/java/net/ucanaccess/commands/DropTableCommand.java b/src/main/java/net/ucanaccess/commands/DropTableCommand.java index 21e32b6a..f90f720d 100644 --- a/src/main/java/net/ucanaccess/commands/DropTableCommand.java +++ b/src/main/java/net/ucanaccess/commands/DropTableCommand.java @@ -7,8 +7,8 @@ import java.sql.SQLException; public class DropTableCommand implements ICommand { - private String execId; - private String tableName; + private final String execId; + private final String tableName; public DropTableCommand(String _tableName, String _execId) { tableName = _tableName; diff --git a/src/main/java/net/ucanaccess/commands/IndexSelector.java b/src/main/java/net/ucanaccess/commands/IndexSelector.java index cf6179e0..f6ebf71f 100644 --- a/src/main/java/net/ucanaccess/commands/IndexSelector.java +++ b/src/main/java/net/ucanaccess/commands/IndexSelector.java @@ -19,9 +19,9 @@ public final class IndexSelector { - private Index bestIndex; - private boolean primaryCursor; - private Table table; + private final Table table; + private Index bestIndex; + private boolean primaryCursor; public IndexSelector(Table _table) { table = _table; diff --git a/src/main/java/net/ucanaccess/commands/InsertCommand.java b/src/main/java/net/ucanaccess/commands/InsertCommand.java index 04ab5cc0..785cc82f 100644 --- a/src/main/java/net/ucanaccess/commands/InsertCommand.java +++ b/src/main/java/net/ucanaccess/commands/InsertCommand.java @@ -21,11 +21,11 @@ import java.util.List; public class InsertCommand implements ICommand { - private Database dbIO; - private String execId; - private Object[] newRow; - private Table table; - private String tableName; + private final String tableName; + private Database dbIO; + private Object[] newRow; + private final String execId; + private Table table; public InsertCommand(String _tableName, Database _dbIo, Object[] _newRow, String _execId) { tableName = _tableName; diff --git a/src/main/java/net/ucanaccess/commands/UpdateCommand.java b/src/main/java/net/ucanaccess/commands/UpdateCommand.java index b8864f87..d473952b 100644 --- a/src/main/java/net/ucanaccess/commands/UpdateCommand.java +++ b/src/main/java/net/ucanaccess/commands/UpdateCommand.java @@ -21,19 +21,19 @@ import java.util.Map; public class UpdateCommand extends AbstractCursorCommand { - private List blobColumns; - private String execId; - private IndexSelector indexSelector; - private Object[] modifiedRow; - private Map rowPattern; - private Table table; - private List tableColumns; - private boolean isRollbacking; - - public UpdateCommand(Table _table, Map _map, Object[] _modifiedRow, String _execId) { + private final List tableColumns; + private final IndexSelector indexSelector; + private final Map rowPattern; + private final Object[] modifiedRow; + private final String execId; + private List blobColumns; + private final Table table; + private boolean isRollbacking; + + public UpdateCommand(Table _table, Map _rowPattern, Object[] _modifiedRow, String _execId) { tableColumns = _table.getColumns(); indexSelector = new IndexSelector(_table); - rowPattern = _map; + rowPattern = _rowPattern; modifiedRow = _modifiedRow; execId = _execId; checkBlob(_modifiedRow); diff --git a/src/main/java/net/ucanaccess/complex/ComplexBase.java b/src/main/java/net/ucanaccess/complex/ComplexBase.java index 328088b0..26f62e5e 100644 --- a/src/main/java/net/ucanaccess/complex/ComplexBase.java +++ b/src/main/java/net/ucanaccess/complex/ComplexBase.java @@ -18,7 +18,7 @@ public abstract class ComplexBase implements Serializable { private static final long serialVersionUID = 1L; public static final ComplexValue.Id CREATE_ID = ComplexColumnInfoImpl.INVALID_ID; - private int id; + private final int id; private String tableName; private String columnName; diff --git a/src/main/java/net/ucanaccess/console/Main.java b/src/main/java/net/ucanaccess/console/Main.java index daa9c799..56a22161 100644 --- a/src/main/java/net/ucanaccess/console/Main.java +++ b/src/main/java/net/ucanaccess/console/Main.java @@ -16,16 +16,16 @@ import java.util.stream.Collectors; public class Main { - private static final String EXPORT_USAGE = "export [--help] [--bom] [-d ] [-t ] " - + "[--big_query_schema ] " + "[--newlines] "; + private static final String EXPORT_USAGE = "export [--help] [--bom] [-d ] [-t
] " + + "[--big_query_schema ] " + "[--newlines] "; - private static final String EXPORT_PROMPT = "Export command syntax is: " + EXPORT_USAGE; + private static final String EXPORT_PROMPT = "Export command syntax is: " + EXPORT_USAGE; - private static boolean batchMode = false; - private Connection conn; - private boolean connected = true; - private BufferedReader input; - private String lastSqlQuery; + private static boolean batchMode = false; + private final Connection conn; + private boolean connected = true; + private final BufferedReader input; + private String lastSqlQuery; public Main(Connection _conn, BufferedReader _input) { conn = _conn; @@ -430,7 +430,7 @@ static class TableFormat { static final List NUMERIC_JDBC_TYPES = List.of(Types.BIT, Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT, Types.FLOAT, Types.REAL, Types.DOUBLE, Types.NUMERIC, Types.DECIMAL, Types.ROWID); - private int maxColWidth = 50; + private final int maxColWidth = 50; private final List colNames; private final List colWidths; private final List colTypes; diff --git a/src/main/java/net/ucanaccess/converters/DFunction.java b/src/main/java/net/ucanaccess/converters/DFunction.java index b044934a..48f78308 100644 --- a/src/main/java/net/ucanaccess/converters/DFunction.java +++ b/src/main/java/net/ucanaccess/converters/DFunction.java @@ -25,7 +25,7 @@ public class DFunction { List.of("COUNT", "MAX", "MIN", "SUM", "AVG", "LAST", "FIRST", "LOOKUP"); private Connection conn; - private String sql; + private final String sql; public DFunction(Connection _conn, String _sql) { conn = _conn; diff --git a/src/main/java/net/ucanaccess/converters/LoadJet.java b/src/main/java/net/ucanaccess/converters/LoadJet.java index a2c300a8..a53f4ed0 100644 --- a/src/main/java/net/ucanaccess/converters/LoadJet.java +++ b/src/main/java/net/ucanaccess/converters/LoadJet.java @@ -1293,12 +1293,12 @@ void synchronisationTriggers(String tableName, boolean hasAutoNumberColumn, bool } private final class ViewsLoader { - private static final int OBJECT_ALREADY_EXISTS = -ErrorCode.X_42504; - private static final int OBJECT_NOT_FOUND = -ErrorCode.X_42501; - private static final int UNEXPECTED_TOKEN = -ErrorCode.X_42581; + private static final int OBJECT_ALREADY_EXISTS = -ErrorCode.X_42504; + private static final int OBJECT_NOT_FOUND = -ErrorCode.X_42501; + private static final int UNEXPECTED_TOKEN = -ErrorCode.X_42581; - private Map notLoaded = new HashMap<>(); - private Map notLoadedProcedure = new HashMap<>(); + private final Map notLoaded = new HashMap<>(); + private final Map notLoadedProcedure = new HashMap<>(); private boolean loadView(Query _q) throws SQLException { return loadView(_q, null); diff --git a/src/main/java/net/ucanaccess/converters/Metadata.java b/src/main/java/net/ucanaccess/converters/Metadata.java index 642908c1..ba250376 100644 --- a/src/main/java/net/ucanaccess/converters/Metadata.java +++ b/src/main/java/net/ucanaccess/converters/Metadata.java @@ -175,7 +175,7 @@ public static Property parse(Object _val) { private static final String RENAME = "UPDATE UCA_METADATA.TABLES SET TABLE_NAME=?, ESCAPED_TABLE_NAME=? WHERE TABLE_NAME=?"; - private Connection conn; + private final Connection conn; public Metadata(Connection _conn) { conn = _conn; diff --git a/src/main/java/net/ucanaccess/converters/ParametricQuery.java b/src/main/java/net/ucanaccess/converters/ParametricQuery.java index 617e97e7..3037f86b 100644 --- a/src/main/java/net/ucanaccess/converters/ParametricQuery.java +++ b/src/main/java/net/ucanaccess/converters/ParametricQuery.java @@ -9,8 +9,8 @@ import java.util.regex.Pattern; public class ParametricQuery { - private Connection hsqldb; - private QueryImpl qi; + private final Connection hsqldb; + private final QueryImpl qi; private boolean loaded; private PreparedStatement ps; private String parameters; diff --git a/src/main/java/net/ucanaccess/converters/Persist2Jet.java b/src/main/java/net/ucanaccess/converters/Persist2Jet.java index 7297f849..0ba6c115 100644 --- a/src/main/java/net/ucanaccess/converters/Persist2Jet.java +++ b/src/main/java/net/ucanaccess/converters/Persist2Jet.java @@ -24,9 +24,9 @@ import java.util.*; public class Persist2Jet { - private static Map> columnNamesCache = new HashMap<>(); + private static final Map> COL_NAMES_CACHE = new HashMap<>(); static { - DBReference.addOnReloadRefListener(() -> columnNamesCache.clear()); + DBReference.addOnReloadRefListener(COL_NAMES_CACHE::clear); } public Map getRowPattern(Object[] varr, Table t) throws SQLException { @@ -57,7 +57,7 @@ private List getColumnNames(String ntn) throws SQLException { String pref = conn.getDbIO().getFile().getAbsolutePath(); Connection conq = conn.getHSQLDBConnection(); String key = pref + ntn; - if (!columnNamesCache.containsKey(key)) { + if (!COL_NAMES_CACHE.containsKey(key)) { ResultSet rs = conq.getMetaData().getColumns(null, PUBLIC, ntn, null); Map tm = new TreeMap<>(); while (rs.next()) { @@ -67,9 +67,9 @@ private List getColumnNames(String ntn) throws SQLException { } List ar = new ArrayList<>(tm.values()); - columnNamesCache.put(key, ar); + COL_NAMES_CACHE.put(key, ar); } - return columnNamesCache.get(key); + return COL_NAMES_CACHE.get(key); } private List getColumnNamesCreate(String ntn) throws SQLException { diff --git a/src/main/java/net/ucanaccess/converters/Pivot.java b/src/main/java/net/ucanaccess/converters/Pivot.java index 75234e69..abcb374a 100644 --- a/src/main/java/net/ucanaccess/converters/Pivot.java +++ b/src/main/java/net/ucanaccess/converters/Pivot.java @@ -34,7 +34,7 @@ public class Pivot { private String pivot; private List pivotIn; private String aggregateFun; - private Connection conn; + private final Connection conn; private boolean pivotInCondition = true; private String originalQuery; diff --git a/src/main/java/net/ucanaccess/converters/SQLConverter.java b/src/main/java/net/ucanaccess/converters/SQLConverter.java index 0743af53..d7a36927 100644 --- a/src/main/java/net/ucanaccess/converters/SQLConverter.java +++ b/src/main/java/net/ucanaccess/converters/SQLConverter.java @@ -90,17 +90,17 @@ public final class SQLConverter { "ON", "ORDER", "OR", "OUTER", "PRIMARY", "REFERENCES", "RIGHT", "SELECT", "SET", "SOME", "STDDEV_POP", "STDDEV_SAMP", "SUM", "TABLE", "THEN", "TO", "TRAILING", "TRIGGER", "UNION", "UNIQUE", "USING", "VALUES", "VAR_POP", "VAR_SAMP", "WHEN", "WHERE", "WITH", "END", "DO", "CONSTRAINT", "USER", "ROW"); - private static final String KEYWORD_ALIAS = createKeywordAliasRegex(); - private static final List PROCEDURE_KEYWORD_LIST = List.of("NEW", "ROW"); - private static final List WHITE_SPACED_TABLE_NAMES = new ArrayList<>(); - private static final Set ESCAPED_IDENTIFIERS = new HashSet<>(); - private static final Set ALREADY_ESCAPED_IDENTIFIERS = new HashSet<>(); - private static final Map IDENTIFIERS_CONTAINING_KEYWORD = new HashMap<>(); - private static final Set APOSTROPHISED_NAMES = new HashSet<>(); - private static final Set WORKAROUND_FUNCTIONS = new HashSet<>(); - - private static boolean supportsAccessLike = true; - private static boolean dualUsedAsTableName = false; + private static final String KEYWORD_ALIAS = createKeywordAliasRegex(); + private static final List PROCEDURE_KEYWORD_LIST = List.of("NEW", "ROW"); + private static final List WHITE_SPACED_TABLE_NAMES = new ArrayList<>(); + private static final Set ESCAPED_IDENTIFIERS = new HashSet<>(); + private static final Set ALREADY_ESCAPED_IDENTIFIERS = new HashSet<>(); + private static final Map IDENTIFIERS_CONTAINING_KEYWORD = new HashMap<>(); + private static final Set APOSTROPHISED_NAMES = new HashSet<>(); + private static final Set WORKAROUND_FUNCTIONS = new HashSet<>(); + + private static boolean supportsAccessLike = true; + private static boolean dualUsedAsTableName = false; private SQLConverter() { } @@ -228,47 +228,47 @@ private static int[] getDoubleQuoteGroup(String _s) { public enum DDLType { - CREATE_TABLE_AS_SELECT( - Pattern.compile("[\\s\n\r]*(?i)create[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]*(?)AS[\\s\n\r]*\\(\\s*((?)SELECT)")), - CREATE_TABLE(Pattern.compile("[\\s\n\r]*(?i)create[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN)), - DROP_TABLE_CASCADE( - Pattern.compile( - "[\\s\n\r]*(?i)drop[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + "[\\s\n\r]+(?i)cascade")), - - DROP_TABLE(Pattern.compile("[\\s\n\r]*(?i)drop[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN)), - ALTER_RENAME( - Pattern.compile("[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)rename[\\s\n\r]+(?i)to[\\s\n\r]+" + NAME_PATTERN)), - CREATE_PRIMARY_KEY( - Pattern.compile("[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)constraint[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+)?(?i)primary[\\s\n\r]+(?i)key(.*)")), - CREATE_FOREIGN_KEY( - Pattern.compile("[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)constraint[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+)?(?i)foreign[\\s\n\r]+(?i)key[\\s\n\r]+" - + "(?:\\(.*\\))[\\s\n\r]*(?i)references[\\s\n\r]+" + NAME_PATTERN + "(.*)")), - DROP_FOREIGN_KEY( - Pattern.compile("[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)drop[\\s\n\r]+(?i)constraint[\\s\n\r]+" + NAME_PATTERN)), - - ADD_COLUMN( - Pattern.compile("[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)column[\\s\n\r]+)?" + NAME_PATTERN + "(.*)")), - CREATE_INDEX( - Pattern.compile("(?i)CREATE[\\s\n\r]+(?:(?i)unique)?[\\s\n\r]*(?i)index[\\s\n\r]+" + NAME_PATTERN - + "[\\s\n\r]+(?i)ON[\\s\n\r]+" + NAME_PATTERN + "[\\s\n\r]+")), - - DISABLE_AUTOINCREMENT( - Pattern.compile( - "[\\s\n\r]*(?i)disable[\\s\n\r]+(?i)autoincrement[\\s\n\r]+(?i)on[\\s\n\r]*" + NAME_PATTERN)), - - ENABLE_AUTOINCREMENT( - Pattern.compile( - "[\\s\n\r]*(?i)enable[\\s\n\r]+(?i)autoincrement[\\s\n\r]+(?i)on[\\s\n\r]*" + NAME_PATTERN)); - private Pattern pattern; - private String ddl; + CREATE_TABLE_AS_SELECT(Pattern.compile( + "[\\s\n\r]*(?i)create[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]*(?)AS[\\s\n\r]*\\(\\s*((?)SELECT)")), + CREATE_TABLE(Pattern.compile( + "[\\s\n\r]*(?i)create[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN)), + DROP_TABLE_CASCADE(Pattern.compile( + "[\\s\n\r]*(?i)drop[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + "[\\s\n\r]+(?i)cascade")), + + DROP_TABLE(Pattern.compile( + "[\\s\n\r]*(?i)drop[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN)), + ALTER_RENAME(Pattern.compile( + "[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)rename[\\s\n\r]+(?i)to[\\s\n\r]+" + NAME_PATTERN)), + CREATE_PRIMARY_KEY(Pattern.compile( + "[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)constraint[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+)?(?i)primary[\\s\n\r]+(?i)key(.*)")), + CREATE_FOREIGN_KEY(Pattern.compile( + "[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)constraint[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+)?(?i)foreign[\\s\n\r]+(?i)key[\\s\n\r]+" + + "(?:\\(.*\\))[\\s\n\r]*(?i)references[\\s\n\r]+" + NAME_PATTERN + "(.*)")), + DROP_FOREIGN_KEY(Pattern.compile( + "[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)drop[\\s\n\r]+(?i)constraint[\\s\n\r]+" + NAME_PATTERN)), + + ADD_COLUMN(Pattern.compile( + "[\\s\n\r]*(?i)alter[\\s\n\r]+(?i)table[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)add[\\s\n\r]+(?:(?i)column[\\s\n\r]+)?" + NAME_PATTERN + "(.*)")), + CREATE_INDEX(Pattern.compile( + "(?i)CREATE[\\s\n\r]+(?:(?i)unique)?[\\s\n\r]*(?i)index[\\s\n\r]+" + NAME_PATTERN + + "[\\s\n\r]+(?i)ON[\\s\n\r]+" + NAME_PATTERN + "[\\s\n\r]+")), + + DISABLE_AUTOINCREMENT(Pattern.compile( + "[\\s\n\r]*(?i)disable[\\s\n\r]+(?i)autoincrement[\\s\n\r]+(?i)on[\\s\n\r]*" + NAME_PATTERN)), + + ENABLE_AUTOINCREMENT(Pattern.compile( + "[\\s\n\r]*(?i)enable[\\s\n\r]+(?i)autoincrement[\\s\n\r]+(?i)on[\\s\n\r]*" + NAME_PATTERN)); + + private final Pattern pattern; + private String ddl; DDLType(Pattern _pattern) { pattern = _pattern; diff --git a/src/main/java/net/ucanaccess/converters/TypesMap.java b/src/main/java/net/ucanaccess/converters/TypesMap.java index 2e994b7f..e4cf967f 100644 --- a/src/main/java/net/ucanaccess/converters/TypesMap.java +++ b/src/main/java/net/ucanaccess/converters/TypesMap.java @@ -34,7 +34,7 @@ public enum AccessType { hsqlType = _hsqlType; } - protected String getHsqlType() { + String getHsqlType() { return hsqlType; } @@ -43,9 +43,9 @@ protected String getHsqlType() { private static final Map ACCESS_TO_HSQL_TYPES_MAP = Arrays.stream(AccessType.values()).collect(Collectors.toMap(AccessType::name, AccessType::getHsqlType, (o, n) -> o, LinkedHashMap::new)); @SuppressWarnings("PMD.UseDiamondOperator") - private static final Map ACCESS_TO_JACKCESS_TYPES_MAP = new EnumMap(AccessType.class); + private static final Map ACCESS_TO_JACKCESS_TYPES_MAP = new EnumMap<>(AccessType.class); @SuppressWarnings("PMD.UseDiamondOperator") - private static final Map JACKCESS_TO_HSQLDB_TYPES_MAP = new EnumMap(DataType.class); + private static final Map JACKCESS_TO_HSQLDB_TYPES_MAP = new EnumMap<>(DataType.class); static { ACCESS_TO_JACKCESS_TYPES_MAP.put(AccessType.AUTOINCREMENT, DataType.LONG); diff --git a/src/main/java/net/ucanaccess/converters/UcanaccessTable.java b/src/main/java/net/ucanaccess/converters/UcanaccessTable.java index 34a264ee..7742c4cc 100644 --- a/src/main/java/net/ucanaccess/converters/UcanaccessTable.java +++ b/src/main/java/net/ucanaccess/converters/UcanaccessTable.java @@ -12,8 +12,8 @@ import java.util.Map; public class UcanaccessTable implements Table { - private Table wrapped; - private String tableName; + private final Table wrapped; + private final String tableName; public UcanaccessTable(Table _table, String _tableName) { wrapped = _table; diff --git a/src/main/java/net/ucanaccess/jdbc/AbstractExecute.java b/src/main/java/net/ucanaccess/jdbc/AbstractExecute.java index d0211350..6151de94 100644 --- a/src/main/java/net/ucanaccess/jdbc/AbstractExecute.java +++ b/src/main/java/net/ucanaccess/jdbc/AbstractExecute.java @@ -15,6 +15,7 @@ import java.sql.Statement; import java.util.Arrays; import java.util.Locale; +import java.util.Objects; public abstract class AbstractExecute { protected enum CommandType { @@ -55,7 +56,7 @@ protected AbstractExecute(UcanaccessStatement _statement) { } private Object enableDisable(DDLType _ddlType) throws SQLException, IOException { - String tableName = _ddlType.getDBObjectName(); + String tableName = Objects.requireNonNull(_ddlType.getDBObjectName()); if (tableName.startsWith("[") && tableName.endsWith("]")) { tableName = tableName.substring(1, tableName.length() - 1); } diff --git a/src/main/java/net/ucanaccess/jdbc/DBReference.java b/src/main/java/net/ucanaccess/jdbc/DBReference.java index b2d5e9f2..6040fef2 100644 --- a/src/main/java/net/ucanaccess/jdbc/DBReference.java +++ b/src/main/java/net/ucanaccess/jdbc/DBReference.java @@ -19,14 +19,14 @@ public class DBReference { private static final String CIPHER_SPEC = "AES"; private static List onReloadListeners = new ArrayList<>(); private static String version; - private File dbFile; + private final File dbFile; private Database dbIO; private FileLock fileLock = null; private String id = id(); private boolean inMemory = true; private long lastModified; private boolean openExclusive = false; - private MemoryTimer memoryTimer; + private final MemoryTimer memoryTimer; private boolean readOnly; private boolean readOnlyFileFormat; private boolean showSchema; @@ -35,15 +35,15 @@ public class DBReference { private boolean immediatelyReleaseResources; private boolean encryptHSQLDB; private String encryptionKey; - private String pwd; - private IJackcessOpenerInterface jko; + private final String pwd; + private final IJackcessOpenerInterface jko; private Map externalResourcesMapping; private boolean firstConnection = true; private FileFormat dbFormat; private boolean columnOrderDisplay; private boolean hsqldbShutdown; private File mirrorFolder; - private Set links = new HashSet<>(); + private final Set links = new HashSet<>(); private boolean ignoreCase = true; private boolean mirrorReadOnly; private Integer lobScale; diff --git a/src/main/java/net/ucanaccess/jdbc/DBReferenceSingleton.java b/src/main/java/net/ucanaccess/jdbc/DBReferenceSingleton.java index 5530fbfb..42810610 100644 --- a/src/main/java/net/ucanaccess/jdbc/DBReferenceSingleton.java +++ b/src/main/java/net/ucanaccess/jdbc/DBReferenceSingleton.java @@ -9,8 +9,8 @@ import java.util.Map; public final class DBReferenceSingleton { - private static DBReferenceSingleton singleton; - private Map dbRegistry = Collections.synchronizedMap(new HashMap<>()); + private static DBReferenceSingleton singleton; + private final Map dbRegistry = Collections.synchronizedMap(new HashMap<>()); private DBReferenceSingleton() { } diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessBlob.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessBlob.java index b712da09..66a6d464 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessBlob.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessBlob.java @@ -9,9 +9,9 @@ import java.sql.SQLException; public class UcanaccessBlob implements Blob { - private Blob blob; - private boolean usingBlobKey; - private UcanaccessConnection conn; + private Blob blob; + private boolean usingBlobKey; + private final UcanaccessConnection conn; public UcanaccessBlob(Blob _blob, UcanaccessConnection _conn) throws SQLException { blob = _blob; diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessConnection.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessConnection.java index b163e9db..2b2ea4c8 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessConnection.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessConnection.java @@ -20,42 +20,42 @@ import java.util.concurrent.Executor; public class UcanaccessConnection implements Connection { - static final String BATCH_ID = "BATCH_ID"; - private static ThreadLocal ctx = new ThreadLocal<>(); - - private boolean feedbackState; - private LinkedList commands = new LinkedList<>(); - private Connection hsqlDBConnection; - private Map savepointsMap = new HashMap<>(); - private DBReference ref; - private boolean checkModified = false; - private boolean autoCommit = true; - private Properties clientInfo; - private Session session; - private SQLWarning warnings; - private String url; - private UcanaccessStatement currentStatement; - private Object lastGeneratedKey; - private String refId; + static final String BATCH_ID = "BATCH_ID"; + private static final ThreadLocal CTX = new ThreadLocal<>(); + + private boolean feedbackState; + private final LinkedList commands = new LinkedList<>(); + private Connection hsqlDBConnection; + private final Map savepointsMap = new HashMap<>(); + private DBReference ref; + private boolean checkModified = false; + private boolean autoCommit = true; + private Properties clientInfo; + private Session session; + private SQLWarning warnings; + private String url; + private UcanaccessStatement currentStatement; + private Object lastGeneratedKey; + private String refId; public static synchronized UcanaccessConnection getCtxConnection() { - return Optional.ofNullable(ctx).map(tl -> tl.get().getCurrentConnection()).orElse(null); + return Optional.ofNullable(CTX).map(tl -> tl.get().getCurrentConnection()).orElse(null); } public static synchronized boolean hasContext() { - return ctx.get() != null; + return CTX.get() != null; } public static synchronized String getCtxExcId() { - return ctx.get().getCurrentExecId(); + return CTX.get().getCurrentExecId(); } public static synchronized void setCtxConnection(UcanaccessConnection conn) { - ctx.set(new Context(conn)); + CTX.set(new Context(conn)); } public static synchronized void setCtxExecId(String id) { - ctx.get().setCurrentExecId(id); + CTX.get().setCurrentExecId(id); } public UcanaccessConnection(DBReference _ref, Properties _clientInfo, Session _session) diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessDataSource.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessDataSource.java index e70bcebd..b1d994d4 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessDataSource.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessDataSource.java @@ -26,7 +26,7 @@ public class UcanaccessDataSource implements Serializable, Referenceable, DataSo private String accessPath; private int loginTimeout = 0; - private transient PrintWriter logWriter = Logger.getLogPrintWriter(); + private final transient PrintWriter logWriter = Logger.getLogPrintWriter(); private final Map userPass = new HashMap<>(); private final Map props = new EnumMap<>(Property.class); diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessDatabaseMetadata.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessDatabaseMetadata.java index 0552ac84..55b33519 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessDatabaseMetadata.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessDatabaseMetadata.java @@ -14,13 +14,13 @@ import java.util.List; public class UcanaccessDatabaseMetadata implements DatabaseMetaData { - private static final String SELECT_BASE = "SELECT * FROM INFORMATION_SCHEMA."; - private static final String NATIVE_ALIAS = " l."; - private static final String CUSTOM_ALIAS = " r."; - private static final String CAST_EXPR = "CAST(null AS VARCHAR(50)) AS "; + private static final String SELECT_BASE = "SELECT * FROM INFORMATION_SCHEMA."; + private static final String NATIVE_ALIAS = " l."; + private static final String CUSTOM_ALIAS = " r."; + private static final String CAST_EXPR = "CAST(null AS VARCHAR(50)) AS "; - private UcanaccessConnection connection; - private DatabaseMetaData wrapped; + private final UcanaccessConnection connection; + private final DatabaseMetaData wrapped; public UcanaccessDatabaseMetadata(DatabaseMetaData _wrapped, UcanaccessConnection _connection) { wrapped = _wrapped; @@ -226,19 +226,17 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl Integer[] scopeArr = new Integer[] {bestRowTemporary, bestRowTransaction, bestRowSession}; String nullableS = nullable ? null : String.valueOf(columnNoNulls); - StringBuilder sql = - new StringBuilder(select("SYSTEM_BESTROWIDENTIFIER", + String sql = select("SYSTEM_BESTROWIDENTIFIER", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME), - Arrays.asList(null, null, "TABLE_NAME", COLUMN_NAME))) - .append(from("SYSTEM_BESTROWIDENTIFIER", "COLUMNS_VIEW")) + Arrays.asList(null, null, "TABLE_NAME", COLUMN_NAME)) + + from("SYSTEM_BESTROWIDENTIFIER", "COLUMNS_VIEW") + + on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + and("TABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEM", "=", schema) + and("TABLE_NAME", "=", table) + + and("NULLABLE", "=", nullableS, false) + + in(NATIVE_ALIAS, "SCOPE", scopeArr); - .append(on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(and("TABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEM", "=", schema)).append(and("TABLE_NAME", "=", table)) - .append(and("NULLABLE", "=", nullableS, false)) - .append(in(NATIVE_ALIAS, "SCOPE", scopeArr)); - - return executeQuery(sql.toString()); + return executeQuery(sql); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -298,19 +296,19 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table String schem = connection.isShowSchema() ? "PUBLIC" : null; String s = "SELECT " + cat + " TABLE_CAT, " + schem + " TABLE_SCHEM,"; - StringBuilder select = new StringBuilder(s) - .append(cAlias("TABLE_NAME")).append(",").append(cAlias(COLUMN_NAME)).append(",") - .append(nAlias("GRANTOR")).append(",").append(nAlias("GRANTEE")).append(",") - .append(nAlias("PRIVILEGE_TYPE PRIVILEGE")).append(",").append(nAlias("IS_GRANTABLE")) - .append(from("COLUMN_PRIVILEGES", "COLUMNS_VIEW")) - .append(on(List.of("TABLE_NAME", COLUMN_NAME), - List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(and("TABLE_CATALOG", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEMA", "=", "PUBLIC")) - .append(and("TABLE_NAME", "=", table)) - .append(and(COLUMN_NAME, "LIKE", columnNamePattern)); + String select = s + + cAlias("TABLE_NAME") + "," + cAlias(COLUMN_NAME) + "," + + nAlias("GRANTOR") + "," + nAlias("GRANTEE") + "," + + nAlias("PRIVILEGE_TYPE PRIVILEGE") + "," + nAlias("IS_GRANTABLE") + + from("COLUMN_PRIVILEGES", "COLUMNS_VIEW") + + on(List.of("TABLE_NAME", COLUMN_NAME), + List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + and("TABLE_CATALOG", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEMA", "=", "PUBLIC") + + and("TABLE_NAME", "=", table) + + and(COLUMN_NAME, "LIKE", columnNamePattern); - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -327,18 +325,19 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = new StringBuilder(select("SYSTEM_COLUMNS", + String select = select("SYSTEM_COLUMNS", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME, "COLUMN_DEF", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"), Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, "COLUMN_DEF", "IS_AUTOINCREMENT", - "IS_GENERATEDCOLUMN"))).append(",").append(cAlias("ORIGINAL_TYPE")) - .append(from("SYSTEM_COLUMNS", "COLUMNS_VIEW")) - .append(on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(and("TABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEM", "=", "PUBLIC")) - .append(and("TABLE_NAME", "LIKE", tableNamePattern)) - .append(and(COLUMN_NAME, "LIKE", columnNamePattern)); + "IS_GENERATEDCOLUMN")) + + "," + cAlias("ORIGINAL_TYPE") + + from("SYSTEM_COLUMNS", "COLUMNS_VIEW") + + on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + and("TABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEM", "=", "PUBLIC") + + and("TABLE_NAME", "LIKE", tableNamePattern) + + and(COLUMN_NAME, "LIKE", columnNamePattern); - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -367,25 +366,23 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St } String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = new StringBuilder(select("SYSTEM_CROSSREFERENCE", + String select = select("SYSTEM_CROSSREFERENCE", List.of("PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME", "FKCOLUMN_NAME"), - Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", "v.COLUMN_NAME"))) - .append(from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW")) - - .append(on(List.of("PKTABLE_NAME", "PKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(" INNER JOIN UCA_METADATA.COLUMNS_VIEW v " - + "ON( l.FKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.FKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)") + Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", "v.COLUMN_NAME")) + + from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW") + + on(List.of("PKTABLE_NAME", "PKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + " INNER JOIN UCA_METADATA.COLUMNS_VIEW v " + + "ON( l.FKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.FKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)" + + and("PKTABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("PKTABLE_SCHEM", "=", "PUBLIC") + + and("PKTABLE_NAME", "=", parentTable) + + and("FKTABLE_CAT", "=", "PUBLIC") + + and("FKTABLE_SCHEM", "=", "PUBLIC") + + and("FKTABLE_NAME", "=", foreignTable) + + " ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"; - .append(and("PKTABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("PKTABLE_SCHEM", "=", "PUBLIC")) - .append(and("PKTABLE_NAME", "=", parentTable)) - .append(and("FKTABLE_CAT", "=", "PUBLIC")) - .append(and("FKTABLE_SCHEM", "=", "PUBLIC")) - .append(and("FKTABLE_NAME", "=", foreignTable)) - .append(" ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"); - - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -471,20 +468,19 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th } String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = new StringBuilder(select("SYSTEM_CROSSREFERENCE", + String select = select("SYSTEM_CROSSREFERENCE", List.of("PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME", "FKCOLUMN_NAME"), - Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", - "v.COLUMN_NAME"))).append(from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW")) - .append(on(List.of("PKTABLE_NAME", "PKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(" INNER JOIN UCA_METADATA.COLUMNS_VIEW v " - + "ON( l.FKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.FKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)") - - .append(and("PKTABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("PKTABLE_SCHEM", "=", "PUBLIC")).append(and("PKTABLE_NAME", "=", table)) - .append(" ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"); + Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", "v.COLUMN_NAME")) + + from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW") + + on(List.of("PKTABLE_NAME", "PKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + " INNER JOIN UCA_METADATA.COLUMNS_VIEW v " + + "ON( l.FKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.FKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)" + + and("PKTABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("PKTABLE_SCHEM", "=", "PUBLIC") + and("PKTABLE_NAME", "=", table) + + " ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"; - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -537,20 +533,18 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = new StringBuilder(select("SYSTEM_CROSSREFERENCE", + String select = select("SYSTEM_CROSSREFERENCE", List.of("FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME", "FKCOLUMN_NAME", "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME"), - Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", "v.COLUMN_NAME"))) - .append(from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW")) - - .append(on(List.of("FKTABLE_NAME", "FKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(" INNER JOIN UCA_METADATA.COLUMNS_VIEW v " - + "ON( l.PKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.PKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)") - - .append(and("FKTABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("FKTABLE_SCHEM", "=", "PUBLIC")).append(and("FKTABLE_NAME", "=", table)) - .append(" ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, KEY_SEQ"); - return executeQuery(select.toString()); + Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME, cat, schem, "v.TABLE_NAME", "v.COLUMN_NAME")) + + from("SYSTEM_CROSSREFERENCE", "COLUMNS_VIEW") + + on(List.of("FKTABLE_NAME", "FKCOLUMN_NAME"), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + " INNER JOIN UCA_METADATA.COLUMNS_VIEW v " + + "ON( l.PKTABLE_NAME= v.ESCAPED_TABLE_NAME AND l.PKCOLUMN_NAME= v.ESCAPED_COLUMN_NAME)" + + and("FKTABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("FKTABLE_SCHEM", "=", "PUBLIC") + and("FKTABLE_NAME", "=", table) + + " ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, KEY_SEQ"; + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -566,16 +560,15 @@ public ResultSet getIndexInfo(String catalog, String schema, String table, boole String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; String nuS = unique ? "AND NON_UNIQUE IS FALSE" : ""; - StringBuilder select = new StringBuilder( - select("SYSTEM_INDEXINFO", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME), - Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME))) - .append(from("SYSTEM_INDEXINFO", "COLUMNS_VIEW")) - .append(on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(and("TABLE_CAT", "=", "PUBLIC")) - .append(and("TABLE_SCHEM", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_NAME", "=", table)).append(nuS); + String select = select("SYSTEM_INDEXINFO", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME), + Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME)) + + from("SYSTEM_INDEXINFO", "COLUMNS_VIEW") + + on(List.of("TABLE_NAME", COLUMN_NAME), List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + and("TABLE_CAT", "=", "PUBLIC") + + and("TABLE_SCHEM", "=", "PUBLIC", " WHERE ") + + and("TABLE_NAME", "=", table) + nuS; - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -805,15 +798,14 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr } String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = new StringBuilder( - select("SYSTEM_PRIMARYKEYS", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME), - Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME))) - .append(from("SYSTEM_PRIMARYKEYS", "COLUMNS_VIEW")) - .append(on(List.of("TABLE_NAME", COLUMN_NAME), - List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME"))) - .append(and("TABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEM", "=", "PUBLIC")).append(and("TABLE_NAME", "=", table)); - return executeQuery(select.toString()); + String select = select("SYSTEM_PRIMARYKEYS", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", COLUMN_NAME), + Arrays.asList(cat, schem, "TABLE_NAME", COLUMN_NAME)) + + from("SYSTEM_PRIMARYKEYS", "COLUMNS_VIEW") + + on(List.of("TABLE_NAME", COLUMN_NAME), + List.of("ESCAPED_TABLE_NAME", "ESCAPED_COLUMN_NAME")) + + and("TABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEM", "=", "PUBLIC") + and("TABLE_NAME", "=", table); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -971,17 +963,15 @@ public String getSystemFunctions() throws SQLException { public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { try { tableNamePattern = normalizeName(tableNamePattern); - StringBuilder select = new StringBuilder( - select("TABLE_PRIVILEGES", List.of("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"), - List.of(CAST_EXPR + " TABLE_CAT ", CAST_EXPR + " TABLE_SCHEM", "TABLE_NAME"))) - .append(from("TABLE_PRIVILEGES", "TABLES")) + String select = select("TABLE_PRIVILEGES", List.of("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"), + List.of(CAST_EXPR + " TABLE_CAT ", CAST_EXPR + " TABLE_SCHEM", "TABLE_NAME")) + + from("TABLE_PRIVILEGES", "TABLES") + + on(List.of("TABLE_NAME"), List.of("ESCAPED_TABLE_NAME")) + + and("TABLE_CATALOG", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEMA", "=", "PUBLIC") + + and("TABLE_NAME", "LIKE", tableNamePattern); - .append(on(List.of("TABLE_NAME"), List.of("ESCAPED_TABLE_NAME"))) - .append(and("TABLE_CATALOG", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEMA", "=", "PUBLIC")) - .append(and("TABLE_NAME", "LIKE", tableNamePattern)); - - return executeQuery(select.toString()); + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } @@ -998,17 +988,16 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam String cat = connection.isShowSchema() ? "PUBLIC" : null; String schem = connection.isShowSchema() ? "PUBLIC" : null; - StringBuilder select = - new StringBuilder(select("SYSTEM_TABLES", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME"), - Arrays.asList(cat, schem, "TABLE_NAME"))) - .append(from("SYSTEM_TABLES", "TABLES")) - .append(on(List.of("TABLE_NAME"), List.of("ESCAPED_TABLE_NAME"))) - .append(and("TABLE_CAT", "=", "PUBLIC", " WHERE ")) - .append(and("TABLE_SCHEM", "=", "PUBLIC")) - .append(and("TABLE_NAME", "LIKE", tableNamePattern)) - .append(in(CUSTOM_ALIAS, "TYPE", types)); - - return executeQuery(select.toString()); + String select = select("SYSTEM_TABLES", List.of("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME"), + Arrays.asList(cat, schem, "TABLE_NAME")) + + from("SYSTEM_TABLES", "TABLES") + + on(List.of("TABLE_NAME"), List.of("ESCAPED_TABLE_NAME")) + + and("TABLE_CAT", "=", "PUBLIC", " WHERE ") + + and("TABLE_SCHEM", "=", "PUBLIC") + + and("TABLE_NAME", "LIKE", tableNamePattern) + + in(CUSTOM_ALIAS, "TYPE", types); + + return executeQuery(select); } catch (SQLException _ex) { throw new UcanaccessSQLException(_ex); } diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java index 69207074..404baa5d 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java @@ -222,7 +222,7 @@ public Connection connect(String _url, Properties _props) throws SQLException { } Properties newProps = new Properties(); - props.entrySet().stream() + props.entrySet() .forEach(e -> newProps.put(e.getKey().name(), e.getValue())); newProps.putAll(unknownProps); @@ -238,14 +238,13 @@ public Connection connect(String _url, Properties _props) throws SQLException { private Integer validateLobScale(String _property) { try { - Integer i = Integer.parseInt(_property); + int i = Integer.parseInt(_property); if (i == 1 || i == 2 || i == 4 || i == 8 || i == 16 || i == 32) { return i; } } catch (Exception _ignored) { - } Logger.logWarning(LoggerMessageEnum.LOBSCALE); return null; diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessPreparedStatement.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessPreparedStatement.java index 74e99c73..30dfb027 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessPreparedStatement.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessPreparedStatement.java @@ -18,9 +18,9 @@ public class UcanaccessPreparedStatement extends UcanaccessStatement implements PreparedStatement { - private PreparedStatement wrapped; - private String sql; - private Map memento = new HashMap<>(); + private PreparedStatement wrapped; + private String sql; + private final Map memento = new HashMap<>(); public UcanaccessPreparedStatement(NormalizedSQL _nsql, PreparedStatement _hidden, UcanaccessConnection _conn) throws SQLException { super(_hidden, _conn); diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSet.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSet.java index 744eca35..57dab51d 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSet.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSet.java @@ -11,10 +11,10 @@ import java.util.*; public class UcanaccessResultSet implements ResultSet { - private ResultSet wrapped; - private UcanaccessStatement wrappedStatement; - private Set metadata; - private Set updIndexes = new HashSet<>(); + private final ResultSet wrapped; + private final UcanaccessStatement wrappedStatement; + private Set metadata; + private final Set updIndexes = new HashSet<>(); public UcanaccessResultSet(ResultSet _wrapped, UcanaccessStatement _statement) { wrapped = _wrapped; diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSetMetaData.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSetMetaData.java index 7ea0fed2..6f86449d 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSetMetaData.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessResultSetMetaData.java @@ -11,7 +11,7 @@ public class UcanaccessResultSetMetaData implements ResultSetMetaData { - private ResultSetMetaData wrapped; + private final ResultSetMetaData wrapped; private Metadata metadata; private final Map aliases; diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessSavepoint.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessSavepoint.java index d3166774..b61d1a83 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessSavepoint.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessSavepoint.java @@ -6,7 +6,7 @@ import java.sql.Savepoint; public class UcanaccessSavepoint implements Savepoint { - private Savepoint wrapped; + private final Savepoint wrapped; public UcanaccessSavepoint(Savepoint _wrapped) { wrapped = _wrapped; diff --git a/src/main/java/net/ucanaccess/jdbc/UcanaccessStatement.java b/src/main/java/net/ucanaccess/jdbc/UcanaccessStatement.java index 2f918f3c..fb13296c 100644 --- a/src/main/java/net/ucanaccess/jdbc/UcanaccessStatement.java +++ b/src/main/java/net/ucanaccess/jdbc/UcanaccessStatement.java @@ -13,12 +13,12 @@ public class UcanaccessStatement implements Statement { - private UcanaccessConnection connection; + private final UcanaccessConnection connection; @SuppressWarnings("checkstyle:VisibilityModifierCheck") - protected Statement wrapped; - private Object generatedKey; - private Map aliases; - private boolean enableDisable; + protected Statement wrapped; + private Object generatedKey; + private Map aliases; + private boolean enableDisable; protected Map getAliases() { return aliases; diff --git a/src/main/java/net/ucanaccess/log/Logger.java b/src/main/java/net/ucanaccess/log/Logger.java index 38424db7..14d4b62f 100644 --- a/src/main/java/net/ucanaccess/log/Logger.java +++ b/src/main/java/net/ucanaccess/log/Logger.java @@ -8,9 +8,9 @@ public final class Logger { - private static PrintWriter logPrintWriter; + private static PrintWriter logPrintWriter; /** The resource bundle with logger messages. */ - private static ResourceBundle messageBundle = ResourceBundle.getBundle(ILoggerResourceMessage.BUNDLE_NAME); + private static final ResourceBundle MESSAGE_BUNDLE = ResourceBundle.getBundle(ILoggerResourceMessage.BUNDLE_NAME); private Logger() { } @@ -29,7 +29,7 @@ public static PrintWriter getLogPrintWriter() { } public static String getMessage(String _code, Object... _params) { - String msg = Optional.ofNullable(_code).map(messageBundle::getString).orElse(_code); + String msg = Optional.ofNullable(_code).map(MESSAGE_BUNDLE::getString).orElse(_code); if (_code != null && _params != null && _params.length > 0) { msg = String.format(msg, _params); } diff --git a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java index 5ce6e8bc..ca96c845 100644 --- a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java @@ -293,7 +293,7 @@ void testSqlErrors(AccessVersion _accessVersion) throws SQLException { "ALTER TABLE tx2 ALTER COLUMN [my best friend] SET DEFAULT 33", "Feature not supported.", "ALTER TABLE tx2 DROP COLUMN [my best friend]", "Feature not supported.", "ALTER TABLE tx2 ADD COLUMN [1 my best friend] LONG NOT NULL", "x2 already contains one or more records(1 records)") - .entrySet().stream().forEach( + .entrySet().forEach( e -> { String ddl = e.getKey(); String expectedMessage = e.getValue(); diff --git a/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java b/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java index 8b278068..9af09f7a 100644 --- a/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java @@ -212,10 +212,10 @@ void testPs(AccessVersion _accessVersion) throws SQLException { init(_accessVersion); for (PreparedStatement ps : List.of( - ucanaccess.prepareStatement("CREATE TABLE PS (PS AUTOINCREMENT PRIMARY KEY)"), - ucanaccess.prepareStatement("CREATE TABLE PS1 (PS AUTOINCREMENT PRIMARY KEY)", 0, 0), - ucanaccess.prepareStatement("CREATE TABLE PS2 (PS AUTOINCREMENT PRIMARY KEY)", 0, 0, 0), - ucanaccess.prepareStatement("CREATE TABLE PS3 (PS AUTOINCREMENT PRIMARY KEY)", 0))) { + ucanaccess.prepareStatement("CREATE TABLE PS0 (PS AUTOINCREMENT PRIMARY KEY)"), + ucanaccess.prepareStatement("CREATE TABLE PS1 (PS AUTOINCREMENT PRIMARY KEY)", 0), + ucanaccess.prepareStatement("CREATE TABLE PS2 (PS AUTOINCREMENT PRIMARY KEY)", 0, 0), + ucanaccess.prepareStatement("CREATE TABLE PS3 (PS AUTOINCREMENT PRIMARY KEY)", 0, 0, 0))) { ps.execute(); } } diff --git a/src/test/java/net/ucanaccess/jdbc/ExternalResourcesTest.java b/src/test/java/net/ucanaccess/jdbc/ExternalResourcesTest.java index 2bc82386..0806e53e 100644 --- a/src/test/java/net/ucanaccess/jdbc/ExternalResourcesTest.java +++ b/src/test/java/net/ucanaccess/jdbc/ExternalResourcesTest.java @@ -13,7 +13,7 @@ class ExternalResourcesTest extends UcanaccessBaseTest { @ParameterizedTest(name = "[{index}] {0}") @MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()") - void testLinks(AccessVersion _accessVersion) throws SQLException, ClassNotFoundException { + void testLinks(AccessVersion _accessVersion) throws SQLException { init(_accessVersion); File main = copyResourceToTempFile(getTestDbDir() + "main.mdb"); diff --git a/src/test/java/net/ucanaccess/jdbc/FolderTest.java b/src/test/java/net/ucanaccess/jdbc/FolderTest.java index 95b3c181..fa3cf9b5 100644 --- a/src/test/java/net/ucanaccess/jdbc/FolderTest.java +++ b/src/test/java/net/ucanaccess/jdbc/FolderTest.java @@ -13,7 +13,7 @@ class FolderTest extends UcanaccessBaseTest { @ParameterizedTest(name = "[{index}] {0}") @MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()") - void testFolderContent(AccessVersion _accessVersion) throws SQLException, ClassNotFoundException { + void testFolderContent(AccessVersion _accessVersion) throws SQLException { init(_accessVersion); String folderPath = System.getProperty("accessFolder");