|
static long | getNewLongIdFromLong (Dao dao, String table, String field) |
|
static long | getNewLongIdFromLong (Dao dao, String table, String field, String fieldConstraints[]) |
|
static long | getNewLongIdFromString (Dao dao, String table, String field) |
|
static long | getNewLongIdFromString (Dao dao, String table, String field, String fieldConstraints[]) |
|
static long | getMaxLongIdFromLong (Dao dao, String table, String field) |
|
static long | getMaxLongIdFromLong (Dao dao, String table, String field, String fieldConstraints[]) |
|
static long | getMaxLongIdFromLong (Dao dao, String table, String field, String fieldConstraints[], boolean count) |
|
static long | getMaxLongIdFromString (Dao dao, String table, String field) |
|
static long | getMaxLongIdFromString (Dao dao, String table, String field, String fieldConstraints[]) |
|
static String | putPrefix (String field, String prefix) |
|
- Author
- Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g
Definition at line 31 of file IdUtils.java.
◆ getMaxLongIdFromLong() [1/3]
static long org.turro.elephant.db.IdUtils.getMaxLongIdFromLong |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field |
|
) |
| |
|
static |
Definition at line 91 of file IdUtils.java.
static long getMaxLongIdFromLong(Dao dao, String table, String field)
◆ getMaxLongIdFromLong() [2/3]
static long org.turro.elephant.db.IdUtils.getMaxLongIdFromLong |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field, |
|
|
String |
fieldConstraints[] |
|
) |
| |
|
static |
◆ getMaxLongIdFromLong() [3/3]
static long org.turro.elephant.db.IdUtils.getMaxLongIdFromLong |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field, |
|
|
String |
fieldConstraints[], |
|
|
boolean |
count |
|
) |
| |
|
static |
Definition at line 99 of file IdUtils.java.
100 WhereClause wc =
new WhereClause();
101 wc.addClause(
"select count(a." + field +
"), max(a." + field +
") from " + table +
" a");
102 wc.addClause(
"where 1=1");
103 for(String fc : fieldConstraints) {
104 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"a."));
106 Object result[] = (Object[]) dao.getSingleResult(wc.getClause());
107 Long regs = (Long) result[0],
id = (Long) result[1];
108 if(
id ==
null ||
id == 0) {
112 return count ? (regs.equals(
id) ?
id + 1L : 0L) :
id + 1L;
static String putPrefix(String field, String prefix)
◆ getMaxLongIdFromString() [1/2]
static long org.turro.elephant.db.IdUtils.getMaxLongIdFromString |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field |
|
) |
| |
|
static |
Definition at line 115 of file IdUtils.java.
static long getMaxLongIdFromString(Dao dao, String table, String field)
◆ getMaxLongIdFromString() [2/2]
static long org.turro.elephant.db.IdUtils.getMaxLongIdFromString |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field, |
|
|
String |
fieldConstraints[] |
|
) |
| |
|
static |
Definition at line 119 of file IdUtils.java.
121 WhereClause wc =
new WhereClause();
122 wc.addClause(
"select max(cast(a." + field +
" as signed)) from " + table +
" a");
123 wc.addClause(
"where 1=1");
124 for(String fc : fieldConstraints) {
125 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"a."));
127 Long result = (Long) StringParser.convertToClass(Long.class, dao.getSingleNativeResult(wc.getClause()));
128 if(result ==
null || result == 0) {
129 result = Long.valueOf(0);
132 }
catch(Exception ex) {
133 Logger.getLogger(IdUtils.class.getName()).log(Level.INFO, ElephantContext.logMsg(
null), ex);
◆ getNewLongIdFromLong() [1/2]
static long org.turro.elephant.db.IdUtils.getNewLongIdFromLong |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field |
|
) |
| |
|
static |
Definition at line 33 of file IdUtils.java.
static long getNewLongIdFromLong(Dao dao, String table, String field)
◆ getNewLongIdFromLong() [2/2]
static long org.turro.elephant.db.IdUtils.getNewLongIdFromLong |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field, |
|
|
String |
fieldConstraints[] |
|
) |
| |
|
static |
Definition at line 37 of file IdUtils.java.
40 WhereClause wc =
new WhereClause();
41 wc.addClause(
"select max(a." + field +
") + 1 from " + table +
" a");
42 wc.addClause(
"where a." + field +
" = (");
43 wc.addClause(
" select count(*) from " + table +
" b");
45 wc.addClause(
" and " +
putPrefix(field,
"b.") +
" > 0");
46 for(String fc : fieldConstraints) {
47 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"b."));
50 for(String fc : fieldConstraints) {
51 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"a."));
53 result = (Long) dao.getSingleResult(wc.getClause());
54 if(result ==
null || result == 0) {
◆ getNewLongIdFromString() [1/2]
static long org.turro.elephant.db.IdUtils.getNewLongIdFromString |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field |
|
) |
| |
|
static |
Definition at line 61 of file IdUtils.java.
static long getNewLongIdFromString(Dao dao, String table, String field)
◆ getNewLongIdFromString() [2/2]
static long org.turro.elephant.db.IdUtils.getNewLongIdFromString |
( |
Dao |
dao, |
|
|
String |
table, |
|
|
String |
field, |
|
|
String |
fieldConstraints[] |
|
) |
| |
|
static |
Definition at line 65 of file IdUtils.java.
67 WhereClause wc =
new WhereClause();
68 wc.addClause(
"select max(cast(a." + field +
" as signed)) + 1 from " + table +
" a");
69 wc.addClause(
"where cast(" +
putPrefix(field,
"a.") +
" as signed) = (");
70 wc.addClause(
" select count(*) from " + table +
" b");
71 wc.addClause(
" where cast(" +
putPrefix(field,
"b.") +
" as signed) <= cast(" +
putPrefix(field,
"a.") +
" as signed)");
72 wc.addClause(
" and cast(" +
putPrefix(field,
"b.") +
" as signed) > 0");
73 for(String fc : fieldConstraints) {
74 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"b."));
77 for(String fc : fieldConstraints) {
78 if(!Strings.isBlank(fc)) wc.addClause(
" and " +
putPrefix(fc,
"a."));
80 Long result = (Long) StringParser.convertToClass(Long.class, dao.getSingleNativeResult(wc.getClause()));
81 if(result ==
null || result == 0) {
85 }
catch(Exception ex) {
86 Logger.getLogger(IdUtils.class.getName()).log(Level.INFO, ElephantContext.logMsg(
null), ex);
◆ putPrefix()
static String org.turro.elephant.db.IdUtils.putPrefix |
( |
String |
field, |
|
|
String |
prefix |
|
) |
| |
|
static |
Definition at line 138 of file IdUtils.java.
139 int p = Math.max(field.lastIndexOf(
"("), 0);
141 field = field.substring(0, p + 1) + prefix + field.substring(p + 1);
143 field = prefix + field;
The documentation for this class was generated from the following file: