CustomKeyGeneratorObject.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.jdbc;

  21. import java.util.HashMap;
  22. import java.util.Map;

  23. import org.openspcoop2.utils.TipiDatabase;

  24. /**
  25.  * CustomKeyGeneratorObject
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class CustomKeyGeneratorObject implements IKeyGeneratorObject {

  32.     private KeyGeneratorObjects keyGeneratorObject;
  33.     private String columnNameId;
  34.     private String table;
  35.     private CustomKeyGeneratorOtherTableObjects defaultTableObjects;
  36.     private Map<TipiDatabase,CustomKeyGeneratorOtherTableObjects> customTableObjects =
  37.             new HashMap<TipiDatabase, CustomKeyGeneratorOtherTableObjects>();
  38.    
  39.    
  40.     public CustomKeyGeneratorObject(String table,String columnNameId,
  41.             String sequenceName,String tableNameForInitSequence){
  42.         this.keyGeneratorObject = KeyGeneratorObjects.CUSTOM;
  43.         this.table = table;
  44.         this.columnNameId = columnNameId;
  45.         this.defaultTableObjects = new CustomKeyGeneratorOtherTableObjects(sequenceName,tableNameForInitSequence);
  46.     }
  47.     public CustomKeyGeneratorObject(String table,String columnNameId){
  48.         this.keyGeneratorObject = KeyGeneratorObjects.CUSTOM;
  49.         this.table = table;
  50.         this.columnNameId = columnNameId;
  51.         this.defaultTableObjects = new CustomKeyGeneratorOtherTableObjects("seq_"+this.table,this.table+"_init_seq");
  52.     }
  53.     public CustomKeyGeneratorObject(String table){
  54.         this.keyGeneratorObject = KeyGeneratorObjects.CUSTOM;
  55.         this.table = table;
  56.         this.columnNameId = "id";
  57.         this.defaultTableObjects = new CustomKeyGeneratorOtherTableObjects("seq_"+this.table,this.table+"_init_seq");
  58.     }
  59.    
  60.     public String getColumnNameId() {
  61.         return this.columnNameId;
  62.     }
  63.     public void setColumnNameId(String columnNameId) {
  64.         this.columnNameId = columnNameId;
  65.     }
  66.     @Override
  67.     public String getTable() {
  68.         return this.table;
  69.     }
  70.     public void setTable(String table) {
  71.         this.table = table;
  72.     }
  73.     @Override
  74.     public KeyGeneratorObjects getType(){
  75.         return this.keyGeneratorObject;
  76.     }
  77.     public CustomKeyGeneratorOtherTableObjects getDefaultTableObjects() {
  78.         return this.defaultTableObjects;
  79.     }
  80.     public void setDefaultTableObjects(
  81.             CustomKeyGeneratorOtherTableObjects defaultTableObjects) {
  82.         this.defaultTableObjects = defaultTableObjects;
  83.     }
  84.     public void addCustomTableObjectsForDatabaseType(TipiDatabase tipoDatabase,CustomKeyGeneratorOtherTableObjects custom){
  85.         this.customTableObjects.put(tipoDatabase, custom);
  86.     }
  87.     public void addCustomTableObjectsForDatabaseType(TipiDatabase tipoDatabase,String sequenceName){
  88.         this.customTableObjects.put(tipoDatabase, new CustomKeyGeneratorOtherTableObjects(sequenceName));
  89.     }
  90.     public void addCustomTableObjectsForDatabaseType(TipiDatabase tipoDatabase,String sequenceName,String tableNameForInitSequence){
  91.         this.customTableObjects.put(tipoDatabase, new CustomKeyGeneratorOtherTableObjects(sequenceName, tableNameForInitSequence));
  92.     }
  93.     public boolean existsCustomTableObjectsForDatabaseType(TipiDatabase tipoDatabase){
  94.         return this.customTableObjects.containsKey(tipoDatabase);
  95.     }
  96.     public CustomKeyGeneratorOtherTableObjects getCustomTableObjectsForDatabaseType(TipiDatabase tipoDatabase){
  97.         return this.customTableObjects.get(tipoDatabase);
  98.     }
  99.    
  100. }