コード例 #1
0
ファイル: DB2PlugIn.java プロジェクト: BhavinGitHub/wonder
  /**
   * This is usually extracted from the the database using JDBC, but this is really inconvenient for
   * users who are trying to generate SQL at some. A specific version of the data has been written
   * into the property list of the framework and this can be used as a hard-coded equivalent.
   */
  public NSDictionary jdbcInfo() {
    // you can swap this code out to write the property list out in order
    // to get a fresh copy of the JDBCInfo.plist.
    //    try {
    //      String jdbcInfoS = NSPropertyListSerialization.stringFromPropertyList(super.jdbcInfo());
    //      FileOutputStream fos = new FileOutputStream("/tmp/JDBCInfo.plist");
    //      fos.write(jdbcInfoS.getBytes());
    //      fos.close();
    //    }
    //    catch(Exception e) {
    //      throw new IllegalStateException("problem writing JDBCInfo.plist",e);
    //    }

    NSDictionary jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      } finally {
        try {
          jdbcInfoStream.close();
        } catch (IOException e) {
        }
      }
    } else {
      jdbcInfo = super.jdbcInfo();
    }
    return jdbcInfo;
  }
コード例 #2
0
ファイル: _MySQLPlugIn.java プロジェクト: pgrbnsn/wonder
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public NSDictionary<String, Object> jdbcInfo() {

    NSDictionary<String, Object> jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary<String, Object>)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      }

    } else {

      NSMutableDictionary<String, Object> mutableInfo = super.jdbcInfo().mutableClone();
      NSMutableDictionary<String, NSDictionary> typeInfo =
          ((NSDictionary<String, NSDictionary>) mutableInfo.objectForKey("typeInfo"))
              .mutableClone();
      NSDictionary textTypeInfo = typeInfo.objectForKey("TEXT");
      if (textTypeInfo != null) {
        Object rawCreateParams = textTypeInfo.objectForKey("createParams");
        if (!rawCreateParams.equals("1")) {
          NSMutableDictionary newRawTypeInfo = textTypeInfo.mutableClone();
          newRawTypeInfo.setObjectForKey("1", "createParams");
          typeInfo.setObjectForKey(newRawTypeInfo, "RAW");
        }
      }
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "BLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "LONGBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "MEDIUMBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "TINYBLOB", "createParams");
      mutableInfo.setObjectForKey(typeInfo, "typeInfo");

      NSLog.debug.appendln(
          new StringBuilder("fetched MySQL (")
              .append(databaseProductName())
              .append(") JDBC Info = ")
              .append(mutableInfo)
              .toString());

      // Write a fresh copy of JDBCInfo.plist to /tmp
      // writeJDBCInfo(mutableInfo);

      jdbcInfo = mutableInfo.immutableClone();
    }
    return jdbcInfo;
  }