TenantDatabaseDescriptor.java

/*
** Module   : TenantDatabaseDescriptor.java
** Abstract : Class that handles the databases access and connection settings for a tenant database instance.
**
** Copyright (c) 2024-2025, Golden Code Development Corporation.
**
** -#- -I- --Date-- ----------------------------------------Description---------------------------------------
** 001 RAA 20240702 Created initial version.
**     RAA 20240710 Added database field.
**     RAA 20240715 Clarified the type of database name occurrences.
**     RAA 20240726 Added logical name field. Added TenantDatabaseDescriptorKey sub-class.
**     RAA 20240726 Removed hash code computations from TenantDatabaseDescriptorKey.
**     RAA 20240807 Removed TenantDatabaseDescriptorKey sub-class.
** 002 OM  20250331 Added c3p0 connection parameters.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.persist.orm;

import com.goldencode.p2j.persist.Database;

/**
 * Class responsible with storing the settings of a database instance for a tenant.
 */
public class TenantDatabaseDescriptor
{
   /** The physical name of the database. */
   private String pdbName;
   
   /** The logical name of the database. */
   private String ldbName;
   
   /** The URL of the database. */
   private String url;
   
   /** The username of the database. */
   private String username;
   
   /** The password of the database. */
   private String password;
   
   /** The {@code c3p0.maxStatementsPerConnection} database connection parameter. */ 
   private Integer c3p0MaxStmts;
   
   /** The {@code c3p0.minPoolSize} database connection parameter. */ 
   private Integer c3p0MinPool;
   
   /** The {@code c3p0.maxPoolSize} database connection parameter. */ 
   private Integer c3p0MaxPool;
   
   /** The {@code c3p0.acquireIncrement} database connection parameter. */
   private Integer c3p0AcqInc;
   
   /** The {@code c3p0.maxIdleTime} database connection parameter. */ 
   private Integer c3p0MaxIdle;
   
   /** The database instance. */
   private Database database;
   
   /**
    * Constructor that sets the database physical name, URL, username and password.
    * 
    * @param   pdbName
    *          The physical name of the database.
    * @param   ldbName
    *          The logical name of the database.
    * @param   url
    *          The URL to be set.
    * @param   username
    *          The username to be set.
    * @param   password
    *          The password to be set.
    * @param   c3p0MaxStmts
    *          The {@code c3p0.maxStatementsPerConnection} database connection parameter.
    * @param   c3p0MinPool
    *          The {@code c3p0.minPoolSize} database connection parameter.
    * @param   c3p0MaxPool
    *          The {@code c3p0.maxPoolSize} database connection parameter.
    * @param   c3p0AcqInc
    *          The {@code c3p0.acquireIncrement} database connection parameter.
    * @param   c3p0MaxIdle
    *          The {@code c3p0.maxIdleTime} database connection parameter.
    * @param   database
    *          The database instance.
    */
   public TenantDatabaseDescriptor(String pdbName, 
                                   String ldbName, 
                                   String url, 
                                   String username, 
                                   String password,
                                   Integer c3p0MaxStmts,
                                   Integer c3p0MinPool,
                                   Integer c3p0MaxPool,
                                   Integer c3p0AcqInc,
                                   Integer c3p0MaxIdle,
                                   Database database)
   {
      this.pdbName = pdbName;
      this.ldbName = ldbName;
      this.url = url;
      this.username = username;
      this.password = password;
      this.database = database;
      this.c3p0MaxStmts = c3p0MaxStmts;
      this.c3p0MinPool = c3p0MinPool;
      this.c3p0MaxPool = c3p0MaxPool;
      this.c3p0AcqInc = c3p0AcqInc;
      this.c3p0MaxIdle = c3p0MaxIdle;
   }
   
   /**
    * Copy constructor.
    * 
    * @param   other
    *          The other instance of {@code TenantDatabaseDescriptor}.
    */
   public TenantDatabaseDescriptor(TenantDatabaseDescriptor other)
   {
      this.pdbName = other.pdbName;
      this.ldbName = other.ldbName;
      this.url = other.url;
      this.username = other.username;
      this.password = other.password;
      this.database = other.database;
      this.c3p0MaxStmts = other.c3p0MaxStmts;
      this.c3p0MinPool = other.c3p0MinPool;
      this.c3p0MaxPool = other.c3p0MaxPool;
      this.c3p0AcqInc = other.c3p0AcqInc;
      this.c3p0MaxIdle = other.c3p0MaxIdle;
   }
   
   /**
    * Getter for the {@code pdbName} field.
    * 
    * @return  The physical name of the database.
    */
   public String getPdbName()
   {
      return pdbName;
   }
   
   /**
    * Getter for the {@code ldbName} field.
    * 
    * @return  The logical name of the database.
    */
   public String getLdbName()
   {
      return ldbName;
   }
   
   /**
    * Getter for the {@code url} field.
    * 
    * @return  The URL of the database.
    */
   public String getUrl()
   {
      return url;
   }
   
   /**
    * Getter for the {@code username} field.
    * 
    * @return  The username of the database.
    */
   public String getUsername()
   {
      return username;
   }
   
   /**
    * Getter for the {@code password} field.
    * 
    * @return  The password of the database.
    */
   public String getPassword()
   {
      return password;
   }
   
   /**
    * Getter for the {@code database} field.
    * 
    * @return  The database in use.
    */
   public Database getDatabase()
   {
      return database;
   }
   
   /**
    * Setter for the {@code pdbName} field.
    * 
    * @param   pdbName
    *          The physical name for this database.
    */
   public void setPdbName(String pdbName)
   {
      this.pdbName = pdbName;
   }
   
   /**
    * Setter for the {@code ldbName} field.
    * 
    * @param   ldbName
    *          The logical name for this database.
    */
   public void setLdbName(String ldbName)
   {
      this.ldbName = ldbName;
   }
   
   /**
    * Setter for the {@code url} field.
    * 
    * @param   url
    *          The URL for this database.
    */
   public void setUrl(String url)
   {
      this.url = url;
   }
   
   /**
    * Setter for the {@code username} field.
    * 
    * @param   username
    *          The username for this database.
    */
   public void setUsername(String username)
   {
      this.username = username;
   }
   
   /**
    * Setter for the {@code password} field.
    * 
    * @param   password
    *          The password for this database.
    */
   public void setPassword(String password)
   {
      this.password = password;
   }
   
   /**
    * Setter for the {@code database} field.
    * 
    * @param   database
    *          The database to be set.
    */
   public void setDatabase(Database database)
   {
      this.database = database;
   }
   
   /**
    * Obtain the {@code c3p0.maxStatementsPerConnection} database connection parameter.
    * 
    * @return  the {@code c3p0.maxStatementsPerConnection} database connection parameter, 
    *          possible {@code null}.
    */
   public Integer getC3p0MaxStmts()
   {
      return c3p0MaxStmts;
   }
   
   /**
    * Configures the {@code c3p0.maxStatementsPerConnection} database connection parameter.
    *
    * @param   c3p0MaxStmts
    *          The new value for {@code c3p0.maxStatementsPerConnection} database connection parameter, 
    *          possible {@code null}.
    */
   public void setC3p0MaxStmts(Integer c3p0MaxStmts)
   {
      this.c3p0MaxStmts = c3p0MaxStmts;
   }
   
   /**
    * Obtain the {@code c3p0.c3p0MinPool} database connection parameter.
    *
    * @return  the {@code c3p0.c3p0MinPool} database connection parameter, possible {@code null}.
    */
   public Integer getC3p0MinPool()
   {
      return c3p0MinPool;
   }
   
   /**
    * Configures the {@code c3p0.minPoolSize} database connection parameter.
    *
    * @param   c3p0MinPool
    *          The {@code c3p0.minPoolSize} database connection parameter, possible {@code null}.
    */
   public void setC3p0MinPool(Integer c3p0MinPool)
   {
      this.c3p0MinPool = c3p0MinPool;
   }
   
   /**
    * Obtain the {@code c3p0.c3p0MaxPool} database connection parameter.
    *
    * @return  the {@code c3p0.c3p0MaxPool} database connection parameter, possible {@code null}.
    */
   public Integer getC3p0MaxPool()
   {
      return c3p0MaxPool;
   }
   
   /**
    * Configures the {@code c3p0.maxPoolSize} database connection parameter.
    *
    * @param   c3p0MaxPool
    *          The {@code c3p0.maxPoolSize} database connection parameter, possible {@code null}.
    */
   public void setC3p0MaxPool(Integer c3p0MaxPool)
   {
      this.c3p0MaxPool = c3p0MaxPool;
   }
   
   /**
    * Obtain the {@code c3p0.acquireIncrement} database connection parameter.
    *
    * @return  the {@code c3p0.c3p0AcqInc} database connection parameter, 
    *          possible {@code null}.
    */
   public Integer getC3p0AcqInc()
   {
      return c3p0AcqInc;
   }
   
   /**
    * Configures the {@code c3p0.acquireIncrement} database connection parameter.
    *
    * @param   c3p0AcqInc
    *          The {@code c3p0.c3p0AcqInc} database connection parameter, 
    *          possible {@code null}.
    */
   public void setC3p0AcqInc(Integer c3p0AcqInc)
   {
      this.c3p0AcqInc = c3p0AcqInc;
   }
   
   /**
    * Obtain the {@code c3p0.maxIdleTime} database connection parameter.
    *
    * @return  the {@code c3p0.maxIdleTime} database connection parameter, possible {@code null}.
    */
   public Integer getC3p0MaxIdle()
   {
      return c3p0MaxIdle;
   }
   
   /**
    * Configures the {@code c3p0.maxIdleTime} database connection parameter.
    *
    * @param   c3p0MaxIdle
    *          The {@code c3p0.maxIdleTime} database connection parameter, possible {@code null}.
    */
   public void setC3p0MaxIdle(Integer c3p0MaxIdle)
   {
      this.c3p0MaxIdle = c3p0MaxIdle;
   }
}