예제 #1
0
 @Override
 protected <T> CharSequence createSQLJoin(
     final Function<Class, EntityInfo> func,
     final Map<Class, String> joinTabalis,
     final EntityInfo<T> info) {
   boolean morejoin = false;
   if (this.joinEntity == null) {
     if (this.joinClass != null) this.joinEntity = func.apply(this.joinClass);
     if (this.nodes != null) {
       for (FilterNode node : this.nodes) {
         if (node instanceof FilterJoinNode) {
           FilterJoinNode joinNode = ((FilterJoinNode) node);
           if (joinNode.joinClass != null) {
             joinNode.joinEntity = func.apply(joinNode.joinClass);
             if (this.joinClass != null && this.joinClass != joinNode.joinClass) morejoin = true;
           }
         }
       }
     }
   }
   StringBuilder sb = new StringBuilder();
   if (this.joinClass != null) {
     sb.append(createElementSQLJoin(joinTabalis, info, this));
   }
   if (morejoin) {
     Set<Class> set = new HashSet<>();
     if (this.joinClass != null) set.add(this.joinClass);
     for (FilterNode node : this.nodes) {
       if (node instanceof FilterJoinNode) {
         FilterJoinNode joinNode = ((FilterJoinNode) node);
         if (!set.contains(joinNode.joinClass)) {
           CharSequence cs = createElementSQLJoin(joinTabalis, info, joinNode);
           if (cs != null) {
             sb.append(cs);
             set.add(joinNode.joinClass);
           }
         }
       }
     }
   }
   return sb;
 }
예제 #2
0
 private static CharSequence createElementSQLJoin(
     final Map<Class, String> joinTabalis, final EntityInfo info, final FilterJoinNode node) {
   if (node.joinClass == null) return null;
   StringBuilder sb = new StringBuilder();
   String[] joinColumns = node.joinColumns;
   sb.append(" INNER JOIN ")
       .append(node.joinEntity.getTable())
       .append(" ")
       .append(joinTabalis.get(node.joinClass))
       .append(" ON ")
       .append(info.getSQLColumn("a", joinColumns[0]))
       .append(" = ")
       .append(node.joinEntity.getSQLColumn(joinTabalis.get(node.joinClass), joinColumns[0]));
   for (int i = 1; i < joinColumns.length; i++) {
     sb.append(" AND ")
         .append(info.getSQLColumn("a", joinColumns[i]))
         .append(" = ")
         .append(node.joinEntity.getSQLColumn(joinTabalis.get(node.joinClass), joinColumns[i]));
   }
   return sb;
 }
예제 #3
0
 protected void loadHttpServlet(final AnyValue conf, final ClassFilter<? extends Servlet> filter)
     throws Exception {
   final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
   final String prefix = conf == null ? "" : conf.getValue("path", "");
   final String threadName = "[" + Thread.currentThread().getName() + "] ";
   List<FilterEntry<? extends Servlet>> list = new ArrayList(filter.getFilterEntrys());
   list.sort(
       (FilterEntry<? extends Servlet> o1,
           FilterEntry<? extends Servlet>
               o2) -> { // 必须保证WebSocketServlet优先加载, 因为要确保其他的HttpServlet可以注入本地模式的WebSocketNode
         boolean ws1 = WebSocketServlet.class.isAssignableFrom(o1.getType());
         boolean ws2 = WebSocketServlet.class.isAssignableFrom(o2.getType());
         if (ws1 == ws2) return o1.getType().getName().compareTo(o2.getType().getName());
         return ws1 ? -1 : 1;
       });
   final List<AbstractMap.SimpleEntry<String, String[]>> ss =
       sb == null ? null : new ArrayList<>();
   for (FilterEntry<? extends Servlet> en : list) {
     Class<HttpServlet> clazz = (Class<HttpServlet>) en.getType();
     if (Modifier.isAbstract(clazz.getModifiers())) continue;
     WebServlet ws = clazz.getAnnotation(WebServlet.class);
     if (ws == null || ws.value().length == 0) continue;
     final HttpServlet servlet = clazz.newInstance();
     resourceFactory.inject(servlet, this);
     final String[] mappings = ws.value();
     String pref = ws.repair() ? prefix : "";
     DefaultAnyValue servletConf = (DefaultAnyValue) en.getProperty();
     WebInitParam[] webparams = ws.initParams();
     if (webparams.length > 0) {
       if (servletConf == null) servletConf = new DefaultAnyValue();
       for (WebInitParam webparam : webparams) {
         servletConf.addValue(webparam.name(), webparam.value());
       }
     }
     this.httpServer.addHttpServlet(servlet, pref, servletConf, mappings);
     if (ss != null) {
       for (int i = 0; i < mappings.length; i++) {
         mappings[i] = pref + mappings[i];
       }
       ss.add(new AbstractMap.SimpleEntry<>(clazz.getName(), mappings));
     }
   }
   if (ss != null) {
     Collections.sort(
         ss,
         (AbstractMap.SimpleEntry<String, String[]> o1,
             AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
     int max = 0;
     for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
       if (as.getKey().length() > max) max = as.getKey().length();
     }
     for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
       sb.append(threadName).append(" Loaded ").append(as.getKey());
       for (int i = 0; i < max - as.getKey().length(); i++) {
         sb.append(' ');
       }
       sb.append("  mapping to  ").append(Arrays.toString(as.getValue())).append(LINE_SEPARATOR);
     }
   }
   if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
 }