Esempio n. 1
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public boolean start() {
   try {
     List<Class> modelClasses = ClassSearcher.findClasses(Model.class);
     TableBind tb = null;
     for (Class modelClass : modelClasses) {
       tb = (TableBind) modelClass.getAnnotation(TableBind.class);
       if (tb == null) {
         this.addMapping(tableName(modelClass), modelClass);
       } else {
         if (StringKit.notBlank(tb.name())) {
           if (StringKit.notBlank(tb.pk())) {
             this.addMapping(tb.name(), tb.pk(), modelClass);
           } else {
             this.addMapping(tb.name(), modelClass);
           }
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     //			throw new RuntimeException(e);
   }
   return super.start();
 }
Esempio n. 2
0
 private String tableName(Class<?> clazz) {
   String tableName = clazz.getSimpleName();
   if (tableNameStyle == TableNameStyle.UP) {
     tableName = tableName.toUpperCase();
   } else if (tableNameStyle == TableNameStyle.LOWER) {
     tableName = tableName.toLowerCase();
   } else {
     tableName = StringKit.firstCharToLowerCase(tableName);
   }
   return tableName;
 }
Esempio n. 3
0
  JettyServer(String webAppDir, int port, String context, int scanIntervalSeconds) {
    if (webAppDir == null)
      throw new IllegalStateException("Invalid webAppDir of web server: " + webAppDir);
    if (port < 0 || port > 65536)
      throw new IllegalArgumentException("Invalid port of web server: " + port);
    if (StringKit.isBlank(context))
      throw new IllegalStateException("Invalid context of web server: " + context);

    this.webAppDir = webAppDir;
    this.port = port;
    this.context = context;
    this.scanIntervalSeconds = scanIntervalSeconds;
  }
Esempio n. 4
0
 @Override
 public void commentForTables(Table table, Connection connection) {
   try {
     String sql = "SHOW TABLE STATUS ";
     pstmt = connection.prepareStatement(sql);
     rs = pstmt.executeQuery();
     table.setComment(table.getName());
     while (rs.next()) {
       if (table.getName().equals(rs.getString("name"))) {
         String comment = rs.getString("comment");
         if (StringKit.notBlank(comment)) {
           table.setComment(rs.getString("comment"));
         }
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 5
0
 @Override
 public void commentForTables(Table table, Connection connection) {
   try {
     String sql = "select table_name,comments from user_tab_comments  where table_name=?";
     pstmt = connection.prepareStatement(sql);
     rs = pstmt.executeQuery();
     table.setComment(table.getName());
     while (rs.next()) {
       if (table.getName().equals(rs.getString("table_name"))) {
         String comment = rs.getString("comments");
         if (StringKit.notBlank(comment)) {
           table.setComment(comment);
         }
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 6
0
 @Override
 public void commentForColumns(Table table, Connection connection) {
   try {
     String sql = "show full columns from" + " " + table.getName();
     pstmt = connection.prepareStatement(sql);
     rs = pstmt.executeQuery();
     Map<String, String> val = new HashMap<String, String>();
     while (rs.next()) {
       val.put(rs.getString("Field"), rs.getString("COMMENT"));
     }
     List<Column> columns = table.getColumns();
     for (Column column : columns) {
       column.setComment(column.getName());
       String comment = val.get(column.getName());
       if (StringKit.notBlank(comment)) {
         column.setComment(comment);
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 7
0
 @Override
 public void commentForColumns(Table table, Connection connection) {
   try {
     String sql = "select * from user_col_comments where TABLE_NAME = ?";
     pstmt = connection.prepareStatement(sql);
     pstmt.setString(1, table.getName());
     rs = pstmt.executeQuery();
     List<Column> columns = table.getColumns();
     for (Column column : columns) {
       column.setComment(column.getName());
       while (rs.next()) {
         if (column.getName().equals(rs.getString("COLUMN_NAME"))) {
           String comment = rs.getString("COMMENTS");
           if (StringKit.notBlank(comment)) {
             column.setComment(comment);
             continue;
           }
         }
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Esempio n. 8
0
 public static void setTimeFromat(String timeFormat) {
   if (StringKit.isBlank(timeFormat))
     throw new IllegalArgumentException("timeFormat can not be blank.");
   DateKit.timeFormat = timeFormat;
 }
Esempio n. 9
0
 public static void setDateFromat(String dateFormat) {
   if (StringKit.isBlank(dateFormat))
     throw new IllegalArgumentException("dateFormat can not be blank.");
   DateKit.dateFormat = dateFormat;
 }
Esempio n. 10
0
 public ContextPathHandler(String contextPathName) {
   if (StringKit.isBlank(contextPathName))
     throw new IllegalArgumentException("contextPathName can not be blank.");
   this.contextPathName = contextPathName;
 }
Esempio n. 11
0
 public Controller keepModelWithGroup(String group, Class modelClass) {
   String modelName = StringKit.firstCharToLowerCase(modelClass.getSimpleName());
   keepModelWithGroup(group, modelClass, modelName);
   return this;
 }
Esempio n. 12
0
/** 感谢对开源热心的少年们提供的各种代码,这个DD是站在巨人的肩膀上的 感谢 @波总 的JFinal,@闲.大赋 的beetl,向你们致敬! :) */
public class Myconfig extends JFinalConfig {
  private String json = java.lang.System.getenv("VCAP_SERVICES");
  private boolean isLocal = StringKit.isBlank(json);
  /** 配置常量 */
  public void configConstant(Constants me) {
    loadPropertyFile("classes/config.txt");
    if (isLocal) {
      me.setDevMode(true);
    }
    me.setError404View("/common/404.html");
    me.setError500View("/common/500.html");
    me.setMainRenderFactory(new BeetlRenderFactory());
    GroupTemplate gt = BeetlRenderFactory.groupTemplate;
    gt.setStatementStart("@");
    gt.setStatementEnd(null);
  }

  /** 配置路由 */
  public void configRoute(Routes me) {
    me.add("/", IndexController.class).add("/topic", TopicController.class);
    me.add("/post", PostController.class).add("/reply", ReplyController.class);
    me.add("/admin/welcome", WelcomeController.class).add("/admin/module", ModuleController.class);
  }

  /** 配置插件 */
  public void configPlugin(Plugins me) {
    // [ copy from @ mike 的适配器 :) ]
    String dbname, username, password, host, port, driver;
    driver = getProperty("driverClass");
    if (isLocal) {
      dbname = getProperty("dbname");
      username = getProperty("username");
      port = getProperty("port");
      host = getProperty("host");
      password = getProperty("password");
    } else {
      JSONObject credentials =
          JSONObject.parseObject(json)
              .getJSONArray("mysql-5.1")
              .getJSONObject(0)
              .getJSONObject("credentials");
      host = credentials.getString("host");
      port = credentials.getString("port");
      dbname = credentials.getString("name");
      username = credentials.getString("username");
      password = credentials.getString("password");
    }
    DruidPlugin druidPlugin =
        new DruidPlugin(
            "jdbc:mysql://" + host + ":" + port + "/" + dbname, username, password, driver);
    druidPlugin.setInitialSize(3).setMaxActive(10);
    me.add(druidPlugin);
    // 配置ActiveRecord插件
    ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
    if (isLocal) {
      arp.setShowSql(true);
    }
    arp.addMapping("module", Module.class)
        .addMapping("topic", Topic.class)
        .addMapping("post", Post.class);
    arp.addMapping("reply", Reply.class).addMapping("sub_module", SubModule.class);
    me.add(arp);
    // 缓存插件
    me.add(new EhCachePlugin());
  }

  /** 配置全局拦截器 */
  public void configInterceptor(Interceptors me) {
    // 支持在jfinal中用sesion
    me.add(new SessionInViewInterceptor());
    me.add(new GlobalInterceptor());
  }

  /** 配置处理器 */
  public void configHandler(Handlers me) {}

  /** 初始化常量 */
  public void afterJFinalStart() {
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
    MyConstants.PAGE_SIZE = getPropertyToInt("page_size", 10);
    MyConstants.PAGE_SIZE_OF_REPLY = getPropertyToInt("page_size_of_reply", 3);
    MyConstants.MODULE_LIST = Module.dao.getModuleList();
    MyConstants.TOPIC_CONTENT_PREVIEW_SIZE = getPropertyToInt("topic_preview_size", 280);
    MyConstants.ADMIN_NAME = getProperty("admin_name");
    MyConstants.ADMIN_PASSWORD = getProperty("admin_password");
    MyConstants.SIDEBAR_TOPIC_SIZE = getPropertyToInt("sidebar_topic_size", 6);
    MyConstants.PAGE_SIZE_FOR_ADMIN = getPropertyToInt("page_size_for_admin", 30);
  }

  /** 建议使用 JFinal 手册推荐的方式启动项目 运行此 main 方法可以启动项目,此main方法可以放置在任意的Class类定义中,不一定要放于此 */
  public static void main(String[] args) throws Exception {
    JFinal.start("Web", 80, "/", 5);
  }
}