/**
   * Create table in database. <br>
   *
   * @throws ProvMonitorException If table could not be created. <br>
   * @throws DatabaseException <code>Database related problems.</code><br>
   *     <ul>
   *       <li>ConnectionException - Connection problems related.
   *       <li>DatabaseException - Problems with the table creation itself.
   *     </ul>
   */
  @Override
  public void createTable() throws ProvMonitorException {
    Connection conn = ConnectionManager.getInstance().getConnection();
    Statement s = null;
    try {
      try {
        // Preparing statement
        s = conn.createStatement();
        // Transaction control
        conn.setAutoCommit(false);

      } catch (SQLException e) {
        throw new ConnectionException(e.getMessage(), e.getCause(), e.getSQLState());
      }
      if (s != null) {
        String createTableSQL =
            "CREATE TABLE PROCESS_INSTANCE (INSTANCE_ID VARCHAR(255) NOT NULL"
                + ", PROCESS_ID VARCHAR(255) NOT NULL"
                + ", NAME VARCHAR(255)"
                + ", SWFMS_ID INT"
                + ")";

        s.executeUpdate(createTableSQL);
        conn.commit();
      }
    } catch (SQLException e) {
      try {
        conn.rollback();
      } catch (SQLException ex) {
      }
      throw new DatabaseException(e.getMessage(), e.getCause());
    }
  }
  /**
   * Verify table existence in database. <br>
   *
   * @return <code><b>true</b></code> - If table exists. <br>
   *     <code><b>false</b></code> - If table does not exist.
   * @throws ProvMonitorException If table could not be created. <br>
   */
  @Override
  public boolean isTableCreated() throws ProvMonitorException {
    Connection conn = ConnectionManager.getInstance().getConnection();
    try {

      try {
        // Transaction control
        conn.setAutoCommit(false);
      } catch (SQLException e) {
        throw new ConnectionException(e.getMessage(), e.getCause(), e.getSQLState());
      }

      // Verifying schema
      PreparedStatement psInsert =
          conn.prepareStatement(
              "INSERT INTO PROCESS_INSTANCE (INSTANCE_ID, PROCESS_ID) values (?,?)");
      psInsert.setString(1, "TesteParam1");
      psInsert.setString(2, "TesteParam2");
      psInsert.executeUpdate();
      conn.rollback();

      return true;

    } catch (SQLException e) {
      // Schema object does not exist
      try {
        conn.rollback();
      } catch (SQLException ex) {
      }
      return false;
    }
  }