Package si.unimb.cot.mgbl.gamemgmt.aog.datamodel

Examples of si.unimb.cot.mgbl.gamemgmt.aog.datamodel.AOGGameLevelHiber


  //use transactions strictly, false if transactions are handled outside the methods
  private static boolean USE_TRANSACTIONS_INSIDE=false;

  public static ArrayList<AOGGameCardHiber> getOrderedCardsForLevel(long gameLevelId, Session hibernateSession) {
    ArrayList<AOGGameCardHiber> ret=new ArrayList<AOGGameCardHiber>();
    AOGGameLevelHiber ag=AOGGameLevelDao.findGameLevelHiber(gameLevelId, hibernateSession);
    if (ag.getCards()==null) return ret;
   
    Set<AOGGameCardHiber> cards=ag.getCards();
    for (AOGGameCardHiber gameLevelHiber : cards) {
      ret.add(gameLevelHiber);
    }
    //sort them
    Collections.sort(ret,new Comparator<AOGGameCardHiber>() {
View Full Code Here


 
  public static AOGGameLevelHiber findGameLevelHiber(long id, Session hibernateSession) {
    Query q=hibernateSession.createQuery("select o from AOGGameLevelHiber o where o.id=:id");
    q.setParameter("id",id);
    for (Iterator iter = q.iterate(); iter.hasNext();) {
      AOGGameLevelHiber gameLevelHiber=(AOGGameLevelHiber)iter.next();
     
      //pre read cards
      Set<AOGGameCardHiber> cards=gameLevelHiber.getCards();
      for (AOGGameCardHiber gameCardHiber : cards) {
        gameCardHiber.getId();
      }
     
      return gameLevelHiber;
View Full Code Here

    if (t!=null) t.commit();
    return newGame.getId();
  }
 
  public static void deleteGameLevel(long id,Session hibernateSession) {
    AOGGameLevelHiber gt=findGameLevelHiber(id,hibernateSession);
    if (gt==null) return;
    Transaction t=null;
    if (USE_TRANSACTIONS_INSIDE) t=hibernateSession.beginTransaction();
    //delete cards
    Set<AOGGameCardHiber> cards=gt.getCards();
    for (AOGGameCardHiber gameCardHiber : cards) {
      AOGGameCardDao.deleteGameCard(gameCardHiber.getId(), hibernateSession);
    }
    hibernateSession.delete(gt);
    if (t!=null) t.commit();
View Full Code Here

  public ActionForward defaultMethodInsertLevel(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res,Game g,GameHiber gh,AOGGameHiber ag) {
   
    AOGAuthorForm form=(AOGAuthorForm)af;

    //insert at the end by default
    AOGGameLevelHiber newOne=new AOGGameLevelHiber();
    //get max level number
    int max=-1;
    ArrayList<AOGGameLevelHiber> levels=form.getOrderedLevels();
    for (AOGGameLevelHiber gameLevelHiber : levels) {
      if (gameLevelHiber.getLevelNumber()>max) max=gameLevelHiber.getLevelNumber();
    }
    //insert new one
    newOne.setLevelNumber(max+1);
    ag.getLevels().add(newOne);
    AOGGameLevelDao.persistAOGGameLevelHiber(newOne,session);

    ag.setRepublishNeeded(true);
   
    AOGGameDao.updateGame(ag, session);
   
    //add an introduction card to level
    AOGGameCardHiber ach=new AOGGameCardHiber();
    //fill data
   
    ach.setCardType(AOGGameCardDao.CARD_TYPE_INTRODUCTION);
    ach.setCardText(req.getParameter("levelintro"));
   
    ach.setCardNumber(0);
   
    AOGGameCardDao.persistAOGGameCardHiber(ach, session);
   
    newOne.getCards().add(ach);
   
    AOGGameLevelDao.updateGameLevel(newOne, session);
   
    form.setOrderedLevels(AOGGameLevelDao.getOrderedLevelsForGame(ag.getId(),session));
View Full Code Here

    ag.setRepublishNeeded(true);
    AOGGameDao.updateGame(ag, session);
   
    AOGGameCardDao.persistAOGGameCardHiber(ach, session);
   
    AOGGameLevelHiber lvl=AOGGameLevelDao.findGameLevelHiber(levelId, session);
    lvl.getCards().add(ach);
   
    AOGGameLevelDao.updateGameLevel(lvl, session);
   
    MessageBean.setMyMessage(req, "Info card inserted");
   
View Full Code Here

    ag.setRepublishNeeded(true);
    AOGGameDao.updateGame(ag, session);

    AOGGameCardDao.persistAOGGameCardHiber(ach, session);
   
    AOGGameLevelHiber lvl=AOGGameLevelDao.findGameLevelHiber(levelId, session);
    lvl.getCards().add(ach);
   
    AOGGameLevelDao.updateGameLevel(lvl, session);
   
    MessageBean.setMyMessage(req, "Intro card inserted");
   
View Full Code Here

    ag.setRepublishNeeded(true);
    AOGGameDao.updateGame(ag, session);

    //persist
    AOGGameCardDao.persistAOGGameCardHiber(ach, session);
    AOGGameLevelHiber lvl=AOGGameLevelDao.findGameLevelHiber(levelId, session);
    lvl.getCards().add(ach);
    AOGGameLevelDao.updateGameLevel(lvl, session);
    MessageBean.setMyMessage(req, "Question card inserted");
    try {
      res.sendRedirect("authAOG.do?id="+req.getParameter("id")+"#card"+ach.getId());
    } catch (Exception e) {
View Full Code Here

  public ActionForward defaultMethodDeleteLevel(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res,Game g,GameHiber gh,AOGGameHiber ag) {
    String levelIdParameter=req.getParameter("levelId");
    long levelId=Long.parseLong(levelIdParameter);
    Set<AOGGameLevelHiber> lvls=ag.getLevels();
    for (Iterator iterator = lvls.iterator(); iterator.hasNext();) {
      AOGGameLevelHiber l = (AOGGameLevelHiber) iterator.next();
     
      if (l.getId()==levelId) {
        iterator.remove();
        AOGGameLevelDao.deleteGameLevel(l.getId(), session);

        ag.setRepublishNeeded(true);
        AOGGameDao.updateGame(ag, session);
       
        break;
View Full Code Here

     
  //delete card
  public ActionForward defaultMethodDeleteCard(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res,Game g,GameHiber gh,AOGGameHiber ag) {
    String levelIdParameter=req.getParameter("levelId");
    long levelId=Long.parseLong(levelIdParameter);
    AOGGameLevelHiber level=null;
    AOGGameCardHiber card=null;
    long cardId=Long.parseLong(req.getParameter("cardId"));
   
    Set<AOGGameLevelHiber> lvls=ag.getLevels();
    for (Iterator iterator = lvls.iterator(); iterator.hasNext();) {
      AOGGameLevelHiber l = (AOGGameLevelHiber) iterator.next();
      if (l.getId()==levelId) {
        level=l;
        break;
      }
    }
View Full Code Here

    ag.setRepublishNeeded(true);
    AOGGameDao.updateGame(ag, session);

    //persist
    AOGGameCardDao.persistAOGGameCardHiber(ach, session);
    AOGGameLevelHiber lvl=AOGGameLevelDao.findGameLevelHiber(levelId, session);
    lvl.getCards().add(ach);
    AOGGameLevelDao.updateGameLevel(lvl, session);
    MessageBean.setMyMessage(req, "Order-Question card inserted");
    try {
      res.sendRedirect("authAOG.do?id="+req.getParameter("id")+"#card"+ach.getId());
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of si.unimb.cot.mgbl.gamemgmt.aog.datamodel.AOGGameLevelHiber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.