Java tutorial
/* * Copyright (C) 2014 Aurora Cain * * 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/>. */ package edu.uncc.genosets.datamanager.persister; import edu.uncc.genosets.datamanager.entity.AnalysisSet; import edu.uncc.genosets.datamanager.entity.CustomizableEntity; import edu.uncc.genosets.datamanager.entity.FactAnalysisSet; import java.util.List; import org.hibernate.StatelessSession; /** * * @author aacain */ public class AnalysisSetPersister implements Persister { private AnalysisSet analysisSet; private List<CustomizableEntity> entities; public AnalysisSetPersister(AnalysisSet analysisSet, List<CustomizableEntity> entities) { this.analysisSet = analysisSet; this.entities = entities; } @Override public void persist(StatelessSession session) { if (analysisSet.getId() == null) { session.insert(analysisSet.getDefaultName(), analysisSet); } for (CustomizableEntity entity : entities) { if (entity.getId() == null) { session.insert(entity.getDefaultName(), entity); } FactAnalysisSet fact = new FactAnalysisSet(); fact.setAnalysisSetId(analysisSet.getAnalysisSetId()); fact.setEntityId(entity.getId()); fact.setEntityTable(entity.getEntityName()); session.insert(fact.getDefaultName(), fact); } } }