gt:         DatabaseLogin login = new DatabaseLogin();
context: /*******************************************************************************
   * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
   * This program and the accompanying materials are made available under the 
   * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
   * which accompanies this distribution. 
   * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
   * and the Eclipse Distribution License is available at 
   * http://www.eclipse.org/org/documents/edl-v10.php.
   *
   * Contributors:
   *     Oracle - initial API and implementation from Oracle TopLink
   ******************************************************************************/  
  package org.eclipse.persistence.testing.framework;
  
  import java.util.*;
  
  import org.eclipse.persistence.config.PersistenceUnitProperties;
  import org.eclipse.persistence.exceptions.*;
  import org.eclipse.persistence.logging.AbstractSessionLog;
  import org.eclipse.persistence.platform.database.TimesTenPlatform;
  import org.eclipse.persistence.sessions.DatabaseLogin;
  import org.eclipse.persistence.sessions.DatabaseSession;
  import org.eclipse.persistence.platform.database.DatabasePlatform;
  import org.eclipse.persistence.sessions.Project;
  import org.eclipse.persistence.sessions.Session;
  import org.eclipse.persistence.testing.framework.junit.JUnitTestCaseHelper;
  import org.eclipse.persistence.tools.schemaframework.*;
  
  /**
   * Used in a test model to configure the database and session.
   * This class also store every database login that we use.
   */
  public class TestSystem {
      protected DatabaseLogin login;
      public Project project;
      
      public Map<String, String> properties;
  
      /**
       * Add all of the descriptors.
       */
      public void addDescriptors(DatabaseSession session) {
          session.addDescriptors(buildDescriptors());
      }
          
      /**
       * Return all descriptor for the system.
       * This can be used so that subclasses do not have to add descriptors themselves.
       */
      public Vector buildDescriptors() {
          return new Vector();
      }
      
      /**
       * Return all tables for the system.
       * This can be used so that subclasses do not have to create the tables themselves.
       */
      public Vector buildTables() {
          return new Vector();
      }
  
      /**
       * Define the table creation pattern.
       */
      public void createTables() throws Exception {
          DatabaseSession session;
  
          session = login();
          try {
              createTables(session);
          } finally {
              session.logout();
          }
      }
  
      /**
       * Default method to create/recreate the database.
       * First drop constraints ignoring errors if tables did not exist.
       * Second recreate the tables.
       * Then add the constraints back.
       */
      public void createTables(DatabaseSession session) throws Exception {
          Vector tables = buildTables();
          SchemaManager schemaManager = new SchemaManager(session);
          for (Enumeration dropForeignKeyEnum = tables.elements();
                   dropForeignKeyEnum.hasMoreElements();) {
              TableDefinition table = (TableDefinition)dropForeignKeyEnum.nextElement();
              try {
                  schemaManager.dropConstraints(table);
              } catch (DatabaseException exception) {
                  // Ignore
              }
          }
          for (Enumeration replaceEnum = tables.elements(); replaceEnum.hasMoreElements();) {
              TableDefinition table = (TableDefinition)replaceEnum.nextElement();
              schemaManager.replaceObject(table);
          }
          for (Enumeration createForeignKeyEnum = tables.elements();
                   createForeignKeyEnum.hasMoreElements();) {
              TableDefinition table = (TableDefinition)createForeignKeyEnum.nextElement();
              schemaManager.createConstraints(table);
          }
      }
  
      /**
       * Return the default database login to be used.
       */
      public DatabaseLogin getLogin() {
          if (login == null) {
              loadLoginFromProperties();
          }
          return login;
      }
  
      /**
       * Load the default login from the test.properties file.
       * This file must be on the classpath, or system property set.
       */
      public void loadLoginFromProperties() {        
          this.properties = JUnitTestCaseHelper.getDatabaseProperties();
          login = new DatabaseLogin();
          login.setDriverClassName(this.properties.get(PersistenceUnitProperties.JDBC_DRIVER));
          login.setConnectionString(this.properties.get(PersistenceUnitProperties.JDBC_URL));
          login.setUserName(this.properties.get(PersistenceUnitProperties.JDBC_USER));
          // This avoids encrypting the password, as some tests require it non-encrypted.
          login.setEncryptedPassword(this.properties.get(PersistenceUnitProperties.JDBC_PASSWORD));
          String platform = this.properties.get("eclipselink.target-database");
          if (platform != null) {
              login.setPlatformClassName(platform);
          }
      }
  
      /**
       * Return a connected session using the default login.
       */
      public DatabaseSession login() {
          DatabaseSession session;
  
          session = new Project(getLogin()).createDatabaseSession();
          addDescriptors(session);
          session.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(properties.get(PersistenceUnitProperties.LOGGING_LEVEL)));
          session.login();
  
          return session;
      }
  
      /**
       * Define the database population pattern.
       */
      public void populate() throws Exception {
          DatabaseSession session;
  
          session = login();
          try {
              populate(session);
          } finally {
              session.logout();
          }
      }
  
      /**
       * Abstract method for database population.
       */
      public void populate(DatabaseSession session) throws Exception {
          // Nothing by default.
      }
  
      /**
       * Used for configuration during testing.
       */
      public void run(Session session) throws Exception {
          // Use old API to be able to run on 9.0.4 for perf testing.
          session.getIdentityMapAccessor().initializeIdentityMaps();
          this.addDescriptors((DatabaseSession)session);
          if (session.getDatasourceLogin().getDatasourcePlatform().isTimesTen()) {
              ((TimesTenPlatform)session.getDatasourceLogin().getDatasourcePlatform()).setSupportsForeignKeyConstraints(false);
          }
          this.createTables((DatabaseSession)session);
          this.populate((DatabaseSession)session);
          // Use old API to be able to run on 9.0.4 for perf testing.
          session.getIdentityMapAccessor().initializeIdentityMaps();
      }
  
      /**
       * Set the default database login to be used.
       */
      public void setLogin(DatabaseLogin login) {
          this.login = login;
      }
  
      /**
       * You must have MS Access installed an the MS ODBC setup to a local database.
       */
      public void useAccessJDBCODBC() {
          DatabaseLogin login = new DatabaseLogin();
          login.useAccess();
          login.setODBCDataSourceName("MSACCESS");
          setLogin(login);
      }
  
      /**
       * You must have the Attunity Connect driver loaded.
       */
      public void useAttunityConnect() {
          DatabaseLogin login = new DatabaseLogin(new org.eclipse.persistence.platform.database.AttunityPlatform());
          login.setDatabaseURL("mercury2;deftdpname=oracle");
          login.setDriverClassName("com.attunity.jdbc.NvDriver");
          login.setDriverURLHeader("jdbc:attconnect://");
          setLogin(login);
      }
  
      /**
       * You must have the Derby driver loaded.
       */
      public void useDerby() {
          DatabaseLogin login = new DatabaseLogin(new org.eclipse.persistence.platform.database.DerbyPlatform());
          login.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
          login.setDriverURLHeader("jdbc:derby:");
          login.setDatabaseURL("test;create=true");
          setLogin(login);
      }
  
      /**
       * You must have the H2 driver loaded.
       */
      public void useH2() {
          DatabaseLogin login = new DatabaseLogin(new org.eclipse.persistence.platform.database.H2Platform());
          login.setDriverClassName("org.h2.Driver");
          login.setDriverURLHeader("jdbc:h2:");
          login.setDatabaseURL("test");
          login.setUserName("sa");
          login.setPassword("");
          setLogin(login);
      }
  
      /**
       * You must have the Postgres driver loaded.
       */
      public void usePostgres() {
          DatabaseLogin login = new DatabaseLogin(new org.eclipse.persistence.platform.database.PostgreSQLPlatform());
          login.setDriverClassName("org.postgresql.Driver");
          login.setDriverURLHeader("jdbc:postgresql:");
          login.setDatabaseURL("//ottvm048.ca.oracle.com/toplink");
          setLogin(login);
      }
  
      /**
       * You must have the Universal drivers and license files loaded.
       */
      public void useDB2UniversalDriver() {
          DatabaseLogin login = new DatabaseLogin();
          login.useDB2();
          login.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
          login.setDriverURLHeader("jdbc:db2://");
          login.setDatabaseURL("ottvm046.ca.oracle.com:50000/TOPLINK2");
          login.setUserName("");
          //set the encrypted password will enable toplink to use the plain text password as is
          login.setEncryptedPassword("password");
          setLogin(login);
      }
  
      /**
       * You must have the DataDirect drivers and oc4j.jar loaded.
       */
      public void useDB2DataDirect() {
  