Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Code hygiene, introduce UcanaccessRuntimeExce…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
spannm committed Nov 4, 2023
1 parent 725b367 commit 3f51528
Show file tree
Hide file tree
Showing 46 changed files with 1,254 additions and 1,203 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/AddColumnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.addColumn(tableName, columnName, columnMap, types, defaults, notNulls);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/AlterRenameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.renameTable(oldTableName, newTableName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/CompositeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public IFeedbackAction persist() throws SQLException {
}
}
return cfa;
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.createForeignKey(tableName, referencedTable, relationshipName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/CreateIndexCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.createIndex(tableName, indexName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.createPrimaryKey(tableName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/net/ucanaccess/commands/CreateTableCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ public boolean equals(Object obj) {
return false;
}
CreateTableCommand other = (CreateTableCommand) obj;
if (tableName == null) {
if (other.tableName != null) {
return false;
}
} else if (!tableName.equals(other.tableName)) {
return false;
}
return true;
return tableName == null ? other.tableName == null : tableName.equals(other.tableName);
}

@Override
Expand Down Expand Up @@ -80,8 +73,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.createTable(tableName, columnMap, types, defaults, notNulls);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/ucanaccess/commands/DDLCommandEnlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class DDLCommandEnlist {
private Boolean[] notNulls;
private Map<String, String> columnMap = new HashMap<>();

private void enlistCreateTable(String sql, DDLType ddlType) throws SQLException {
String tn = ddlType.getDBObjectName();
private void enlistCreateTable(String _sql, DDLType _ddlType) throws SQLException {
String tn = _ddlType.getDBObjectName();
UcanaccessConnection ac = UcanaccessConnection.getCtxConnection();
String execId = UcanaccessConnection.getCtxExcId();
Connection hsqlConn = ac.getHSQLDBConnection();
Expand All @@ -36,12 +36,12 @@ private void enlistCreateTable(String sql, DDLType ddlType) throws SQLException

lfa.synchronisationTriggers(ntn, true, true);
CreateTableCommand c4io;
if (ddlType.equals(DDLType.CREATE_TABLE)) {
parseTypesFromCreateStatement(sql);
if (_ddlType.equals(DDLType.CREATE_TABLE)) {
parseTypesFromCreateStatement(_sql);
c4io = new CreateTableCommand(tn, execId, columnMap, types, defaults, notNulls);
} else {
try (Statement st = ac.createStatement()) {
ResultSet rs = st.executeQuery(ddlType.getSelect(sql));
ResultSet rs = st.executeQuery(_ddlType.getSelect(_sql));
ResultSetMetaData rsmd = rs.getMetaData();
Metadata mt = new Metadata(ac.getHSQLDBConnection());
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public IFeedbackAction persist() throws SQLException {
if (cur.findNextRow(rowPattern)) {
cur.deleteCurrentRow();
}
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.dropForeignKey(relationshipName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/DropTableCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public IFeedbackAction persist() throws SQLException {
try {
Persist2Jet p2a = new Persist2Jet();
p2a.dropTable(tableName);
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/ucanaccess/commands/ICursorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.healthmarketscience.jackcess.Cursor;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

public interface ICursorCommand extends ICommand {
Expand All @@ -13,5 +12,5 @@ public interface ICursorCommand extends ICommand {

Map<String, Object> getRowPattern();

IFeedbackAction persistCurrentRow(Cursor cur) throws IOException, SQLException;
IFeedbackAction persistCurrentRow(Cursor cur) throws IOException;
}
5 changes: 3 additions & 2 deletions src/main/java/net/ucanaccess/commands/IndexSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
import net.ucanaccess.complex.ComplexBase;
import net.ucanaccess.converters.SQLConverter;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -70,8 +71,8 @@ public boolean matches(Table _table, String _columnName, Object _currVal, Object
if (_currVal instanceof ComplexBase[] && _dbVal instanceof ComplexValueForeignKey) {
try {
return Arrays.equals((ComplexBase[]) _currVal, ComplexBase.convert((ComplexValueForeignKey) _dbVal));
} catch (Exception e) {
throw new RuntimeException(e);
} catch (Exception _ex) {
throw new UcanaccessRuntimeException(_ex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/commands/InsertCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void initComplex() {
public void insertRow(Table _table, Object[] _row) throws IOException {
try {
_table.addRow(newRow);
} catch (ConstraintViolationException e) {
} catch (ConstraintViolationException _ex) {
List<? extends Column> lc = _table.getColumns();
boolean retry = false;
for (Column cl : lc) {
Expand All @@ -88,7 +88,7 @@ public void insertRow(Table _table, Object[] _row) throws IOException {
}
}
if (!retry) {
throw e;
throw _ex;
}
Database db = _table.getDatabase();
File fl = db.getFile();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/ucanaccess/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public IFeedbackAction persist() throws SQLException {
persist(cur);

}
} catch (IOException e) {
throw new UcanaccessSQLException(e);
} catch (IOException _ex) {
throw new UcanaccessSQLException(_ex);
}
return new BlobAction(table, modifiedRow);
}

@Override
public IFeedbackAction persistCurrentRow(Cursor cur) throws IOException, SQLException {
public IFeedbackAction persistCurrentRow(Cursor cur) throws IOException {
if (blobColumns != null) {
for (Column col : blobColumns) {
Object val = cur.getCurrentRowValue(col);
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/net/ucanaccess/complex/ComplexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ public boolean equals(Object obj) {
if (id != other.id) {
return false;
}
if (tableName == null) {
if (other.tableName != null) {
return false;
}
} else if (!tableName.equals(other.tableName)) {
return false;
}
return true;
return tableName == null ? other.tableName == null : tableName.equals(other.tableName);
}

public static Object[] convert(ComplexValueForeignKey fk) throws IOException, UcanaccessSQLException {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/ucanaccess/console/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import net.ucanaccess.log.Logger;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.io.*;
import java.sql.*;
Expand Down Expand Up @@ -34,7 +35,7 @@ private static boolean hasPassword(File fl) throws IOException {
Database db;
try {
db = DatabaseBuilder.open(fl);
} catch (IOException e) {
} catch (IOException _ex) {
DatabaseBuilder dbb = new DatabaseBuilder();
dbb.setReadOnly(true);
dbb.setFile(fl);
Expand Down Expand Up @@ -194,8 +195,8 @@ private String readInput() {
System.exit(0);
}
return ret.trim();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} catch (IOException _ex) {
throw new UcanaccessRuntimeException(_ex.getMessage());
}
}

Expand Down Expand Up @@ -260,8 +261,8 @@ private void start(String[] commands) {
} else {
executeStatement(cmd);
}
} catch (Exception e) {
prompt(e.getMessage());
} catch (Exception _ex) {
prompt(_ex.getMessage());
}
if (exit) {
connected = false;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/ucanaccess/converters/DFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class DFunction {
private static final Pattern FROM_PATTERN = Pattern.compile("\\w*(?i)FROM\\w*");
private static final String SELECT_FROM = "(?i)SELECT(.*\\W)(?i)FROM(.*)";
private static final String DFUNCTIONS_WHERE =
"(?i)_[\\s\n\r]*\\([\\s\n\r]*[\'\"](.*)[\'\"]\\,[\\s\n\r]*[\'\"](.*)[\'\"]\\,[\\s\n\r]*[\'\"](.*)[\'\"][\\s\n\r]*\\)";
"(?i)_[\\s\n\r]*\\([\\s\n\r]*['\"](.*)['\"]\\,[\\s\n\r]*['\"](.*)['\"]\\,[\\s\n\r]*['\"](.*)['\"][\\s\n\r]*\\)";
private static final String DFUNCTIONS_WHERE_DYNAMIC =
"(?i)_[\\s\n\r]*\\([\\s\n\r]*[\'\"](.*)[\'\"]\\,[\\s\n\r]*[\'\"](.*)[\'\"]\\,(.*)\\)";
"(?i)_[\\s\n\r]*\\([\\s\n\r]*['\"](.*)['\"]\\,[\\s\n\r]*['\"](.*)['\"]\\,(.*)\\)";
private static final String DFUNCTIONS_NO_WHERE =
"(?i)_[\\s\n\r]*\\([\\s\n\r]*[\'\"](.*)[\'\"]\\,[\\s\n\r]*[\'\"](.*)[\'\"][\\s\n\r]*\\)";
"(?i)_[\\s\n\r]*\\([\\s\n\r]*['\"](.*)['\"]\\,[\\s\n\r]*['\"](.*)['\"][\\s\n\r]*\\)";
private static final String IDENTIFIER = "(\\W)((?i)_)(\\W)";
private static final List<String> DFUNCTIONLIST =
List.of("COUNT", "MAX", "MIN", "SUM", "AVG", "LAST", "FIRST", "LOOKUP");
Expand Down Expand Up @@ -105,7 +105,7 @@ private String resolveAmbiguosTableName(String identifier) {
return identifier;
}
return tableN;
} catch (SQLException e) {
} catch (SQLException _ex) {
return identifier;
} finally {
if (st != null) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/net/ucanaccess/converters/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.ucanaccess.ext.FunctionType;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.jdbc.UcanaccessSQLException.ExceptionMessages;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.math.BigDecimal;
import java.math.MathContext;
Expand Down Expand Up @@ -160,8 +161,8 @@ public static Integer clng(String value) throws UcanaccessSQLException {
try {
DecimalFormat dc = FormatCache.getNoArgs();
return clng(dc.parse(value).doubleValue());
} catch (ParseException e) {
throw new UcanaccessSQLException(e);
} catch (ParseException _ex) {
throw new UcanaccessSQLException(_ex);
}
}

Expand Down Expand Up @@ -450,15 +451,15 @@ public static Timestamp timestamp0(String dt) {
if (mtc.find()) {
gc.set(Integer.parseInt(mtc.group(1)), Integer.parseInt(mtc.group(2)) - 1, Integer.parseInt(mtc.group(3)));
} else {
throw new RuntimeException("internal error in parsing timestamp");
throw new UcanaccessRuntimeException("internal error in parsing timestamp");
}
mtc = pth.matcher(dt);
if (mtc.find()) {
gc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(mtc.group(1)));
gc.set(Calendar.MINUTE, Integer.parseInt(mtc.group(2)));
gc.set(Calendar.SECOND, Integer.parseInt(mtc.group(3)));
} else {
throw new RuntimeException("internal error in parsing timestamp");
throw new UcanaccessRuntimeException("internal error in parsing timestamp");
}
gc.set(Calendar.MILLISECOND, 0);
return new Timestamp(gc.getTime().getTime());
Expand Down Expand Up @@ -548,8 +549,8 @@ public static String format(Double d, String par) throws UcanaccessSQLException
try {
DecimalFormat formatter = FormatCache.getDecimalFormat(par);
return formatter.format(d);
} catch (Exception e) {
throw new UcanaccessSQLException(e);
} catch (Exception _ex) {
throw new UcanaccessSQLException(_ex);
}
}

Expand All @@ -572,8 +573,8 @@ public static String format(String s, String par, boolean incl) throws Ucanacces
try {

return format(df.parse(s).doubleValue(), par);
} catch (ParseException e) {
throw new UcanaccessSQLException(e);
} catch (ParseException _ex) {
throw new UcanaccessSQLException(_ex);
}
} else if (isDate(s)) {
return format(dateValue(s, false), par);
Expand Down Expand Up @@ -846,7 +847,7 @@ public static String mid(String value, int start, int length) {
}
int len = start - 1 + length;
if (start < 1) {
throw new RuntimeException("Invalid function call");
throw new UcanaccessRuntimeException("Invalid function call");
}
if (len > value.length()) {
len = value.length();
Expand Down Expand Up @@ -1422,7 +1423,7 @@ public static Double formulaToNumeric(String res, String datatype) {
d = Math.rint(d + APPROX);
}
return d;
} catch (Exception e) {
} catch (Exception _ex) {
return null;
}

Expand Down Expand Up @@ -1529,7 +1530,7 @@ public static Timestamp formulaToDate(String res, String datatype) {
}
try {
return dateValue(res, false);
} catch (Exception e) {
} catch (Exception _ex) {
return null;
}
}
Expand Down
Loading

0 comments on commit 3f51528

Please sign in to comment.