예제 #1
0
  private void readProperties(Properties info) {
    Object[] list = new Object[info.size()];
    info.keySet().toArray(list);
    DbSettings s = null;

    // 可在info中配三种参数,相关文档见:E:\H2\my-h2\my-h2-docs\999 可配置的参数汇总.java中的1、2、3项
    for (Object k : list) {
      String key = StringUtils.toUpperEnglish(k.toString());
      if (prop.containsKey(key)) {
        throw DbException.get(ErrorCode.DUPLICATE_PROPERTY_1, key);
      }
      Object value = info.get(k);
      // 支持org.h2.command.dml.SetTypes中的参数和ConnectionInfo与connectionTime相关的参数
      if (isKnownSetting(key)) {
        prop.put(key, value);
      } else {
        if (s == null) {
          s = getDbSettings();
        }
        // org.h2.constant.DbSettings中的参数
        if (s.containsKey(key)) {
          prop.put(key, value);
        }
      }
    }
  }
예제 #2
0
 private void readSettingsFromURL() {
   // 如url=jdbc:h2:tcp://localhost:9092/test9;optimize_distinct=true;early_filter=true;nested_joins=false
   DbSettings defaultSettings = DbSettings.getDefaultSettings();
   int idx = url.indexOf(';'); // 用";"号来分隔参数,第一个";"号表明url和参数的分界,之后的";"号用来分隔多个参数
   if (idx >= 0) {
     // optimize_distinct=true;early_filter=true;nested_joins=false
     String settings = url.substring(idx + 1);
     // jdbc:h2:tcp://localhost:9092/test9
     url = url.substring(0, idx);
     // [optimize_distinct=true, early_filter=true, nested_joins=false]
     String[] list = StringUtils.arraySplit(settings, ';', false);
     for (String setting : list) {
       if (setting.length() == 0) {
         continue;
       }
       int equal = setting.indexOf('=');
       if (equal < 0) {
         throw getFormatException();
       }
       String value = setting.substring(equal + 1);
       String key = setting.substring(0, equal);
       key = StringUtils.toUpperEnglish(key);
       // info中除了可以配三种参数外(相关文档见:E:\H2\my-h2\my-h2-docs\999 可配置的参数汇总.java中的1、2、3项)
       // 还可以配其他参数,但是被忽略
       // 但是url中只能配三种参数
       if (!isKnownSetting(key) && !defaultSettings.containsKey(key)) {
         throw DbException.get(ErrorCode.UNSUPPORTED_SETTING_1, key);
       }
       // 不能与info中的参数重复(如果值相同就不会报错)
       // 例子见my.test.ConnectionInfoTest
       String old = prop.getProperty(key);
       if (old != null && !old.equals(value)) {
         throw DbException.get(ErrorCode.DUPLICATE_PROPERTY_1, key);
       }
       prop.setProperty(key, value);
     }
   }
 }
예제 #3
0
 /**
  * Overwrite the user name. The user name is case-insensitive and stored in uppercase. English
  * conversion is used.
  *
  * @param name the user name
  */
 public void setUserName(String name) {
   this.user = StringUtils.toUpperEnglish(name);
 }