BrightSide Workbench Full Report + Source Code
org.turro.elephant.db.IdUtils Class Reference

Static Public Member Functions

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)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 31 of file IdUtils.java.

Member Function Documentation

◆ 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.

91  {
92  return getMaxLongIdFromLong(dao, table, field, new String[] {});
93  }
static long getMaxLongIdFromLong(Dao dao, String table, String field)
Definition: IdUtils.java:91
Here is the caller graph for this function:

◆ getMaxLongIdFromLong() [2/3]

static long org.turro.elephant.db.IdUtils.getMaxLongIdFromLong ( Dao  dao,
String  table,
String  field,
String  fieldConstraints[] 
)
static

Definition at line 95 of file IdUtils.java.

95  {
96  return getMaxLongIdFromLong(dao, table, field, fieldConstraints, false);
97  }
Here is the call graph for this function:

◆ 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.

99  {
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."));
105  }
106  Object result[] = (Object[]) dao.getSingleResult(wc.getClause());
107  Long regs = (Long) result[0], id = (Long) result[1];
108  if(id == null || id == 0) {
109  regs = 0L;
110  id = 0L;
111  }
112  return count ? (regs.equals(id) ? id + 1L : 0L) : id + 1L;
113  }
static String putPrefix(String field, String prefix)
Definition: IdUtils.java:138
Here is the call graph for this function:

◆ 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.

115  {
116  return getMaxLongIdFromString(dao, table, field, new String[] {});
117  }
static long getMaxLongIdFromString(Dao dao, String table, String field)
Definition: IdUtils.java:115
Here is the caller graph for this function:

◆ 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.

119  {
120  try {
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."));
126  }
127  Long result = (Long) StringParser.convertToClass(Long.class, dao.getSingleNativeResult(wc.getClause()));
128  if(result == null || result == 0) {
129  result = Long.valueOf(0);
130  }
131  return result + 1;
132  } catch(Exception ex) {
133  Logger.getLogger(IdUtils.class.getName()).log(Level.INFO, ElephantContext.logMsg(null), ex);
134  return 1;
135  }
136  }
Here is the call graph for this function:

◆ 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.

33  {
34  return getNewLongIdFromLong(dao, table, field, new String[] {});
35  }
static long getNewLongIdFromLong(Dao dao, String table, String field)
Definition: IdUtils.java:33
Here is the caller graph for this function:

◆ 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.

37  {
38  Long result = getMaxLongIdFromLong(dao, table, field, fieldConstraints, true);
39  if(result == 0) {
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");
44  wc.addClause(" where " + putPrefix(field, "b.") + " <= " + putPrefix(field, "a."));
45  wc.addClause(" and " + putPrefix(field, "b.") + " > 0");
46  for(String fc : fieldConstraints) {
47  if(!Strings.isBlank(fc)) wc.addClause(" and " + putPrefix(fc, "b."));
48  }
49  wc.addClause(")");
50  for(String fc : fieldConstraints) {
51  if(!Strings.isBlank(fc)) wc.addClause(" and " + putPrefix(fc, "a."));
52  }
53  result = (Long) dao.getSingleResult(wc.getClause());
54  if(result == null || result == 0) {
55  result = getMaxLongIdFromLong(dao, table, field, fieldConstraints);
56  }
57  }
58  return result;
59  }
Here is the call graph for this function:

◆ 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.

61  {
62  return getNewLongIdFromString(dao, table, field, new String[] {});
63  }
static long getNewLongIdFromString(Dao dao, String table, String field)
Definition: IdUtils.java:61
Here is the caller graph for this function:

◆ 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.

65  {
66  try {
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."));
75  }
76  wc.addClause(")");
77  for(String fc : fieldConstraints) {
78  if(!Strings.isBlank(fc)) wc.addClause(" and " + putPrefix(fc, "a."));
79  }
80  Long result = (Long) StringParser.convertToClass(Long.class, dao.getSingleNativeResult(wc.getClause()));
81  if(result == null || result == 0) {
82  result = getMaxLongIdFromString(dao, table, field, fieldConstraints);
83  }
84  return result;
85  } catch(Exception ex) {
86  Logger.getLogger(IdUtils.class.getName()).log(Level.INFO, ElephantContext.logMsg(null), ex);
87  return 1;
88  }
89  }
Here is the call graph for this function:

◆ putPrefix()

static String org.turro.elephant.db.IdUtils.putPrefix ( String  field,
String  prefix 
)
static

Definition at line 138 of file IdUtils.java.

138  {
139  int p = Math.max(field.lastIndexOf("("), 0);
140  if(p > 0) {
141  field = field.substring(0, p + 1) + prefix + field.substring(p + 1);
142  } else {
143  field = prefix + field;
144  }
145  return field;
146  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: