Skip to content

Commit 7ffb392

Browse files
fix: keep CCJSqlParser under the class size limit for JaCoCo
The extra INSERT OR alternatives pushed the constant pool of CCJSqlParser past 65535 entries once JaCoCo instrumented it, so the class was silently left without coverage data and the coverage check failed. Parse the algorithm with RelObjectName and decide in AbstractJSqlParser instead.
1 parent 7eb65c8 commit 7ffb392

2 files changed

Lines changed: 29 additions & 28 deletions

File tree

‎src/main/java/net/sf/jsqlparser/parser/AbstractJSqlParser.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import net.sf.jsqlparser.parser.feature.Feature;
1313
import net.sf.jsqlparser.parser.feature.FeatureConfiguration;
14+
import net.sf.jsqlparser.statement.upsert.UpsertType;
1415

1516
import java.util.ArrayList;
1617
import java.util.Collections;
@@ -259,6 +260,30 @@ public Integer getAsInteger(Feature f) {
259260
return getConfiguration().getAsInteger(f);
260261
}
261262

263+
/**
264+
* The INSERT OR conflict algorithms other than REPLACE are SQLite syntax.
265+
*/
266+
protected UpsertType insertOrType(String algorithm) throws ParseException {
267+
if ("REPLACE".equalsIgnoreCase(algorithm)) {
268+
return UpsertType.INSERT_OR_REPLACE;
269+
}
270+
if (!Dialect.SQLITE.name().equals(getAsString(Feature.dialect))) {
271+
throw new ParseException("INSERT OR " + algorithm + " needs Dialect.SQLITE");
272+
}
273+
switch (algorithm.toUpperCase()) {
274+
case "IGNORE":
275+
return UpsertType.INSERT_OR_IGNORE;
276+
case "ROLLBACK":
277+
return UpsertType.INSERT_OR_ROLLBACK;
278+
case "ABORT":
279+
return UpsertType.INSERT_OR_ABORT;
280+
case "FAIL":
281+
return UpsertType.INSERT_OR_FAIL;
282+
default:
283+
throw new ParseException("Expected ABORT, FAIL, IGNORE, REPLACE or ROLLBACK");
284+
}
285+
}
286+
262287
public String getAsString(Feature f) {
263288
return getConfiguration().getAsString(f);
264289
}

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,11 +3139,6 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
31393139
}
31403140
}
31413141

3142-
private void requireSqliteSyntax(String syntax) throws ParseException {
3143-
requireDdlSyntax(Dialect.SQLITE.name().equals(getAsString(Feature.dialect)),
3144-
syntax + " needs Dialect.SQLITE");
3145-
}
3146-
31473142
private void requireDdlSyntax(boolean valid, String message) throws ParseException {
31483143
if (!valid) {
31493144
throw new ParseException(message);
@@ -8104,6 +8099,7 @@ OutputClause OutputClause():
81048099
Upsert Upsert():
81058100
{
81068101
Upsert upsert = new Upsert();
8102+
String algorithm;
81078103
Table table = null;
81088104
ExpressionList<Column> columns;
81098105
List<UpdateSet> updateSets;
@@ -8121,29 +8117,9 @@ Upsert Upsert():
81218117
|
81228118
(
81238119
<K_INSERT> <K_OR>
8124-
(
8125-
<K_REPLACE> { upsert.setUpsertType(UpsertType.INSERT_OR_REPLACE); }
8126-
|
8127-
// the other conflict resolution algorithms are SQLite syntax
8128-
<K_IGNORE> {
8129-
requireSqliteSyntax("INSERT OR IGNORE");
8130-
upsert.setUpsertType(UpsertType.INSERT_OR_IGNORE);
8131-
}
8132-
|
8133-
<K_ROLLBACK> {
8134-
requireSqliteSyntax("INSERT OR ROLLBACK");
8135-
upsert.setUpsertType(UpsertType.INSERT_OR_ROLLBACK);
8136-
}
8137-
|
8138-
// ABORT and FAIL are not keywords of the parser
8139-
tk=<S_IDENTIFIER> {
8140-
requireSqliteSyntax("INSERT OR " + tk.image);
8141-
requireDdlSyntax("ABORT".equalsIgnoreCase(tk.image) || "FAIL".equalsIgnoreCase(tk.image),
8142-
"Expected ABORT, FAIL, IGNORE, REPLACE or ROLLBACK");
8143-
upsert.setUpsertType("ABORT".equalsIgnoreCase(tk.image)
8144-
? UpsertType.INSERT_OR_ABORT : UpsertType.INSERT_OR_FAIL);
8145-
}
8146-
)
8120+
// ABORT and FAIL are not keywords of the parser
8121+
algorithm=RelObjectName()
8122+
{ upsert.setUpsertType(insertOrType(algorithm)); }
81478123
)
81488124
)
81498125
[ LOOKAHEAD(2) <K_INTO> { upsert.setUsingInto(true); } ]

0 commit comments

Comments
 (0)