Repository navigation
Expand file tree
/
Copy pathInsertConflictAlgorithm.java
More file actions
66 lines (58 loc) · 2.08 KB
/
Copy pathInsertConflictAlgorithm.java
File metadata and controls
66 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.insert;
/**
* The conflict resolution algorithm of SQLite's {@code INSERT OR <algorithm>}, which {@link Insert}
* carries as a prefix in front of the INTO keyword.
*
* <p>
* SQLite accepts ABORT, FAIL, IGNORE, REPLACE and ROLLBACK after {@code INSERT OR} (see SQLite's
* {@code lang_insert} and {@code lang_conflict} pages). MySQL's {@code REPLACE} statement keeps its
* historic {@link net.sf.jsqlparser.statement.upsert.Upsert} reading.
*
* @see net.sf.jsqlparser.statement.update.UpdateConflictAlgorithm
*/
public enum InsertConflictAlgorithm {
OR_ABORT("OR ABORT"), OR_FAIL("OR FAIL"), OR_IGNORE("OR IGNORE"), OR_REPLACE(
"OR REPLACE"), OR_ROLLBACK("OR ROLLBACK");
private final String keywords;
InsertConflictAlgorithm(String keywords) {
this.keywords = keywords;
}
/** The words printed between INSERT and INTO. */
public String getKeywords() {
return keywords;
}
/** The algorithm without the OR, as in {@code INSERT OR IGNORE}: IGNORE. */
public String getAlgorithm() {
return keywords.substring("OR ".length());
}
/**
* The algorithm of {@code INSERT OR <algorithm>}.
*
* @param algorithm ABORT, FAIL, IGNORE, REPLACE or ROLLBACK, in any case
* @return the matching constant
* @throws IllegalArgumentException when the word is not a SQLite conflict algorithm
*/
public static InsertConflictAlgorithm fromAlgorithm(String algorithm) {
String upperCase = algorithm.toUpperCase(java.util.Locale.ROOT);
for (InsertConflictAlgorithm value : values()) {
if (value.getAlgorithm().equals(upperCase)) {
return value;
}
}
throw new IllegalArgumentException(
"Expected ABORT, FAIL, IGNORE, REPLACE or ROLLBACK but found " + algorithm);
}
@Override
public String toString() {
return keywords;
}
}