예제 #1
0
  /**
   * This method parses the URL and adds properties to the the properties object. These include
   * required and any optional properties specified in the URL.
   *
   * @param The URL needed to be parsed.
   * @param The properties object which is to be updated with properties in the URL.
   * @throws SQLException if the URL is not in the expected format.
   */
  protected static void parseURL(String url, Properties info) throws SQLException {
    if (url == null) {
      String msg = Messages.getString(Messages.JDBC.urlFormat);
      throw new SQLException(msg);
    }
    try {
      JDBCURL jdbcURL = new JDBCURL(url);
      info.setProperty(TeiidURL.JDBC.VDB_NAME, jdbcURL.getVDBName());
      if (jdbcURL.getConnectionURL() != null) {
        info.setProperty(TeiidURL.CONNECTION.SERVER_URL, jdbcURL.getConnectionURL());
      }
      Properties optionalParams = jdbcURL.getProperties();
      JDBCURL.normalizeProperties(info);
      Enumeration<?> keys = optionalParams.keys();
      while (keys.hasMoreElements()) {
        String propName = (String) keys.nextElement();
        // Don't let the URL properties override the passed-in Properties object.
        if (!info.containsKey(propName)) {
          info.setProperty(propName, optionalParams.getProperty(propName));
        }
      }
      // add the property only if it is new because they could have
      // already been specified either through url or otherwise.
      if (!info.containsKey(TeiidURL.JDBC.VDB_VERSION) && jdbcURL.getVDBVersion() != null) {
        info.setProperty(TeiidURL.JDBC.VDB_VERSION, jdbcURL.getVDBVersion());
      }
      if (!info.containsKey(TeiidURL.CONNECTION.APP_NAME)) {
        info.setProperty(TeiidURL.CONNECTION.APP_NAME, TeiidURL.CONNECTION.DEFAULT_APP_NAME);
      }

    } catch (IllegalArgumentException iae) {
      throw new SQLException(Messages.getString(Messages.JDBC.urlFormat));
    }
  }
예제 #2
0
 static final <T> T transform(
     TeiidVersion teiidVersion, Object value, Class<T> targetType, Class<?> runtimeType)
     throws SQLException {
   if (value == null || targetType.isAssignableFrom(value.getClass())) {
     return targetType.cast(value);
   }
   if (targetType == byte[].class) {
     if (value instanceof Blob) {
       Blob blob = (Blob) value;
       long length = blob.length();
       if (length > Integer.MAX_VALUE) {
         throw new SQLException(
             Messages.getString(Messages.JDBC.DataTypeTransformer_blob_too_big));
       }
       return targetType.cast(blob.getBytes(1, (int) length));
     } else if (value instanceof String) {
       return targetType.cast(((String) value).getBytes());
     } else if (value instanceof BinaryTypeImpl) {
       return targetType.cast(((BinaryTypeImpl) value).getBytesDirect());
     }
   } else if (targetType == String.class) {
     if (value instanceof SQLXML) {
       return targetType.cast(((SQLXML) value).getString());
     } else if (value instanceof Clob) {
       Clob c = (Clob) value;
       long length = c.length();
       if (length == 0) {
         // there is a bug in SerialClob with 0 length
         return targetType.cast(""); // $NON-NLS-1$
       }
       return targetType.cast(
           c.getSubString(1, length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length));
     }
   }
   try {
     DefaultDataTypeManager dataTypeManager = getDataTypeManager(teiidVersion);
     return (T)
         dataTypeManager.transformValue(
             dataTypeManager.convertToRuntimeType(value, true), runtimeType);
   } catch (Exception e) {
     String valueStr = value.toString();
     if (valueStr.length() > 20) {
       valueStr = valueStr.substring(0, 20) + "..."; // $NON-NLS-1$
     }
     String msg =
         Messages.getString(
             Messages.JDBC.DataTypeTransformer_Err_converting,
             valueStr,
             targetType.getSimpleName());
     throw new SQLException(msg, e);
   }
 }
예제 #3
0
  @Override
  public ConnectionImpl connect(String url, Properties info) throws SQLException {
    ConnectionType conn = JDBCURL.acceptsUrl(url);
    if (conn == null) {
      return null;
    }
    if (info == null) {
      // create a properties obj if it is null
      info = new Properties();
    } else {
      // don't modify the original
      info = PropertiesUtils.clone(info);
    }
    parseURL(url, info);

    ConnectionImpl myConnection = null;

    /*
     * Add the teiid server version to the properties
     */
    info.setProperty(ITeiidServerVersion.TEIID_VERSION_PROPERTY, getTeiidVersion().toString());

    try {
      myConnection = socketProfile.connect(url, info);
    } catch (SQLException e) {
      logger.log(Level.SEVERE, "Could not create connection", e); // $NON-NLS-1$
      throw e;
    }

    // logging
    String logMsg = Messages.getString(Messages.JDBC.Connection_success);
    logger.fine(logMsg);

    return myConnection;
  }
예제 #4
0
 static {
   try {
     DriverManager.registerDriver(INSTANCE);
   } catch (SQLException e) {
     // Logging
     String logMsg = Messages.getString(Messages.JDBC.Err_registering, e.getMessage());
     logger.log(Level.SEVERE, logMsg);
   }
 }
예제 #5
0
 @Override
 public void setMetadataID(Object metadataID) {
   if (metadataID == null) {
     throw new IllegalArgumentException(Messages.getString(Messages.ERR.ERR_015_010_0016));
   }
   if (this.isImplicitTempGroupSymbol()) {
     this.isTempTable = true;
   }
   this.metadataID = metadataID;
 }