public static Map getShareVars() {
   Map templateModel = new HashMap();
   templateModel.putAll(System.getProperties());
   templateModel.putAll(GeneratorProperties.getProperties());
   templateModel.put("env", System.getenv());
   templateModel.put("now", new Date());
   templateModel.put(
       GeneratorConstants.DATABASE_TYPE.code,
       GeneratorProperties.getDatabaseType(GeneratorConstants.DATABASE_TYPE.code));
   templateModel.putAll(GeneratorContext.getContext());
   templateModel.putAll(getToolsMap());
   return templateModel;
 }
 public Connection getConnection() {
   try {
     if (connection == null || connection.isClosed()) {
       loadJdbcDriver();
       connection =
           DriverManager.getConnection(
               GeneratorProperties.getRequiredProperty("jdbc.url"),
               GeneratorProperties.getRequiredProperty("jdbc.username"),
               GeneratorProperties.getProperty("jdbc.password"));
     }
     return connection;
   } catch (SQLException e) {
     throw new RuntimeException(e);
   }
 }
 private void loadJdbcDriver() {
   String driver = GeneratorProperties.getRequiredProperty("jdbc.driver");
   try {
     Class.forName(driver);
   } catch (ClassNotFoundException e) {
     throw new RuntimeException("not found jdbc driver class:[" + driver + "]", e);
   }
 }
  public void test() {
    //		GeneratorProperties.("badqiu_birth", new Date());
    GeneratorProperties.setProperty("badqiu_name", "com.badqiu");
    GeneratorModel gm = GeneratorModelUtils.newGeneratorModel("clazz", javaClass);
    assertEquals(gm.templateModel.get("badqiu_name_dir"), null);
    assertEquals(gm.templateModel.get("badqiu_name"), "com.badqiu");
    assertEquals(gm.templateModel.get("clazz"), javaClass);

    assertEquals(gm.filePathModel.get("badqiu_name_dir"), null);
    assertEquals(gm.filePathModel.get("badqiu_name"), "com.badqiu");

    assertEquals(gm.filePathModel.get("className"), javaClass.getClassName());
    assertEquals(GeneratorFacadeTest.class, gm.filePathModel.get("clazz"));
  }
Пример #5
0
 public static void debug(String string, Map templateModel) {
   if (logLevel <= DEBUG) {
     GLogger.println(string);
     if (templateModel == null) return;
     for (Object key : templateModel.keySet()) {
       if (System.getProperties().containsKey(key)
           || GeneratorProperties.getProperties().containsKey(key)) {
         continue;
       }
       if (key.toString().endsWith("_dir")) {
         continue;
       }
       GLogger.println(key + " = " + templateModel.get(key));
     }
   }
 }
 /** 得到模板可以引用的工具类 */
 private static Map getToolsMap() {
   Map toolsMap = new HashMap();
   String[] tools = GeneratorProperties.getStringArray(GENERATOR_TOOLS_CLASS);
   for (String className : tools) {
     try {
       Object instance = ClassHelper.newInstance(className);
       toolsMap.put(Class.forName(className).getSimpleName(), instance);
       GLogger.debug(
           "put tools class:"
               + className
               + " with key:"
               + Class.forName(className).getSimpleName());
     } catch (Exception e) {
       GLogger.error("cannot load tools by className:" + className + " cause:" + e);
     }
   }
   return toolsMap;
 }
 public GeneratorFacade() {
   if (StringHelper.isNotBlank(GeneratorProperties.getProperty("outRoot"))) {
     generator.setOutRootDir(GeneratorProperties.getProperty("outRoot"));
   }
 }
 public String getSchema() {
   return GeneratorProperties.getNullIfBlank("jdbc.schema");
 }
 public String getCatalog() {
   return GeneratorProperties.getNullIfBlank("jdbc.catalog");
 }