@Override
  public java.sql.Connection getConnection() throws java.sql.SQLException {
    java.sql.Connection connection = null;

    /*
     * The resource bundle for the DTO's subsystem contains the suffix that
     * distinguishes multiple versions of the subsystem in the database.properties
     * file, such as "prod" or "test". Most database.properties files have only
     * one implementation and use external facilities to switch between the
     * databases (JNDI, for example, or producing different database.properties
     * files in different setups). Use the subsystem resource bundle to get the
     * suffix, then use the full subsystem name to get a connection factory for
     * the DTO's subsystem, then use that factory to get a JDBC connection.
     */
    java.util.ResourceBundle rb =
        java.util.ResourceBundle.getBundle("org.phoenixbioinformatics.api.db.api");
    String subsystem =
        "org.phoenixbioinformatics.api.db.api"
            + (rb.getString("suffix") == null || rb.getString("suffix").length() == 0
                ? ""
                : "." + rb.getString("suffix"));

    try {
      connection =
          com.poesys.db.connection.ConnectionFactoryFactory.getInstance(subsystem).getConnection();
    } catch (com.poesys.db.InvalidParametersException e) {
      throw new java.sql.SQLException(e.getMessage());
    } catch (java.io.IOException e) {
      throw new java.sql.SQLException(e.getMessage());
    }

    return connection;
  }
  /**
   * Create a new AccessRule association class child of AccessType with an association key. This
   * class links the input objects.
   *
   * @param accessTypesObject associated AccessType object (part of the key)
   * @param partnerObject associated Partner object (part of the key)
   * @param uriPatternsObject associated UriPattern object (part of the key)
   * @param accessTypeId Attribute that is part of the association key
   * @param uriPatternId Attribute that is part of the association key
   * @param partnerId foreign key used as primary key in association class
   * @param partner
   * @return a new AccessRule business layer DTO
   * @throws DelegateException when a parameter causes a problem
   */
  public org.phoenixbioinformatics.api.bs.api.BsAccessRule createAccessRule(
      org.phoenixbioinformatics.api.bs.api.BsAccessType accessTypesObject,
      org.phoenixbioinformatics.api.bs.api.BsPartner partnerObject,
      org.phoenixbioinformatics.api.bs.api.BsUriPattern uriPatternsObject,
      java.math.BigInteger accessTypeId,
      java.math.BigInteger uriPatternId,
      java.lang.String partnerId,
      org.phoenixbioinformatics.api.db.api.IPartner partner)
      throws DelegateException {
    // Create the key.
    com.poesys.db.pk.AssociationPrimaryKey key = null;
    try {
      java.util.ArrayList<com.poesys.db.pk.IPrimaryKey> list =
          new java.util.ArrayList<com.poesys.db.pk.IPrimaryKey>();
      list.add(accessTypesObject.getPrimaryKey());
      list.add(partnerObject.getPrimaryKey());
      list.add(uriPatternsObject.getPrimaryKey());
      key =
          com.poesys.db.pk.PrimaryKeyFactory.createAssociationKey(
              list, "org.phoenixbioinformatics.api.db.api.AccessRule");
    } catch (com.poesys.db.InvalidParametersException e) {
      Object[] args = e.getParameters().toArray();
      String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
      throw new DelegateException(message, e);
    } catch (com.poesys.db.DuplicateKeyNameException e) {
      Object[] args = e.getParameters().toArray();
      String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
      throw new DelegateException(message, e);
    }

    // Create an association-key child data-access AccessRule DTO proxy (supports lazy loading).
    org.phoenixbioinformatics.api.db.api.IAccessRule dto =
        new org.phoenixbioinformatics.api.db.api.AccessRuleProxy(
            new org.phoenixbioinformatics.api.db.api.AccessRule(
                key,
                accessTypesObject.toDto(),
                partnerObject.toDto(),
                uriPatternsObject.toDto(),
                accessTypeId,
                uriPatternId,
                partnerId,
                partner));

    // Create the business DTO.
    return new org.phoenixbioinformatics.api.bs.api.BsAccessRule(dto);
  }
  /**
   * Create a new AccessType with data fields.
   *
   * <p>The AccessType class has a sequence key; this method generates the sequence for later
   * insertion into the database.
   *
   * @param accessTypeId primary key attribute
   * @param name the name of the access type
   * @return the new AccessType object
   * @throws DelegateException when there is a problem generating the key or creating the object
   */
  public org.phoenixbioinformatics.api.bs.api.BsAccessType createAccessType(
      java.math.BigInteger accessTypeId, java.lang.String name) throws DelegateException {
    com.poesys.db.pk.SequencePrimaryKey key = null;

    // Generate a new AccessType id if the input key is null.
    if (accessTypeId == null) {
      java.sql.Connection connection = null;
      try {
        connection = getConnection();
        if (connection == null) {
          throw new DelegateException("Could not get database connection to generate sequence");
        }

        if (dbms.equals(DBMS.MYSQL) || dbms.equals(DBMS.JNDI_MYSQL)) {
          key =
              com.poesys.db.pk.PrimaryKeyFactory.createMySqlSequenceKey(
                  connection,
                  "AccessType_SEQ",
                  "accessTypeId",
                  "org.phoenixbioinformatics.api.db.api.AccessType");
        } else if (dbms.equals(DBMS.ORACLE) || dbms.equals(DBMS.JNDI_ORACLE)) {
          // Create key with sequence AccessType_SEQ
          key =
              com.poesys.db.pk.PrimaryKeyFactory.createOracleSequenceKey(
                  connection,
                  "AccessType_SEQ",
                  "accessTypeId",
                  "org.phoenixbioinformatics.api.db.api.AccessType");
        } else {
          throw new DelegateException("com.poesys.bs.delegate.msg.noDbms");
        }
        // Get the sequence number for use as an attribute value.
        accessTypeId = key.getValue();
      } catch (com.poesys.db.InvalidParametersException e) {
        Object[] args = e.getParameters().toArray();
        String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
        throw new DelegateException(message, e);
      } catch (com.poesys.db.NoPrimaryKeyException e) {
        Object[] args = e.getParameters().toArray();
        String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
        throw new DelegateException(message, e);
      } catch (java.sql.SQLException e) {
        throw new DelegateException(e.getMessage(), e);
      } finally {
        // Done with this connection, close it and return it to the pool.
        if (connection != null) {
          try {
            connection.close();
          } catch (java.sql.SQLException e) {
            throw new DelegateException(e.getMessage(), e);
          }
        }
      }
    } else {
      key =
          com.poesys.db.pk.PrimaryKeyFactory.createSequenceKey(
              "accessTypeId", accessTypeId, "org.phoenixbioinformatics.api.db.api.AccessType");
    }

    // Create a data-access DTO proxy (supports lazy loading).
    org.phoenixbioinformatics.api.db.api.IAccessType dto =
        new org.phoenixbioinformatics.api.db.api.AccessTypeProxy(
            new org.phoenixbioinformatics.api.db.api.AccessType(key, accessTypeId, name));

    // Create the business DTO.
    return new org.phoenixbioinformatics.api.bs.api.BsAccessType(dto);
  }
