Ejemplo n.º 1
0
  /**
   * Determines if the DB connection described by the given <code>ISQLEditorConnectionInfo</code> is
   * actively connected
   *
   * @param connInfo the <code>ISQLEditorConnectionInfo</code> to check
   * @return true if the connection is active, otherwise false
   */
  public static boolean isConnected(ISQLEditorConnectionInfo connInfo) {
    boolean connected = false;

    if (connInfo != null && connInfo.getDatabase() != null) {
      connected = true;
    }
    return connected;
  }
Ejemplo n.º 2
0
  /**
   * Determines if the given <code>ISQLEditorConnectionInfo</code> is references the default user
   * ID. This is done by checking if both the user ID and password are empty and non-null.
   *
   * @param connInfo the <code>ISQLEditorConnectionInfo</code> object to check
   * @return true if the default user ID is being used, otherwise false
   */
  public static boolean isDefaultUser(ISQLEditorConnectionInfo connInfo) {

    String username = null;
    String password = null;

    if (connInfo != null) {
      username = ProfileUtil.getUserName(connInfo.getConnectionProfile());
      password = ProfileUtil.getPassword(connInfo.getConnectionProfile());
    }

    return (username != null
        && username.length() == 0
        && password != null
        && password.length() == 0);
  }
Ejemplo n.º 3
0
  /**
   * Determines if a user ID and password prompt is needed for the given <code>
   * ISQLEditorConnectionInfo</code> object. This is done by checking if either the user ID or
   * password is null or empty.
   *
   * @param connInfo the <code>ISQLEditorConnectionInfo</code> to check
   * @param true when userid/password prompt is needed, otherwise false
   */
  public static boolean isPromptNeeded(ISQLEditorConnectionInfo connInfo) {

    String username = null;
    String password = null;

    if (connInfo != null) {
      username = ProfileUtil.getUserName(connInfo.getConnectionProfile());
      password = ProfileUtil.getPassword(connInfo.getConnectionProfile());
    }

    return (((username == null
            || username.length() == 0
            || password == null
            || password.length() == 0))
        && !isDefaultUser(connInfo));
  }
Ejemplo n.º 4
0
  public static String getDefaultSchemaName(ISQLEditorConnectionInfo connInfo) {
    DatabaseIdentifier dbid = new DatabaseIdentifier(connInfo.getConnectionProfileName());
    String defaultSchemaName = ProfileUtil.getProfileUserName(dbid, false);

    return defaultSchemaName;
  }
  private void doSaveFileResource(
      IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException {
    IDocument storageDocument = null;
    String statementSQL = document.get();
    if (statementSQL == null) statementSQL = "";

    String encodedConnection = null;
    IFile fileResource = null;
    SQLEditor sqlEditor = null;

    if (encodedConnection == null) {
      // get encodedConnection from SQLEditor
      IEditorPart editor =
          PlatformUI.getWorkbench()
              .getActiveWorkbenchWindow()
              .getActivePage()
              .findEditor((IEditorInput) element);
      if ((editor != null) && (editor instanceof SQLEditor)) {
        sqlEditor = (SQLEditor) editor;
        ISQLEditorConnectionInfo connectionInfo = sqlEditor.getConnectionInfo();
        if (connectionInfo != null) encodedConnection = connectionInfo.encode();
      }
    }

    if (element instanceof IFileEditorInput) fileResource = ((IFileEditorInput) element).getFile();

    if (((encodedConnection == null) && element instanceof SQLScrapbookEditorInput)) {
      // get encodedConnection from SQLScrapbookEditorInput
      ISQLEditorConnectionInfo connectionInfo =
          ((SQLScrapbookEditorInput) element).getConnectionInfo();
      if (connectionInfo != null) encodedConnection = connectionInfo.encode();
    }

    if ((encodedConnection == null)
        && (fileResource != null)
        && !"sqlpage".equalsIgnoreCase(fileResource.getFileExtension())) {
      // get encodedConnection from PersistentProperty
      if (fileResource.exists()) {
        encodedConnection = SQLFileUtil.getEncodedConnectionInfo(fileResource);
      }
    }

    if (encodedConnection == null) encodedConnection = "";

    if ((fileResource != null) && "sqlpage".equalsIgnoreCase(fileResource.getFileExtension())) {
      // Do xml document (*.sqlpage file) with only encodedConnection and statementSQL
      Map map = new HashMap();
      map.put("encodedConnection", encodedConnection);

      String pageXML = SQLUtility.getOutputSQLPageXML(statementSQL, map);
      storageDocument = new Document(pageXML);
    }

    if ((encodedConnection != null)
        && (fileResource != null)
        && !"sqlpage".equalsIgnoreCase(fileResource.getFileExtension())) {
      // Save PersistentProperty encodedConnection for not *.sqlpage
      SQLFileUtil.setEncodedConnectionInfo(fileResource, encodedConnection);
    }

    if (storageDocument == null) storageDocument = document;

    super.doSaveDocument(monitor, element, storageDocument, overwrite);
  }