LocalTempTableHelper.java

/*
** Module   : LocalTempTableHelper.java
** Abstract : Helper class which generates local temp table DDL
**
** Copyright (c) 2004-2020, Golden Code Development Corporation.
**
** -#- -I- --Date-- --JPRM-- -----------------------------------Description-----------------------------------
** 001 CA  20080424  @38109  Created initial version. Generates DDL for local temp tables with
**                           local indexes.
** 002 CA  20080430  @38157  Changes due to original incorrect index creation for the "dirty"
**                           database.
** 003 ECF 20080512  @38503  Changed getIndexes(). Use new signature for
**                           DMOIndex.databaseIndexes().
** 004 ECF 20080611  @38696  Modified getComputedCols() to handle new PersistenceException.
**                           DMOIndex now throws an exception if index metadata cannot be queried.
** 005 ECF 20140822          Added implementation of isNotNullAllowed. Replaced Apache commons
**                           logging with J2SE logging.
** 006 EVL 20160223          Javadoc fixes to make compatible with Oracle Java 8 for Solaris 10.
** 007 OM  20200507          Upgrade to new persistence framework, without Hibernate.
** 008 OM  20200919          Improved access to dmo metadata.
**     OM  20200924          Dropped dead code.
*/

/*
** 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;

import java.util.*;
import com.goldencode.p2j.persist.orm.*;

/**
 * Helper class which generates and caches SQL phrases to create and drop
 * temporary tables, and to create indexes in those tables.
 * <p>
 * This class is responsible for local temporary tables support: the created
 * tables and indices will be local to the session which created them.
 */
final class LocalTempTableHelper
extends TempTableHelper
{
   /**
    * Constructor.
    *
    * @param   dmoIface
    *          DMO interface which provides the public API to the temp table.
    */
   LocalTempTableHelper(Class<? extends DataModelObject> dmoIface)
   {
      super(dmoIface, DatabaseManager.TEMP_TABLE_DB);
   }
   
   /**
    * This method will return the needed create table string, which is the 
    * "create local temporary table" string.
    * 
    * @return  The create table string.
    */
   @Override
   String getCreateTableStatement()
   {
      return "create local temporary table ";
   }
   
   /**
    * This method will return an additional suffix to make the index unique across sessions.
    * 
    * @return The additional suffix.
    */
   @Override
   String getAdditionalIndexSuffix()
   {
      return "__${" + UNIQUE_SUFFIX_KEY + "}";
   }
   
   /**
    * This method will return the indexes associated with a certain DMO, as
    * retrieved from the dmo_index.xml file.
    * 
    * @param   schema
    *          The schema used for this DMO.
    * @param   dmoIface
    *          The DMO for which to retrieve the indexes.
    * 
    * @return  An iterator for the indexes associated with this DMO.
    */
   @Override
   Iterator<P2JIndex> getIndexes(String schema, Class<? extends DataModelObject> dmoIface)
   {
      return DmoMetadataManager.getDmoInfo(dmoIface).getDatabaseIndexes();
   }
   
   /**
    * Indicate whether non-nullable columns are permitted.
    * 
    * @return  {@code true} if non-nullable columns are permitted, else {@code false}.
    */
   @Override
   boolean isNotNullAllowed()
   {
      return true;
   }
}