示例#4
0
  /**
   * Create a new PageView with data fields.
   *
   * <p>The PageView class has a sequence key; this method generates the sequence for later
   * insertion into the database.
   *
   * @param pageViewId primary key attribute
   * @param pageViewDate the date and time of the page view request
   * @param uri the request URI and any query string
   * @param ip the IP address of the requests in the session; all page views in the session have
   *     this IP address
   * @param sessionId a token identifying a collection of page views as defined by the client
   *     processing the page views
   * @param partyId foreign key used by setter to query associated object
   * @return the new PageView object
   * @throws DelegateException when there is a problem generating the key or creating the object
   */
  public org.phoenixbioinformatics.api.bs.api.BsPageView createPageView(
      java.math.BigInteger pageViewId,
      java.sql.Timestamp pageViewDate,
      java.lang.String uri,
      java.lang.String ip,
      java.lang.String sessionId,
      java.math.BigInteger partyId)
      throws DelegateException {
    com.poesys.db.pk.SequencePrimaryKey key = null;

    // Generate a new PageView id if the input key is null.
    if (pageViewId == null) {
      java.sql.Connection connection = null;
      try {
        connection = getConnection();
        if (connection == null) {
          throw new DelegateException("Could not get database connection to generate sequence");
        }

        if (dbms.equals(DBMS.MYSQL) || dbms.equals(DBMS.JNDI_MYSQL)) {
          key =
              com.poesys.db.pk.PrimaryKeyFactory.createMySqlSequenceKey(
                  connection,
                  "PageView_SEQ",
                  "pageViewId",
                  "org.phoenixbioinformatics.api.db.api.PageView");
        } else if (dbms.equals(DBMS.ORACLE) || dbms.equals(DBMS.JNDI_ORACLE)) {
          // Create key with sequence PageView_SEQ
          key =
              com.poesys.db.pk.PrimaryKeyFactory.createOracleSequenceKey(
                  connection,
                  "PageView_SEQ",
                  "pageViewId",
                  "org.phoenixbioinformatics.api.db.api.PageView");
        } else {
          throw new DelegateException("com.poesys.bs.delegate.msg.noDbms");
        }
        // Get the sequence number for use as an attribute value.
        pageViewId = key.getValue();
      } catch (com.poesys.db.InvalidParametersException e) {
        Object[] args = e.getParameters().toArray();
        String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
        throw new DelegateException(message, e);
      } catch (com.poesys.db.NoPrimaryKeyException e) {
        Object[] args = e.getParameters().toArray();
        String message = com.poesys.db.Message.getMessage(e.getMessage(), args);
        throw new DelegateException(message, e);
      } catch (java.sql.SQLException e) {
        throw new DelegateException(e.getMessage(), e);
      } finally {
        // Done with this connection, close it and return it to the pool.
        if (connection != null) {
          try {
            connection.close();
          } catch (java.sql.SQLException e) {
            throw new DelegateException(e.getMessage(), e);
          }
        }
      }
    } else {
      key =
          com.poesys.db.pk.PrimaryKeyFactory.createSequenceKey(
              "pageViewId", pageViewId, "org.phoenixbioinformatics.api.db.api.PageView");
    }

    // Create a data-access DTO for direct access, no proxy required.
    org.phoenixbioinformatics.api.db.api.IPageView dto =
        new org.phoenixbioinformatics.api.db.api.PageView(
            key, pageViewId, pageViewDate, uri, ip, sessionId, partyId);

    // Create the business DTO.
    return new org.phoenixbioinformatics.api.bs.api.BsPageView(dto);
  }