Java tutorial
/** * Genji Scrum Tool and Issue Tracker * Copyright (C) 2015 Steinbeis GmbH & Co. KG Task Management Solutions * <a href="http://www.trackplus.com">Genji Scrum Tool</a> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* $Id:$ */ package com.aurel.track.persist; import java.util.LinkedList; import java.util.List; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.apache.torque.TorqueException; import org.apache.torque.util.Criteria; import com.aurel.track.beans.TCostCenterBean; import com.aurel.track.dao.CostCenterDAO; /** * The skeleton for this class was autogenerated by Torque on: * * [Mon Mar 27 12:21:16 EEST 2006] * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as * long as it does not already exist in the output directory. */ public class TCostCenterPeer extends com.aurel.track.persist.BaseTCostCenterPeer implements CostCenterDAO { /** * */ private static final long serialVersionUID = -4082766908174600499L; private static final Logger LOGGER = LogManager.getLogger(TCostCenterPeer.class); private static Class[] replacePeerClasses = { TAccountPeer.class, TDepartmentPeer.class }; private static String[] replaceFields = { TAccountPeer.COSTCENTER, TDepartmentPeer.COSTCENTER }; private static Class[] deletePeerClasses = { TCostCenterPeer.class }; private static String[] deleteFields = { TCostCenterPeer.OBJECTID }; /** * Loads a cost center by primary key * @param objectID * @return */ @Override public TCostCenterBean loadByPrimaryKey(Integer objectID) { TCostCenter tCostCenter = null; try { tCostCenter = retrieveByPK(objectID); } catch (Exception e) { LOGGER.warn("Loading the costcenter by primary key " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (tCostCenter != null) { return tCostCenter.getBean(); } return null; } /** * Loads cost centers by label * @param number * @return */ @Override public List<TCostCenterBean> loadByNumber(String number) { Criteria crit = new Criteria(); crit.add(COSTCENTERNUMBER, number); try { return convertTorqueListToBeanList(doSelect(crit)); } catch (Exception e) { LOGGER.error("Getting the costcenters by number " + " failed with " + e.getMessage()); return null; } } /** * Gets all costcenters * @return */ @Override public List<TCostCenterBean> loadAll() { Criteria crit = new Criteria(); crit.addAscendingOrderByColumn(COSTCENTERNUMBER); try { return convertTorqueListToBeanList(doSelect(crit)); } catch (TorqueException e) { LOGGER.error("Loading all costcenters failed with " + e.getMessage()); return null; } } /** * Saves an costCenter to the TCostCenter table. * @param costCenterBean * @return */ @Override public Integer save(TCostCenterBean costCenterBean) { TCostCenter tCostCenter; try { tCostCenter = BaseTCostCenter.createTCostCenter(costCenterBean); tCostCenter.save(); return tCostCenter.getObjectID(); } catch (Exception e) { LOGGER.error("Saving of costcenter failed with " + e.getMessage()); return null; } } /** * Deletes a costcenter from the database * @param objectID * @return */ @Override public void delete(Integer objectID) { Criteria crit = new Criteria(); crit.add(OBJECTID, objectID); try { doDelete(crit); } catch (TorqueException e) { LOGGER.error("Deleting the costcenter " + objectID + " failed with " + e.getMessage()); } } /** * Returns whether the costcenter has dependent data * @param objectID * @return */ @Override public boolean hasDependentData(Integer objectID) { return ReflectionHelper.hasDependentData(replacePeerClasses, replaceFields, objectID); } /** * Replaces all occurrences of the oldID with the newID and then deletes the oldID costcenter * @param oldID * @param newID * @return */ @Override public void replaceAndDelete(Integer oldID, Integer newID) { if (newID != null) { ReflectionHelper.replace(replacePeerClasses, replaceFields, oldID, newID); } ReflectionHelper.delete(deletePeerClasses, deleteFields, oldID); } private List<TCostCenterBean> convertTorqueListToBeanList(List<TCostCenter> torqueList) { List<TCostCenterBean> beanList = new LinkedList<TCostCenterBean>(); if (torqueList != null) { for (TCostCenter tCostCenter : torqueList) { beanList.add(tCostCenter.getBean()); } } return beanList; } }