MCPcopy Index your code
hub / github.com/Tencent/APIJSON / setKeyAndType

Method setKeyAndType

APIJSONORM/src/main/java/apijson/orm/Join.java:270–353  ·  view source on GitHub ↗
(String joinType, String table, @NotNull String originKey)

Source from the content-addressed store, hash-verified

268
269
270 public void setKeyAndType(String joinType, String table, @NotNull String originKey) throws Exception { //id, id@, id{}@, contactIdList<>@ ...
271 if (originKey.endsWith("@")) {
272 originKey = originKey.substring(0, originKey.length() - 1);
273 }
274 else { //TODO 暂时只允许 User.id = Moment.userId 字段关联,不允许 User.id = 82001 这种
275 throw new IllegalArgumentException(joinType + "/.../" + table + "/" + originKey + " 中字符 " + originKey + " 不合法!join:'.../refKey'" + " 中 refKey 必须以 @ 结尾!");
276 }
277
278 String k;
279
280 if (originKey.endsWith("{}")) {
281 setRelateType("{}");
282 k = originKey.substring(0, originKey.length() - 2);
283 }
284 else if (originKey.endsWith("<>")) {
285 setRelateType("<>");
286 k = originKey.substring(0, originKey.length() - 2);
287 }
288 else if (originKey.endsWith("$")) { // key%$:"a" -> key LIKE '%a%'; key?%$:"a" -> key LIKE 'a%'; key_?$:"a" -> key LIKE '_a'; key_%$:"a" -> key LIKE '_a%'
289 k = originKey.substring(0, originKey.length() - 1);
290 char c = k.isEmpty() ? 0 : k.charAt(k.length() - 1);
291
292 String t = "$";
293 if (c == '%' || c == '_' || c == '?') {
294 t = c + t;
295 k = k.substring(0, k.length() - 1);
296
297 char c2 = k.isEmpty() ? 0 : k.charAt(k.length() - 1);
298 if (c2 == '%' || c2 == '_' || c2 == '?') {
299 if (c2 == c) {
300 throw new IllegalArgumentException(originKey + ":value 中字符 " + k + " 不合法!key$:value 中不允许 key 中有连续相同的占位符!");
301 }
302
303 t = c2 + t;
304 k = k.substring(0, k.length() - 1);
305 }
306 else if (c == '?') {
307 throw new IllegalArgumentException(originKey + ":value 中字符 " + originKey + " 不合法!key$:value 中不允许只有单独的 '?',必须和 '%', '_' 之一配合使用 !");
308 }
309 }
310
311 setRelateType(t);
312 }
313 else if (originKey.endsWith("~")) {
314 boolean ignoreCase = originKey.endsWith("*~");
315 setRelateType(ignoreCase ? "*~" : "~");
316 k = originKey.substring(0, originKey.length() - (ignoreCase ? 2 : 1));
317 }
318 else if (originKey.endsWith(">=")) {
319 setRelateType(">=");
320 k = originKey.substring(0, originKey.length() - 2);
321 }
322 else if (originKey.endsWith("<=")) {
323 setRelateType("<=");
324 k = originKey.substring(0, originKey.length() - 2);
325 }
326 else if (originKey.endsWith(">")) {
327 setRelateType(">");

Callers 1

onJoinParseMethod · 0.95

Calls 7

setRelateTypeMethod · 0.95
setLogicMethod · 0.95
isNameMethod · 0.95
getKeyMethod · 0.95
setKeyMethod · 0.95
lengthMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected