RecordInfo.java
/*
** Module : RecordInfo.java
** Abstract : Information that allows us to identify a record across multiple databases.
**
** Copyright (c) 2009-2024, Golden Code Development Corporation.
**
** -#- -I- --Date-- -JPRM- -----------------------------------Description-------------------------------------
** 001 SVL 20091126 @44449 Created initial version. Allows us to identify a record across multiple databases.
** 002 SBI 20170225 Changed to be a simple DTO that can be used by GWT RPC.
** 003 OM 20241128 Multi-tenant runtime support: selected the proper persistence context, eventually
** based on [sharedDb] parameter.
*/
/*
** 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.admin;
import java.io.Serializable;
/**
* Class which contains information that allows us to identify a record across multiple databases.
*/
public class RecordInfo
implements Serializable
{
/** Physical database name. */
private String databaseName;
/** Name of table. */
private String tableName;
/** Primary key ID. */
private Long recordID;
/**
* {@code true} for records from non-private section of the database.
* NOTE: This attribute does not need to be part of hash/equals since it is an attribute of the database.
*/
private boolean sharedDb;
/** Default constructor */
public RecordInfo()
{
}
/**
* Constructor.
*
* @param databaseName
* Physical database name.
* @param tableName
* Name of table.
* @param recordID
* Primary key ID.
* @param sharedDb
* {@code true} if the buffers are shared (not tenant private).
*/
public RecordInfo(String databaseName, String tableName, Long recordID, boolean sharedDb)
{
this.databaseName = databaseName;
this.tableName = tableName;
this.recordID = recordID;
this.sharedDb = sharedDb;
}
/**
* Retrieve the physical database name.
*
* @return Physical database name.
*/
public String getDatabaseName()
{
return databaseName;
}
/**
* Retrieve the table name.
*
* @return Table name.
*/
public String getTableName()
{
return tableName;
}
/**
* Check if this records belongs to non-private section of the database.
*
* @return {@code true} if this records belongs to non-private section of the database.
*/
public boolean isSharedDb()
{
return sharedDb;
}
/**
* Retrieve the primary key ID of the record. This presumes all tables use
* a 64-bit integral primary key.
*
* @return Primary key of the record.
*/
public Long getRecordID()
{
return recordID;
}
/**
* Sets the database name.
*
* @param databaseName
* The database name
*/
public void setDatabaseName(String databaseName)
{
this.databaseName = databaseName;
}
/**
* Sets the table name.
*
* @param tableName
* The table name
*/
public void setTableName(String tableName)
{
this.tableName = tableName;
}
/**
* Sets the record id.
*
* @param recordID
* The record id.
*/
public void setRecordID(Long recordID)
{
this.recordID = recordID;
}
/**
* Return a hash code consistent with {@link #equals}.
*
* @return Hash code.
*/
public int hashCode()
{
int result = 17;
result = 37 * result + databaseName.hashCode();
result = 37 * result + tableName.hashCode();
result = 37 * result + recordID.hashCode();
return result;
}
/**
* Test for equivalence with another object.
*
* @param o
* Object to compare with.
*
* @return <code>true</code> if <code>o</code> is the same type and the same internal state
* as this object; else <code>false</code>.
*/
public boolean equals(Object o)
{
if (!(o instanceof RecordInfo))
{
return false;
}
if (o == this)
{
return true;
}
RecordInfo other = (RecordInfo) o;
return databaseName.equals(other.databaseName) &&
tableName.equals(other.tableName) &&
recordID.equals(other.recordID);
}
}