Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Logging and error handling overhaul
Browse files Browse the repository at this point in the history
- Avoid stderr/out logging and replace by slf4j
- Introduce specific exceptions (subclasses of UcanaccessSQLException)
- All exception classes in package net.ucanaccess.exception
- Completely unwrap logger messages resource bundle
  • Loading branch information
spannm committed Feb 8, 2024
1 parent 263a63c commit 97481ef
Show file tree
Hide file tree
Showing 66 changed files with 367 additions and 460 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import com.healthmarketscience.jackcess.Cursor;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;

import java.io.IOException;
import java.sql.SQLException;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/ucanaccess/commands/DDLCommandEnlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import net.ucanaccess.converters.Metadata;
import net.ucanaccess.converters.SQLConverter;
import net.ucanaccess.converters.SQLConverter.DDLType;
import net.ucanaccess.exception.InvalidCreateStatementException;
import net.ucanaccess.jdbc.UcanaccessConnection;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.jdbc.UcanaccessSQLException.ExceptionMessages;
import net.ucanaccess.jdbc.UcanaccessStatement;

import java.sql.Connection;
Expand Down Expand Up @@ -271,7 +270,7 @@ private void parseTypesFromCreateStatement(String _sql) throws SQLException {
int endDecl = _sql.lastIndexOf(')');

if (startDecl >= endDecl) {
throw new UcanaccessSQLException(ExceptionMessages.INVALID_CREATE_STATEMENT);
throw new InvalidCreateStatementException(_sql);
}
String decl = _sql.substring(startDecl + 1, endDecl);
String[] tokens = decl.split(",");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.healthmarketscience.jackcess.Cursor;
import com.healthmarketscience.jackcess.Table;
import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.commands;

import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;

import java.io.IOException;
import java.sql.SQLException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/commands/IndexSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
import net.ucanaccess.complex.ComplexBase;
import net.ucanaccess.converters.SQLConverter;
import net.ucanaccess.exception.UcanaccessRuntimeException;
import net.ucanaccess.util.Try;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/commands/InsertCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import net.ucanaccess.complex.SingleValue;
import net.ucanaccess.complex.Version;
import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.jdbc.DBReference;
import net.ucanaccess.jdbc.DBReferenceSingleton;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.triggers.AutoNumberManager;

import java.io.File;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.ucanaccess.complex.SingleValue;
import net.ucanaccess.complex.Version;
import net.ucanaccess.converters.Persist2Jet;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.util.Try;

import java.io.IOException;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/ucanaccess/complex/ComplexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.healthmarketscience.jackcess.complex.ComplexValue;
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
import com.healthmarketscience.jackcess.impl.complex.ComplexColumnInfoImpl;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.jdbc.UcanaccessSQLException.ExceptionMessages;
import net.ucanaccess.exception.UcanaccessSQLException;

import java.io.IOException;
import java.io.Serializable;
Expand Down Expand Up @@ -115,7 +114,7 @@ public static Object[] convert(ComplexValueForeignKey fk) throws IOException, Uc
}
return lat;
}
throw new UcanaccessSQLException(ExceptionMessages.COMPLEX_TYPE_UNSUPPORTED);
throw new UcanaccessSQLException("Complex type not supported yet");
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/ucanaccess/console/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.ucanaccess.console;

import static net.ucanaccess.type.SqlConstants.*;
import static net.ucanaccess.type.SqlConstants.FROM;
import static net.ucanaccess.type.SqlConstants.SELECT;

import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import net.ucanaccess.converters.Metadata.Property;
import net.ucanaccess.log.Logger;
import net.ucanaccess.exception.UcanaccessRuntimeException;
import net.ucanaccess.util.Sql;
import net.ucanaccess.util.Try;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.io.*;
import java.sql.*;
Expand Down Expand Up @@ -42,7 +42,6 @@ private static boolean hasPassword(File _f) throws IOException {
}

public static void main(String[] _args) throws Exception {
Logger.setLogPrintWriter(new PrintWriter(System.out));
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
// password properties info
Properties props = new Properties();
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/ucanaccess/converters/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import com.healthmarketscience.jackcess.DataType;
import net.ucanaccess.converters.TypesMap.AccessType;
import net.ucanaccess.exception.InvalidFunctionParameterException;
import net.ucanaccess.exception.InvalidIntervalValueException;
import net.ucanaccess.exception.UcanaccessRuntimeException;
import net.ucanaccess.exception.UcanaccessSQLException;
import net.ucanaccess.ext.FunctionType;
import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.jdbc.UcanaccessSQLException.ExceptionMessages;
import net.ucanaccess.util.Try;
import net.ucanaccess.util.UcanaccessRuntimeException;

import java.math.BigDecimal;
import java.math.MathContext;
Expand Down Expand Up @@ -295,7 +296,7 @@ public static Date dateAdd(String _intv, int _vl, Date _dt) throws UcanaccessSQL
} else if ("s".equalsIgnoreCase(_intv)) { // second
cl.add(Calendar.SECOND, _vl);
} else {
throw new UcanaccessSQLException(ExceptionMessages.INVALID_INTERVAL_VALUE);
throw new InvalidIntervalValueException(_intv);
}
return _dt instanceof Timestamp
? new Timestamp(cl.getTimeInMillis())
Expand Down Expand Up @@ -362,7 +363,7 @@ public static Integer dateDiff(String _intv, Timestamp _dt1, Timestamp _dt2) thr
} else if ("s".equalsIgnoreCase(_intv)) {
result = (int) Math.rint((double) (clMax.getTimeInMillis() - clMin.getTimeInMillis()) / 1000);
} else {
throw new UcanaccessSQLException(ExceptionMessages.INVALID_INTERVAL_VALUE);
throw new InvalidIntervalValueException(_intv);
}
return result * sign;
}
Expand Down Expand Up @@ -466,7 +467,7 @@ public static Integer datePart(String _intv, Timestamp _dt) throws UcanaccessSQL
} else if ("s".equalsIgnoreCase(_intv)) {
return cl.get(Calendar.SECOND);
} else {
throw new UcanaccessSQLException(ExceptionMessages.INVALID_INTERVAL_VALUE);
throw new InvalidIntervalValueException(_intv);
}
}

Expand Down Expand Up @@ -891,7 +892,7 @@ public static String monthName(int _number, boolean _abbreviate) throws Ucanacce
DateFormatSymbols dfs = new DateFormatSymbols();
return _abbreviate ? dfs.getShortMonths()[_number - 1] : dfs.getMonths()[_number - 1];
}
throw new UcanaccessSQLException(ExceptionMessages.INVALID_MONTH_NUMBER);
throw new UcanaccessSQLException("Invalid month number");
}

/**
Expand Down Expand Up @@ -1182,7 +1183,7 @@ public static Integer strComp(String _value1, String _value2, Integer _type) thr
case 1:
return _value1.toUpperCase().compareTo(_value2.toUpperCase());
default:
throw new UcanaccessSQLException(ExceptionMessages.INVALID_PARAMETER);
throw new InvalidFunctionParameterException("StrComp", _type);
}
}

Expand Down
Loading

0 comments on commit 97481ef

Please sign in to comment.