Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Code hygiene
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Sep 14, 2023
1 parent 93029d4 commit f90d5c4
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public boolean currentRowMatches(Cursor cur, Map<String, Object> currentRow) {
return true;
}

@Override
public abstract Map<String, Object> getRowPattern();

public void replaceAutoincrement(Map<String, Object> map) {
getRowPattern().putAll(map);
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/ucanaccess/commands/CompositeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public class CompositeCommand implements ICommand {
private IndexSelector indexSelector;
private List<ICursorCommand> rollbackCache = new ArrayList<>();

public CompositeCommand() {
}

public boolean add(ICursorCommand c4io) {
if (indexSelector == null) {
indexSelector = c4io.getIndexSelector();
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/ucanaccess/commands/DDLCommandEnlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ private void enlistCreateTable(String sql, DDLType ddlType) throws SQLException
parseTypesFromCreateStatement(sql);
c4io = new CreateTableCommand(tn, execId, columnMap, types, defaults, notNulls);
} else {
try {
Statement st = ac.createStatement();
try (Statement st = ac.createStatement()) {
ResultSet rs = st.executeQuery(ddlType.getSelect(sql));
ResultSetMetaData rsmd = rs.getMetaData();
Metadata mt = new Metadata(ac.getHSQLDBConnection());
Expand Down Expand Up @@ -246,7 +245,7 @@ private void parseColumnTypes(List<String> typeList, List<String> defaultList,

}

if ((colDecls.length > 2 || reset & colDecls.length == 2)
if ((colDecls.length > 2 || reset && colDecls.length == 2)
&& "not".equalsIgnoreCase(colDecls[colDecls.length - 2])
&& "null".equalsIgnoreCase(colDecls[colDecls.length - 1])) {
notNullList.add(true);
Expand Down Expand Up @@ -292,10 +291,10 @@ private String value(String value) {
return null;
}
if (value.startsWith("\"") && value.endsWith("\"")) {
return value.substring(1, value.length() - 1).replaceAll("\"\"", "\"");
return value.substring(1, value.length() - 1).replace("\"\"", "\"");
}
if (value.startsWith("'") && value.endsWith("'")) {
return value.substring(1, value.length() - 1).replaceAll("''", "'");
return value.substring(1, value.length() - 1).replace("''", "'");
}
return value;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/ucanaccess/complex/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
// if (!super.equals(obj))
// return false;
if (getClass() != obj.getClass()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/complex/ComplexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public abstract class ComplexBase implements Serializable {
private String tableName;
private String columnName;

public ComplexBase(ComplexValue.Id _id, String _tableName, String _columnName) {
protected ComplexBase(ComplexValue.Id _id, String _tableName, String _columnName) {
id = _id.get();
tableName = _tableName;
columnName = _columnName;
}

public ComplexBase(ComplexValue cv) {
protected ComplexBase(ComplexValue cv) {
this(cv.getId(), cv.getComplexValueForeignKey().getColumn().getTable().getName(),
cv.getComplexValueForeignKey().getColumn().getName());
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/net/ucanaccess/console/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,18 @@ private void exportCsvAndSchema(String sqlQuery, String csvFileName, String sche

// output the csvFile
File csvFile = new File(csvFileName);
PrintStream out = new PrintStream(csvFile);
try {
try (PrintStream out = new PrintStream(csvFile)) {
exporter.dumpCsv(rs, out);
out.flush();
} finally {
out.close();
}
prompt("Created CSV file: " + csvFile.getAbsolutePath());

// output the schema file if requested
if (schemaFileName != null) {
File schemaFile = new File(schemaFileName);
out = new PrintStream(schemaFile);
try {
try (PrintStream out = new PrintStream(csvFile)) {
exporter.dumpSchema(rs, out);
out.flush();
} finally {
out.close();
}
prompt("Created schema file: " + schemaFile.getAbsolutePath());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/converters/DFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private String convertDFunctions() {
StringBuilder sb = new StringBuilder();
String g3 = mtc.group(3);
String tableN = mtc.group(2).trim();
String alias = tableN.startsWith("[") & tableN.endsWith("]") ? "[" + unpad(tableN) + "_DALIAS]"
String alias = tableN.startsWith("[") && tableN.endsWith("]") ? "[" + unpad(tableN) + "_DALIAS]"
: tableN + "_DALIAS";
String tn = tableN.startsWith("[") & tableN.endsWith("]") ? unpad(tableN) : tableN;
String tn = tableN.startsWith("[") && tableN.endsWith("]") ? unpad(tableN) : tableN;
sb.append(init).append(s).append("(").append(mtc.group(1)).append(") FROM ").append(tableN)
.append(" AS ").append(alias).append(" WHERE ");
boolean accessConcat = g3.indexOf('&') > 0;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/ucanaccess/converters/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ public static Timestamp formulaToDate(Double res, String datatype) throws Ucanac
d = (d - d.intValue()) * 60;
tr = dateAdd("N", d.intValue(), tr);
d = (d - d.intValue()) * 60;
tr = dateAdd("S", Double.valueOf(Math.rint(d + APPROX)).intValue(), tr);
tr = dateAdd("S", (int) Math.rint(d + APPROX), tr);
return tr;
}

Expand Down Expand Up @@ -1596,7 +1596,7 @@ public static double round(double d, double p) {
@FunctionType(namingConflict = true, functionName = "FIX", argumentTypes = {
AccessType.DOUBLE }, returnType = AccessType.DOUBLE)
public static double fix(double d) {
return sign(d) * mint(Math.abs(d));
return sign(d) * (double) mint(Math.abs(d));
}

@FunctionType(functionName = "PARTITION", argumentTypes = { AccessType.DOUBLE, AccessType.DOUBLE, AccessType.DOUBLE,
Expand Down Expand Up @@ -1638,7 +1638,7 @@ private static int lceil(double d) {
}

private static int lrint(double d) {
return Double.valueOf(Math.rint(d - APPROX)).intValue();
return (int) Math.rint(d - APPROX);
}

private static String padLeft(int ext, int n) {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/ucanaccess/converters/LoadJet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,9 @@ private Object value(Object value, Table table, String columnName, Row row) thro
throw new UcanaccessSQLException(e);
}
}
if (value instanceof byte[]) {
if (BlobKey.hasPrimaryKey(table)) {
BlobKey bk = new BlobKey(table, columnName, row);
return bk.getBytes();
}
if (value instanceof byte[] && BlobKey.hasPrimaryKey(table)) {
BlobKey bk = new BlobKey(table, columnName, row);
return bk.getBytes();
}

if (value instanceof Byte) {
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/net/ucanaccess/converters/Persist2Jet.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ public void convertRowTypes(Object[] values, Table t) throws SQLException {
Column column = it.next();

if (value != null) {
if (value instanceof TimestampData) {
if (column.getType().equals(DataType.SHORT_DATE_TIME)) {
TimestampData ts = (TimestampData) value;
LocalDateTime val = LocalDateTime.of(1970, 1, 1, 0, 0)
.plusSeconds(ts.getSeconds())
.plusNanos(ts.getNanos());
values[i] = val;
}
if (value instanceof TimestampData && column.getType().equals(DataType.SHORT_DATE_TIME)) {
TimestampData ts = (TimestampData) value;
LocalDateTime val = LocalDateTime.of(1970, 1, 1, 0, 0)
.plusSeconds(ts.getSeconds())
.plusNanos(ts.getNanos());
values[i] = val;
}
if (value instanceof BlobData) {
BlobData bd = (BlobData) value;
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/net/ucanaccess/converters/SQLConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static DDLType getDDLType(String s) {
}

private static String elab(String s) {
if (!s.contains("[") | !s.contains("]")) {
if (!s.contains("[") || !s.contains("]")) {
return s;
}
return s.replaceAll("\\[([^\\]]*)\\]", " $0 ");
Expand Down Expand Up @@ -738,14 +738,11 @@ public static String preEscapingIdentifier(String name) {
return escaped.toUpperCase(Locale.US);
}

private static String escapeKeywordIdentifier(String escaped, boolean quote) {
if (escaped == null) {
return null;
private static String escapeKeywordIdentifier(String _escaped, boolean _quote) {
if (_escaped != null && KEYWORDLIST.contains(_escaped.toUpperCase())) {
return _quote ? "\"" + _escaped + "\"" : "[" + _escaped + "]";
}
if (KEYWORDLIST.contains(escaped.toUpperCase())) {
escaped = quote ? "\"" + escaped + "\"" : "[" + escaped + "]";
}
return escaped;
return _escaped;
}

public static String basicEscapingIdentifier(String name) {
Expand All @@ -766,7 +763,7 @@ public static String completeEscaping(String escaped) {
}

private static String hsqlEscape(String escaped, boolean quote) {
if (escaped.indexOf(' ') > 0 || escaped.contains("$")) {
if (escaped != null && (escaped.indexOf(' ') > 0 || escaped.contains("$"))) {
escaped = quote ? "\"" + escaped + "\"" : "[" + escaped + "]";
}
return escaped;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/net/ucanaccess/converters/TypesMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.healthmarketscience.jackcess.DataType;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.*;

public final class TypesMap {
public enum AccessType {
Expand All @@ -30,8 +27,8 @@ public enum AccessType {
}

private static final Map<String, String> ACCESS_TO_HSQL_TYPES_MAP = new LinkedHashMap<>();
private static final Map<AccessType, DataType> ACCESS_TO_JACKCESS_TYPES_MAP = new HashMap<>();
private static final Map<DataType, String> JACKCESS_TO_HSQLDB_TYPES_MAP = new HashMap<>();
private static final Map<AccessType, DataType> ACCESS_TO_JACKCESS_TYPES_MAP = new EnumMap<>(AccessType.class);
private static final Map<DataType, String> JACKCESS_TO_HSQLDB_TYPES_MAP = new EnumMap<>(DataType.class);

static {
ACCESS_TO_HSQL_TYPES_MAP.put(AccessType.BYTE.name(), "SMALLINT");
Expand Down
32 changes: 14 additions & 18 deletions src/main/java/net/ucanaccess/jdbc/AbstractExecute.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected AbstractExecute(UcanaccessResultSet _resultSet) {
commandType = CommandType.UPDATABLE_RESULTSET;
}

public AbstractExecute(UcanaccessStatement _statement) {
protected AbstractExecute(UcanaccessStatement _statement) {
statement = _statement;
}

Expand Down Expand Up @@ -115,32 +115,28 @@ private SQLException checkDDLException() {
}
}

private Object addDDLCommand() throws SQLException {
private Object addDdlCommand() throws SQLException {
Object ret;
try {
DDLType ddlType = SQLConverter.getDDLType(sql);
if (ddlType == null) {
throw checkDDLException();
}

if (DDLType.DROP_FOREIGN_KEY.equals(ddlType)) {
if (!HibernateSupport.isActive()) {
throw new UnsupportedOperationException(
"DROP CONSTRAINT is only supported for Hibernate hbm2ddl.auto \"create\"");
}
if (DDLType.DROP_FOREIGN_KEY.equals(ddlType) && !HibernateSupport.isActive()) {
throw new UnsupportedOperationException(
"DROP CONSTRAINT is only supported for Hibernate hbm2ddl.auto \"create\"");
}

if (DDLType.ADD_COLUMN.equals(ddlType)) {

if (SQLConverter.couldNeedDefault(ddlType.getColumnDefinition())) {
String cn = ddlType.getSecondDBObjectName();
String tn = ddlType.getDBObjectName();
int count = count(ddlType.getDBObjectName());
if (count > 0) {
throw new UcanaccessSQLException(ExceptionMessages.DEFAULT_NEEDED, cn, tn, count);
}

if (DDLType.ADD_COLUMN.equals(ddlType)
&& SQLConverter.couldNeedDefault(ddlType.getColumnDefinition())) {
String cn = ddlType.getSecondDBObjectName();
String tn = ddlType.getDBObjectName();
int count = count(ddlType.getDBObjectName());
if (count > 0) {
throw new UcanaccessSQLException(ExceptionMessages.DEFAULT_NEEDED, cn, tn, count);
}

}

String sql0 = ddlType.equals(DDLType.ADD_COLUMN)
Expand Down Expand Up @@ -231,7 +227,7 @@ public Object executeBase() throws SQLException {
Object retv;

if (checkDDL()) {
retv = addDDLCommand();
retv = addDdlCommand();
} else {
try {
retv = executeWrapped();
Expand Down
Loading

0 comments on commit f90d5c4

Please sign in to comment.