r2921 - in branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business: . scaling
Author: echatellier Date: 2010-03-10 10:15:56 +0100 (Wed, 10 Mar 2010) New Revision: 2921 Log: Add classes to inject a lot of data into existing database (scaling). Added: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/package-info.java Added: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java (rev 0) +++ branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-10 09:15:56 UTC (rev 2921) @@ -0,0 +1,155 @@ +/* *##% Pollen + * Copyright (C) 2010 CodeLutin + * + * 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 org.chorem.pollen.business.scaling; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollDAO; +import org.chorem.pollen.business.persistence.PollenModelDAOHelper; +import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.business.persistence.VoteDAO; +import org.chorem.pollen.business.persistence.VoteToChoice; +import org.chorem.pollen.business.persistence.VoteToChoiceDAO; +import org.chorem.pollen.business.persistence.VotingList; +import org.chorem.pollen.business.utils.ContextUtil; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ScalingVote { + + /** log. */ + private static final Log log = LogFactory.getLog(ScalingVote.class); + + /** Adresse de la base de données (surchage l'adresse dans src/test/resources) */ + public static final String DB_URL = "jdbc:h2:" + System.getProperty("user.home") + + File.separator + ".pollen" + File.separator + "pollendb"; + + /** La config en cours. */ + protected static Properties config; + + /** + * Main. + * + * @param args + */ + public static void main(String args[]) { + System.out.println("Using database at : " + DB_URL); + + ContextUtil contextUtil = ContextUtil.getInstance(); + config = contextUtil.getConf(); + config.setProperty("hibernate.connection.url", DB_URL); + config.remove("hibernate.hbm2ddl.auto"); + + try { + new ScalingVote().doInsert(); + } + catch(Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't insert mass mail", e); + } + } + } + + /** + * Insert a lot of vote into poll. + * + * This version find a poll with his name and add a vote + * for each votant in voting list. + * + * @throws TopiaException + */ + public void doInsert() throws TopiaException { + TopiaContext rootContext = TopiaContextFactory.getContext(config); + TopiaContext context = rootContext.beginTransaction(); + + PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context); + VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context); + VoteToChoiceDAO voteToChoiceDAO = PollenModelDAOHelper.getVoteToChoiceDAO(context); + + // find a poll with his name + Poll poll = pollDAO.findByTitle("Test condorcet 3000 v2"); + VotingList votingLists = poll.getVotingList().get(0); + + for (PersonToList personList : votingLists.getPollAccountPersonToList()) { + + PollAccount pollAccount = personList.getPollAccount(); + + // ne traite pas les email qui contienent 20 + // pour qu'il reste des choix de login ensuite + if (pollAccount.getEmail().contains("20@")) { + continue; + } + else { + if (log.isInfoEnabled()) { + log.info("Create vote for " + pollAccount.getEmail()); + } + } + + Vote myNewVote = voteDAO.create(); + myNewVote.setVotingList(votingLists); + myNewVote.setPollAccount(pollAccount); + myNewVote.setPoll(poll); + myNewVote.setWeight(new Double(1)); + myNewVote.setAnonymous(Boolean.FALSE); + + List<Choice> choices = new ArrayList<Choice>(); + choices.add(poll.getChoice().get(0)); + + List<VoteToChoice> voteToChoices = new ArrayList<VoteToChoice>(); + VoteToChoice voteToChoice = voteToChoiceDAO.create(); + voteToChoice.setChoice(poll.getChoice().get(0)); + voteToChoice.setVoteValue(1); + voteToChoice.setVote(myNewVote); + voteToChoices.add(voteToChoice); + + VoteToChoice voteToChoice2 = voteToChoiceDAO.create(); + voteToChoice2.setChoice(poll.getChoice().get(1)); + voteToChoice2.setVoteValue(2); + voteToChoice2.setVote(myNewVote); + voteToChoices.add(voteToChoice2); + + myNewVote.setChoiceVoteToChoice(voteToChoices); + myNewVote.update(); + poll.getVote().add(myNewVote); + } + + poll.update(); + context.commitTransaction(); + context.closeContext(); + + rootContext.closeContext(); + } +} Property changes on: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/package-info.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/package-info.java (rev 0) +++ branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/package-info.java 2010-03-10 09:15:56 UTC (rev 2921) @@ -0,0 +1,20 @@ +/* *##% Pollen + * Copyright (C) 2009 CodeLutin + * + * 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/>. ##%*/ + +/** + * Ensemble de classes pour injecter des données et faire de la montée en charge. + */ +package org.chorem.pollen.business.scaling; Property changes on: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
echatellier@users.chorem.org