> combine) {
- this.combine = combine;
- return this;
- }
- /**
- * noFunctionChar = false
- * @param key
- * @return
- */
- @JSONField(serialize = false)
- @Override
- public Object getWhere(String key) {
- return getWhere(key, false);
- }
- //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/48
- /**
- * @param key - the key passed in
- * @param exactMatch - whether it is exact match
- * @return
- * use entrySet+getValue() to replace keySet+get() to enhance efficiency
- */
- @JSONField(serialize = false)
- @Override
- public Object getWhere(String key, boolean exactMatch) {
- if (exactMatch) {
- return where == null ? null : where.get(key);
- }
-
- if (key == null || where == null){
- return null;
- }
- synchronized (where) {
- if (where != null) {
- int index;
- for (Entry entry : where.entrySet()) {
- String k = entry.getKey();
- index = k.indexOf(key);
- if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
- return entry.getValue();
- }
- }
- }
- }
- return null;
- }
- @Override
- public AbstractSQLConfig putWhere(String key, Object value, boolean prior) {
- if (key != null) {
- if (where == null) {
- where = new LinkedHashMap();
- }
- if (value == null) {
- where.remove(key);
- } else {
- where.put(key, value);
- }
-
- combine = getCombine();
- List andList = combine.get("&");
- if (value == null) {
- if (andList != null) {
- andList.remove(key);
- }
- }
- else if (andList == null || andList.contains(key) == false) {
- int i = 0;
- if (andList == null) {
- andList = new ArrayList<>();
- }
- else if (prior && andList.isEmpty() == false) {
-
- String idKey = getIdKey();
- String idInKey = idKey + "{}";
- String userIdKey = getUserIdKey();
- String userIdInKey = userIdKey + "{}";
-
- if (andList.contains(idKey)) {
- i ++;
- }
- if (andList.contains(idInKey)) {
- i ++;
- }
- if (andList.contains(userIdKey)) {
- i ++;
- }
- if (andList.contains(userIdInKey)) {
- i ++;
- }
- }
-
- if (prior) {
- andList.add(i, key); //userId的优先级不能比id高 0, key);
- } else {
- andList.add(key); //AbstractSQLExecutor.onPutColumn里getSQL,要保证缓存的SQL和查询的SQL里 where 的 key:value 顺序一致
- }
- }
- combine.put("&", andList);
- }
- return this;
- }
-
- /**获取WHERE
- * @return
- * @throws Exception
- */
- @JSONField(serialize = false)
- @Override
- public String getWhereString(boolean hasPrefix) throws Exception {
- return getWhereString(hasPrefix, getMethod(), getWhere(), getCombine(), getJoinList(), ! isTest());
- }
- /**获取WHERE
- * @param method
- * @param where
- * @return
- * @throws Exception
- */
- @JSONField(serialize = false)
- public String getWhereString(boolean hasPrefix, RequestMethod method, Map where, Map> combine, List joinList, boolean verifyName) throws Exception {
- Set>> combineSet = combine == null ? null : combine.entrySet();
- if (combineSet == null || combineSet.isEmpty()) {
- Log.w(TAG, "getWhereString combineSet == null || combineSet.isEmpty() >> return \"\";");
- return "";
- }
-
- List keyList;
-
- String whereString = "";
-
- boolean isCombineFirst = true;
- int logic;
-
- boolean isItemFirst;
- String c;
- String cs;
-
- for (Entry> ce : combineSet) {
- keyList = ce == null ? null : ce.getValue();
- if (keyList == null || keyList.isEmpty()) {
- continue;
- }
-
- if ("|".equals(ce.getKey())) {
- logic = Logic.TYPE_OR;
- }
- else if ("!".equals(ce.getKey())) {
- logic = Logic.TYPE_NOT;
- }
- else {
- logic = Logic.TYPE_AND;
- }
-
-
- isItemFirst = true;
- cs = "";
- for (String key : keyList) {
- c = getWhereItem(key, where.get(key), method, verifyName);
-
- if (StringUtil.isEmpty(c, true)) {//避免SQL条件连接错误
- continue;
- }
-
- cs += (isItemFirst ? "" : (Logic.isAnd(logic) ? AND : OR)) + "(" + c + ")";
-
- isItemFirst = false;
- }
-
- if (StringUtil.isEmpty(cs, true)) {//避免SQL条件连接错误
- continue;
- }
-
- whereString += (isCombineFirst ? "" : AND) + (Logic.isNot(logic) ? NOT : "") + " ( " + cs + " ) ";
- isCombineFirst = false;
- }
-
-
- if (joinList != null) {
-
- String newWs = "";
- String ws = whereString;
-
- List