<commit_before>/*
 * Copyright 2005 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Locale;
import java.util.HashSet;
import java.util.Stack;

import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAResource;

import org.efaps.admin.datamodel.Type;
import org.efaps.admin.user.Person;
import org.efaps.db.databases.AbstractDatabase;
import org.efaps.db.databases.DerbyDatabase;
import org.efaps.db.databases.OracleDatabase;
import org.efaps.db.transaction.ConnectionResource;
import org.efaps.db.transaction.JDBCStoreResource;
import org.efaps.db.transaction.StoreResource;
import org.efaps.db.transaction.VFSStoreResource;
import org.efaps.util.EFapsException;

/**
 *
 */
public class Context {

  /**
   *  Enum storing which dbtype is used.
   */
  public static enum DbType {
    Unknown, Derby, Oracle
  };

  /**
   * Static variable storing the database type.
   */
  private static DbType dbType = DbType.Unknown;

  /**
   * Static variable used to store the database name of the context.
   */
  private static String dbUser = null;

  /**
   * Each thread has his own context object. The value is automatically
   * assigned from the filter class.
   */
  private static ThreadLocal<Context>threadContext = new ThreadLocal<Context>();

  public static void setDbType(DbType _dbType) throws ClassNotFoundException, IllegalAccessException {
System.out.println("---------------- DBType = "+_dbType);
    dbType = _dbType;
    if (dbType == DbType.Derby)  {
      database = new DerbyDatabase();
    } else if (dbType == DbType.Oracle)  {
      database = new OracleDatabase();
    }
  }

  /**
   * Returns the database type of the default connection (database where the
   * data model definition is stored).
   *
   * @see #dbType
   */
  public static DbType getDbType()  {
    return dbType;
  }

  private static AbstractDatabase database = null;

  public static AbstractDatabase getDatabase()  {
    return database;
  }


  /**
   *
   */
  public static void setDbUser(final String _dbUser)  {
    dbUser = _dbUser;
  }

  public static String getDbUser()  {
    return dbUser;<commit_msg>- removed hard coded strings for different database vendors - now a class with all vendor specfic information is used<commit_after>/*
 * Copyright 2005 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Locale;
import java.util.HashSet;
import java.util.Stack;

import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAResource;

import org.efaps.admin.datamodel.Type;
import org.efaps.admin.user.Person;
import org.efaps.db.databases.AbstractDatabase;
import org.efaps.db.transaction.ConnectionResource;
import org.efaps.db.transaction.JDBCStoreResource;
import org.efaps.db.transaction.StoreResource;
import org.efaps.db.transaction.VFSStoreResource;
import org.efaps.util.EFapsException;

/**
 *
 */
public class Context {

  /**
   * Static variable storing the database type.
   */
  private static AbstractDatabase dbType = null;

  /**
   * Each thread has his own context object. The value is automatically
   * assigned from the filter class.
   */
  private static ThreadLocal<Context>threadContext = new ThreadLocal<Context>();

  public static void setDbType(AbstractDatabase _dbType) throws ClassNotFoundException, IllegalAccessException {
System.out.println("---------------- DBType = "+_dbType);
    dbType = _dbType;
  }

  /**
   * Returns the database type of the default connection (database where the
   * data model definition is stored).
   *
   * @see #dbType
   */
  public static AbstractDatabase getDbType()  {
    return dbType;
{'fraction_non_alphanumeric': 0.0947940947940948, 'fraction_numerical': 0.003108003108003108, 'mean_word_length': 3.789767441860465, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5146152', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1421, 'n_words': 480}