Skip to content

Commit

Permalink
Updates for code style
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Jun 22, 2024
1 parent 607e5b2 commit 3ad7570
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public void doAction(ICommand toChange) throws SQLException {
}

public boolean add(IFeedbackAction ifa) {
if (ifa == null) {
return false;
}
return actions.add(ifa);
return ifa != null && actions.add(ifa);
}

}
6 changes: 2 additions & 4 deletions src/main/java/net/ucanaccess/complex/ComplexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public boolean equals(Object obj) {
} else if (!columnName.equals(other.columnName)) {
return false;
}
if (id != other.id) {
return false;
}
return Objects.equals(tableName, other.tableName);
return id == other.id
&& Objects.equals(tableName, other.tableName);
}

public static Object[] convert(ComplexValueForeignKey fk) throws IOException, UcanaccessSQLException {
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/net/ucanaccess/converters/SQLConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@SuppressWarnings({"PMD.FieldDeclarationsShouldBeAtStartOfClass", "java:S1192", "java:S6353"})
@SuppressWarnings({"PMD.FieldDeclarationsShouldBeAtStartOfClass", "PMD.UnnecessaryFullyQualifiedName",
"java:S1192", "java:S6353"})
public final class SQLConverter {

@SuppressWarnings({"java:S5842", "java:S5852", "java:S5998"})
Expand Down Expand Up @@ -103,7 +104,7 @@ private SQLConverter() {
}

public static boolean hasIdentity(String sql) {
return sql.indexOf("@@") > 0 && sql.toUpperCase(java.util.Locale.US).indexOf("@@IDENTITY") > 0;
return sql.indexOf("@@") > 0 && sql.toUpperCase(Locale.US).indexOf("@@IDENTITY") > 0;
}

private static void aliases(String sql, NormalizedSQL nsql) {
Expand All @@ -128,7 +129,7 @@ private static void aliases(String sql, NormalizedSQL nsql) {
StringBuilder sb = new StringBuilder();
for (char c : sqlc) {
if (c == ' ' || c == '\n' || c == '\r' || c == ',') {
String key = SQLConverter.preEscapingIdentifier(sb.toString());
String key = preEscapingIdentifier(sb.toString());
nsql.put(key, sb.toString());
break;
} else {
Expand Down Expand Up @@ -343,8 +344,7 @@ private static String replaceBacktick(String sql) {

private static String replaceAposNames(String sql) {
for (String an : APOSTROPHISED_NAMES) {
sql = sql.replaceAll("(?i)" + Pattern.quote('[' + an + ']'),
'[' + SQLConverter.basicEscapingIdentifier(an) + ']');
sql = sql.replaceAll("(?i)" + Pattern.quote('[' + an + ']'), '[' + basicEscapingIdentifier(an) + ']');
}
return sql;
}
Expand Down Expand Up @@ -421,7 +421,7 @@ private static String convertQuotedAliases(String sql, NormalizedSQL nsql) {
hs.add(g2);
}
String value = g2.substring(1, g2.length() - 1);
nsql.put(SQLConverter.preEscapingIdentifier(value), value);
nsql.put(preEscapingIdentifier(value), value);
sqlN += sqle.substring(0, m.start()) + m.group(1) + g2.replaceAll("['\"]", "") + m.group(3);
sqle = sqle.substring(m.end());
}
Expand Down Expand Up @@ -813,10 +813,7 @@ public static String convertCreateTable(String sql) throws SQLException {
}

public static boolean checkDDL(String sql) {
if (sql == null) {
return false;
}
return Patterns.CHECK_DDL.matcher(sql.replaceAll("\\s+", " ")).matches();
return sql != null && Patterns.CHECK_DDL.matcher(sql.replaceAll("\\s+", " ")).matches();
}

private static String convertLike(String sql) {
Expand Down Expand Up @@ -866,7 +863,7 @@ public static boolean isSupportsAccessLike() {
}

public static void setSupportsAccessLike(boolean _supportsAccessLike) {
SQLConverter.supportsAccessLike = _supportsAccessLike;
supportsAccessLike = _supportsAccessLike;
}

public static boolean isXescaped(String identifier) {
Expand Down Expand Up @@ -1075,7 +1072,7 @@ static boolean isDualUsedAsTableName() {
}

static void setDualUsedAsTableName(boolean _dualUsedAsTableName) {
SQLConverter.dualUsedAsTableName = _dualUsedAsTableName;
dualUsedAsTableName = _dualUsedAsTableName;
}

public static String removeParameters(String qtxt) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/ucanaccess/jdbc/AbstractExecute.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private int count(String tableName) throws SQLException {
}
}

@SuppressWarnings("PMD.UnusedLocalVariable")
private SQLException checkDdlException() {
UcanaccessConnection conn = statement.getConnection();
try (PreparedStatement ps = conn.getHSQLDBConnection().prepareStatement(SQLConverter.convertSQL(sql).getSql())) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/triggers/TriggerAppendOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void fire(int type, String name, String tableName, Object[] oldR, Object[
ColumnImpl verCol = (ColumnImpl) col.getVersionHistoryColumn();
LocalDateTime upTime = LocalDateTime.now();
String val = newR[i] == null ? null : newR[i].toString();
if (type == org.hsqldb.trigger.Trigger.INSERT_BEFORE_ROW) {
if (INSERT_BEFORE_ROW == type) {
newR[verCol.getColumnNumber()] = new JavaObjectData(new Version[] {new Version(val, upTime)});
} else if (type == org.hsqldb.trigger.Trigger.UPDATE_BEFORE_ROW && (oldR[i] != null || newR[i] != null)) {
} else if (UPDATE_BEFORE_ROW == type && (oldR[i] != null || newR[i] != null)) {
if (oldR[i] == null && newR[i] != null || oldR[i] != null && newR[i] == null
|| !oldR[i].equals(newR[i])) {
Version[] oldV = (Version[]) ((JavaObjectData) oldR[verCol.getColumnNumber()]).getObject();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/triggers/TriggerAutoNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void fire(int type, String name, String tableName, Object[] oldR, Object[
} else

if (cl.isAutoNumber()) {
if (type == org.hsqldb.trigger.Trigger.INSERT_BEFORE_ROW) {
if (INSERT_BEFORE_ROW == type) {

if (t.isAllowAutoNumberInsert()) {
if (cl.getAutoNumberGenerator().getType().equals(DataType.LONG) && newR[i] != null) {
Expand All @@ -62,7 +62,7 @@ public void fire(int type, String name, String tableName, Object[] oldR, Object[
conn.setGeneratedKey(newR[i]);
}
}
} else if (type == org.hsqldb.trigger.Trigger.UPDATE_BEFORE_ROW
} else if (UPDATE_BEFORE_ROW == type
&& cl.getAutoNumberGenerator().getType().equals(DataType.LONG)) {
if (!oldR[i].equals(newR[i])) {
throw new UcanaccessRuntimeException("Cannot update autoincrement column");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/type/AccessVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum AccessVersion {
V2010(FileFormat.V2010),
V2016(FileFormat.V2016);

private static final AccessVersion DEFAULT_ACCESS_VERSION = AccessVersion.V2003;
private static final AccessVersion DEFAULT_ACCESS_VERSION = V2003;

private final FileFormat fileFormat;

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/ucanaccess/util/Try.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public <V1, E1 extends Throwable> Try<V1, E1> map(Function<? super V, ? extends
E1 e1 = (E1) t;
return new Try<>((V1) null, e1);
}
return Try.catching((IThrowingSupplier<V1, E1>) () -> _mapper.apply(val));
return catching((IThrowingSupplier<V1, E1>) () -> _mapper.apply(val));
}

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ public V orElse(V _other) {
*/
public void orElse(IThrowingConsumer<EC, Throwable> _consumer) {
if (hasThrown()) {
Try.catching(() -> _consumer.accept(t)).orThrow();
catching(() -> _consumer.accept(t)).orThrow();
}
}

Expand All @@ -247,7 +247,7 @@ public void orElse(IThrowingConsumer<EC, Throwable> _consumer) {
*/
public V orElseApply(IThrowingFunction<EC, V, Throwable> _function) {
if (hasThrown()) {
return Try.catching(() -> _function.apply(t)).orThrow();
return catching(() -> _function.apply(t)).orThrow();
}
return val;
}
Expand All @@ -259,7 +259,7 @@ public V orElseApply(IThrowingFunction<EC, V, Throwable> _function) {
*/
public V orElseGet(IThrowingSupplier<V, Throwable> _supplier) {
if (hasThrown()) {
return Try.catching(_supplier::get).orThrow();
return catching(_supplier::get).orThrow();
}
return val;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class ConcatNullsFalseTest extends UcanaccessBaseTest {

@Override
protected UcanaccessConnectionBuilder buildConnection() {
return super.buildConnection().withConcatNulls(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/net/ucanaccess/jdbc/DataSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void setLobScaleGood() {
}

@Test
@SuppressWarnings("PMD.UnusedLocalVariable")
void createNewDatabase() throws SQLException {
File fileMdb = createTempFileName("ucaDataSourceTest", ".mdb");
assertThat(fileMdb).doesNotExist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ReloadPersistentMirrorTest extends UcanaccessBaseTest {

@ParameterizedTest(name = "[{index}] {0}")
@AccessVersionSource
@SuppressWarnings("PMD.UnusedLocalVariable")
void testReloadMirror(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);

Expand Down

0 comments on commit 3ad7570

Please sign in to comment.