Skip to content

Commit

Permalink
code cleanup (#748)
Browse files Browse the repository at this point in the history
* code cleanup

* remove unused imports
  • Loading branch information
inponomarev authored Nov 27, 2024
1 parent c071ee5 commit 7cebca5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -231,7 +230,7 @@ public final boolean tryInsert() {
ic -> _setAutoIncrement(db().getCurrentIdent(conn(), meta())));
}

getHelper.internalGet(this::_parseResultInternal, Optional.of(this::initXRec),
getHelper.internalGet(this::_parseResultInternal, this::initXRec,
recversion, _currentKeyValues());

postInsert();
Expand Down Expand Up @@ -450,7 +449,7 @@ public boolean tryGetByValuesArray(Object... values) {
if (!canRead()) {
throw new PermissionDeniedException(callContext(), meta(), Action.READ);
}
return getHelper.internalGet(this::_parseResultInternal, Optional.of(this::initXRec),
return getHelper.internalGet(this::_parseResultInternal, this::initXRec,
recversion, values);
}

Expand All @@ -464,7 +463,7 @@ public final boolean tryGetCurrent() {
if (!canRead()) {
throw new PermissionDeniedException(callContext(), meta(), Action.READ);
}
return getHelper.internalGet(this::_parseResultInternal, Optional.of(this::initXRec),
return getHelper.internalGet(this::_parseResultInternal, this::initXRec,
recversion, _currentKeyValues());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

/**
Expand Down Expand Up @@ -52,15 +51,15 @@ PreparedStmtHolder getHolder() {
return get;
}

final boolean internalGet(ParseResultFunction parseResultFunc, Optional<ParseResultCallBack> initXRecFunc,
final boolean internalGet(ParseResultFunction parseResultFunc, ParseResultCallBack initXRecFunc,
int recversion, Object... values) {
PreparedStatement g = prepareGet(recversion, values);
LOGGER.trace("{}", g);
try (ResultSet rs = g.executeQuery()) {
boolean result = rs.next();
if (result) {
parseResultFunc.apply(rs);
initXRecFunc.ifPresent(ParseResultCallBack::apply);
if (initXRecFunc != null) initXRecFunc.apply();
}
return result;
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -140,7 +139,7 @@ public final boolean tryGetByValuesArray(Object... values) {
throw new PermissionDeniedException(callContext(), meta(), Action.READ);
}

return getHelper.internalGet(this::_parseResult, Optional.empty(),
return getHelper.internalGet(this::_parseResult, null,
0, values);
}

Expand All @@ -154,7 +153,7 @@ public final boolean tryGetCurrent() {
if (!canRead()) {
throw new PermissionDeniedException(callContext(), meta(), Action.READ);
}
return getHelper.internalGet(this::_parseResult, Optional.empty(),
return getHelper.internalGet(this::_parseResult, null,
0, _currentKeyValues());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,10 @@ String constantFromSql() {
/**
* Database specific preparation of column for select static method.
*
* @param value to be selected
* @param colName name of the column
* @param maxStringLength maximum length
*/
String prepareRowColumnForSelectStaticStrings(String value, String colName, int maxStringLength) {
String prepareRowColumnForSelectStaticStrings(String colName, int maxStringLength) {
return "? as " + colName;
}

Expand Down Expand Up @@ -843,7 +842,7 @@ public List<String> selectStaticStrings(
//prepare sql
String sql = data.stream().map(
str -> {
String rowStr = prepareRowColumnForSelectStaticStrings(str, columnName, maxStringLength);
String rowStr = prepareRowColumnForSelectStaticStrings(columnName, maxStringLength);
return String.format("SELECT %s %s", rowStr, constantFromSql());
})
.collect(Collectors.joining(" UNION ALL "));
Expand Down Expand Up @@ -908,7 +907,7 @@ public int compareStrings(String left, String right) {
String sql = comparisons.stream()
.map(comparison ->
"SELECT COUNT(*) "
+ " FROM ( SELECT " + prepareRowColumnForSelectStaticStrings("?", "a", maxStringLength)
+ " FROM ( SELECT " + prepareRowColumnForSelectStaticStrings("a", maxStringLength)
+ " " + constantFromSql() + ") r "
+ " WHERE a " + comparison + " ?"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ String constantFromSql() {
}

@Override
String prepareRowColumnForSelectStaticStrings(String value, String colName, int maxStringLength) {
String prepareRowColumnForSelectStaticStrings(String colName, int maxStringLength) {
return String.format("CAST(? as varchar(%d)) as %s", maxStringLength, colName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ String getSelectTriggerBodySql(TriggerQuery query) {
}

@Override
String prepareRowColumnForSelectStaticStrings(String value, String colName, int maxStringLength) {
String prepareRowColumnForSelectStaticStrings(String colName, int maxStringLength) {
return String.format("CAST(? as varchar(%d)) as %s", maxStringLength, colName);
}

Expand Down

0 comments on commit 7cebca5

Please sign in to comment.