Java tutorial
/* * * Copyright 2015 IK4-Tekniker All Rights Reserved * * This file is part of Health Questionnaire SE at FISTAR https://www.fi-star.eu/ * * Health Questionnaire SE 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. * * Health Questionnaire SE 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 should have received a copy of the GNU Affero General Public License * along with Health Questionnaire SE. If not, see http://www.gnu.org/licenses/. * * For those usages not covered by this license please contact with * patricia.casla at tekniker dot es * * Author: Ignacio Lazaro Llorente */ package es.tekniker.framework.ktek.commons; import org.orm.*; import org.orm.cfg.JDBCConnectionSetting; import org.hibernate.*; import java.util.Properties; public class KTEKPersistentManager extends PersistentManager { private static final String PROJECT_NAME = "KTEK.commons"; private static PersistentManager _instance = null; private static SessionType _sessionType = SessionType.THREAD_BASE; private static int _timeToAlive = 60000; private static JDBCConnectionSetting _connectionSetting = null; private static Properties _extraProperties = null; private static String _configurationFile = null; private KTEKPersistentManager() throws PersistentException { super(_connectionSetting, _sessionType, _timeToAlive, new String[] {}, _extraProperties, _configurationFile); setFlushMode(FlushMode.COMMIT); } public String getProjectName() { return PROJECT_NAME; } public static synchronized final PersistentManager instance() throws PersistentException { if (_instance == null) { _instance = new KTEKPersistentManager(); } return _instance; } public void disposePersistentManager() throws PersistentException { _instance = null; super.disposePersistentManager(); } public static void setSessionType(SessionType sessionType) throws PersistentException { if (_instance != null) { throw new PersistentException("Cannot set session type after create PersistentManager instance"); } else { _sessionType = sessionType; } } public static void setAppBaseSessionTimeToAlive(int timeInMs) throws PersistentException { if (_instance != null) { throw new PersistentException( "Cannot set session time to alive after create PersistentManager instance"); } else { _timeToAlive = timeInMs; } } public static void setJDBCConnectionSetting(JDBCConnectionSetting aConnectionSetting) throws PersistentException { if (_instance != null) { throw new PersistentException("Cannot set connection setting after create PersistentManager instance"); } else { _connectionSetting = aConnectionSetting; } } public static void setHibernateProperties(Properties aProperties) throws PersistentException { if (_instance != null) { throw new PersistentException( "Cannot set hibernate properties after create PersistentManager instance"); } else { _extraProperties = aProperties; } } public static void setConfigurationFile(String aConfigurationFile) throws PersistentException { if (_instance != null) { throw new PersistentException("Cannot set configuration file after create PersistentManager instance"); } else { _configurationFile = aConfigurationFile; } } public static void saveJDBCConnectionSetting() { PersistentManager.saveJDBCConnectionSetting(PROJECT_NAME, _connectionSetting); } }