当前位置: 首页>>代码示例>>Java>>正文


Java HibernateUtil.exec方法代码示例

本文整理汇总了Java中ru.ppsrk.gwt.server.HibernateUtil.exec方法的典型用法代码示例。如果您正苦于以下问题:Java HibernateUtil.exec方法的具体用法?Java HibernateUtil.exec怎么用?Java HibernateUtil.exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ru.ppsrk.gwt.server.HibernateUtil的用法示例。


在下文中一共展示了HibernateUtil.exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: completeInfo

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
private void completeInfo(final PlayerDTO playerDTO) throws LogicException, ClientAuthException {
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws LogicException, ClientAuthException {
            try {
                Player playerEnt = (Player) session.createQuery("from Player p where p.steamId = :sid")
                        .setLong("sid", playerDTO.getId()).uniqueResult();
                if (playerEnt != null) {
                    playerDTO.setNick(playerEnt.getNick());
                }
            } catch (NonUniqueResultException e) {
                throw LogicExceptionFormatted.format("Дубликация информации об игроке %d", playerDTO.getId());
            }
            return null;
        }
    });

}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:20,代码来源:GatherPlayersManager.java

示例2: removeVotesForPlayer

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
protected void removeVotesForPlayer(final Long gatherId, final Long playerLeftId) throws LogicException, ClientAuthException {
    synchronized (connectedPlayers.getPlayersByGather(gatherId)) {
        List<Long> votes = HibernateUtil.exec(new HibernateCallback<List<Long>>() {

            @SuppressWarnings("unchecked")
            @Override
            public List<Long> run(Session session) throws LogicException, ClientAuthException {
                session.enableFilter("gatherId").setParameter("gid", gatherId);
                return session
                        .createQuery(
                                "select pv.steamId from PlayerVote pv, Vote v, Gather g2 where v in elements (pv.votes) and v.gather = g2 and v.type = :comm and v.targetId = :tid")
                        .setParameter("comm", VoteType.COMM).setLong("tid", playerLeftId).list();
            }
        });
        for (Long steamId : votes) {
            MessageDTO messageDTO = new MessageDTO(MessageType.VOTE_ENDED,
                    "Игрок, за которого вы голосовали, ушёл. Пожалуйста, переголосуйте.", gatherId);
            messageDTO.setVisibility(MessageVisibility.PERSONAL);
            messageDTO.setToSteamId(steamId);
            messageManager.postMessage(messageDTO);
            unvote(gatherId, steamId);
        }
    }
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:25,代码来源:NS2GServiceImpl.java

示例3: resolveGather

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
protected void resolveGather(final Long gatherId) throws LogicException, ClientAuthException {
    synchronized (connectedPlayers.getPlayersByGather(gatherId)) {
        HibernateUtil.exec(new HibernateCallback<Void>() {

            @Override
            public Void run(Session session) throws LogicException, ClientAuthException {
                session.enableFilter("gatherId").setParameter("gid", gatherId);
                @SuppressWarnings("unchecked")
                Set<Long> votedSteamIds = new HashSet<>(session.createQuery(
                        "select distinct(v.player.steamId) from Vote v left join v.gather").list());
                GatherPlayers gatherPlayers = connectedPlayers.getPlayersByGather(gatherId);
                for (PlayerDTO player : gatherPlayers.getPlayers()) {
                    if (!votedSteamIds.contains(player.getId())) {
                        removePlayer(gatherId, player.getId(), true);
                    }
                }
                return null;
            }
        });
        updateGatherStateByPlayerNumber(gatherId);
    }
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:23,代码来源:NS2GServiceImpl.java

示例4: getVoteResults

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@Override
public List<VoteResultDTO> getVoteResults() throws LogicException, ClientAuthException {
    return HibernateUtil.exec(new HibernateCallback<List<VoteResultDTO>>() {

        @Override
        public List<VoteResultDTO> run(Session session) throws LogicException, ClientAuthException {
            Long gatherId = getCurrentGatherId();
            List<VoteResultDTO> result = new LinkedList<>();
            for (VoteType voteType : VoteType.values()) {
                List<VoteResult> voteResults = getVoteResultsByType(gatherId, session, voteType);
                for (VoteResult voteResult : voteResults) {
                    result.add(voteResult.toDTO(session, connectedPlayers.getPlayersByGather(gatherId)));
                }
            }
            return result;
        }
    });
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:19,代码来源:NS2GServiceImpl.java

示例5: findOpenGatherId

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
private Long findOpenGatherId() throws LogicException, ClientAuthException {
    synchronized (connectedPlayers) {
        return HibernateUtil.exec(new HibernateCallback<Long>() {

            @Override
            public Long run(Session session) throws LogicException, ClientAuthException {
                Gather gather = (Gather) session.createQuery("from Gather g where g.state in (:states)")
                        .setParameterList("states", Arrays.asList(GatherState.OPEN, GatherState.ONTIMER)).setMaxResults(1)
                        .uniqueResult();
                if (gather == null) {
                    // create new gather
                    gather = (Gather) session.merge(new Gather());
                }
                return gather.getId();
            }
        });
    }
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:19,代码来源:NS2GServiceImpl.java

示例6: removeVotes

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
private Boolean removeVotes(final Long steamId) throws LogicException, ClientAuthException {
    synchronized (connectedPlayers) {
        return HibernateUtil.exec(new HibernateCallback<Boolean>() {

            @Override
            public Boolean run(Session session) throws LogicException, ClientAuthException {
                @SuppressWarnings("unchecked")
                List<PlayerVote> playerVotes = session.createQuery("from PlayerVote pv where pv.steamId = :sid")
                        .setLong("sid", steamId).list();
                for (PlayerVote playerVote : playerVotes) {
                    session.delete(playerVote);
                }
                return playerVotes.size() > 0;
            }
        });
    }
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:18,代码来源:NS2GServiceImpl.java

示例7: logout

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@Override
public void logout() throws LogicException, ClientAuthException {
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws LogicException, ClientAuthException {
            try {
                Long steamId = getSteamId();
                @SuppressWarnings("unchecked")
                List<Remembered> remembereds = session.createQuery("from Remembered r where r.steamId = :sid").setLong("sid", steamId)
                        .list();
                for (Remembered remembered : remembereds) {
                    session.delete(remembered);
                }
                removePlayer(getCurrentGatherId(), steamId, false);
            } catch (AnonymousAuthException e) {

            }
            getSession().invalidate();
            return null;
        }
    });
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:24,代码来源:NS2GServiceImpl.java

示例8: getVotedPlayerIds

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@Override
public Set<Long> getVotedPlayerIds() throws LogicException, ClientAuthException {
    return HibernateUtil.exec(new HibernateCallback<Set<Long>>() {

        @Override
        public Set<Long> run(Session session) throws LogicException, ClientAuthException {
            Set<Long> result = new HashSet<>();
            Long gatherId = getCurrentGatherId();
            session.enableFilter("gatherId").setParameter("gid", gatherId);
            @SuppressWarnings("unchecked")
            List<Long> votedSteamIds = session.createQuery(
                    "select distinct(v.player.steamId) from Vote v left join v.gather g, Gather g2 where g = g2").list();
            GatherPlayers gatherPlayers = connectedPlayers.getPlayersByGather(gatherId);
            for (Long voteSteamId : votedSteamIds) {
                PlayerDTO playerDTO = gatherPlayers.getPlayer(voteSteamId);
                if (playerDTO != null) {
                    result.add(playerDTO.getId());
                }
            }
            return result;
        }
    });
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:24,代码来源:NS2GServiceImpl.java

示例9: changeNick

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
private void changeNick(final PlayerDTO playerDTO, final String newNick) throws LogicException, ClientAuthException {
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws LogicException, ClientAuthException {
            Player playerEnt = (Player) session.createQuery("from Player p where p.steamId = :sid").setLong("sid", playerDTO.getId())
                    .uniqueResult();
            if (playerEnt == null) {
                session.merge(new Player(newNick, playerDTO.getId()));
            } else {
                playerEnt.setNick(newNick);
            }
            playerDTO.setNick(newNick);
            return null;
        }
    });
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:18,代码来源:NS2GServiceImpl.java

示例10: rememberMe

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
private String rememberMe(final Long steamId) {
    try {
        return HibernateUtil.exec(new HibernateCallback<String>() {

            @Override
            public String run(Session session) throws LogicException, ClientAuthException {
                Long rememberId = new Random().nextLong();
                Remembered remembered = new Remembered(rememberId, steamId);
                session.merge(remembered);
                return rememberId.toString();
            }
        });
    } catch (LogicException | ClientAuthException e) {
        e.printStackTrace();
    }
    return "";
}
 
开发者ID:rkfg,项目名称:ns2gather,代码行数:18,代码来源:AuthCallbackServlet.java

示例11: getHierarchicByParent

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
public List<D> getHierarchicByParent(final D parent, final String orderField, final AnnotateChildren annotateChildren)
        throws GwtUtilException {

    return HibernateUtil.exec(new HibernateCallback<List<D>>() {

        @Override
        public List<D> run(Session session) throws GwtUtilException {
            Long parentId = getId(parent, false);
            List<D> dtos = mapArray(getChildren(parentId, orderField, true, annotateChildren, session), dtoClass);
            for (D dto : dtos) {
                dto.setParent(parent);
            }
            return dtos;
        }
    });
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:17,代码来源:NestedSetManager.java

示例12: insertNode

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
public synchronized T insertNode(final T node, Long parentId) throws GwtUtilException {
    final Long sureParentId = ensureParentId(parentId);
    return HibernateUtil.exec(new HibernateCallback<T>() {

        @SuppressWarnings("unchecked")
        @Override
        public T run(Session session) throws GwtUtilException {
            T parentNode = (T) session.get(entityClass, sureParentId);
            if (parentNode == null) {
                throw new NestedSetManagerException("Parent node with id=" + sureParentId + " not found.");
            }
            log.debug("Insert; parent node: " + parentNode + " new node: " + node + " to parentNodeId: " + sureParentId);
            node.setLeftNum(parentNode.getRightNum());
            node.setRightNum(node.getLeftNum() + 1);
            node.setDepth(parentNode.getDepth() + 1);
            updateNodes(node.getLeftNum(), 2L, session);
            return (T) session.merge(node);
        }
    });
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:21,代码来源:NestedSetManager.java

示例13: init

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws GwtUtilException {
    AuthServiceImpl.startTest("hibernate.gwtutil_testmem.cfg.xml");
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws LogicException, ClientAuthException {
            try {
                TestEntity testEntity1 = new TestEntity(TEST_ENTITY_NAME);
                testEntity1.setStartDate(df.parse("07/03/1987"));
                session.save(testEntity1);

                TestEntity testEntity2 = new TestEntity(TEST_ENTITY_NAME);
                testEntity2.setStartDate(df.parse("20/03/1987"));
                session.save(testEntity2);

                TestEntity testEntity3 = new TestEntity(TEST_ENTITY_NAME);
                testEntity3.setStartDate(df.parse("30/03/1987"));
                session.save(testEntity3);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:27,代码来源:TestTemporalManager.java

示例14: initNG

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@Before
public void initNG() throws GwtUtilException {
    ServerUtils.resetTables(new String[] { "terrdeptsNG" });
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws GwtUtilException {
            NestedSetManagerNG<DeptNG> nsmNG = new NestedSetManagerNG<>(DeptNG.class, session, lock);
            Long rootId = nsmNG.insertRootNode(new DeptNG()).getId();
            DeptNG sq11 = nsmNG.insertNode(new DeptNG("11 Отряд", "Краснозатонский"), rootId);
            nsmNG.insertNode(new DeptNG("111 ПЧ", "Краснозатонский"), sq11.getId());
            DeptNG sq12 = nsmNG.insertNode(new DeptNG("12 Отряд", "Микунь"), rootId);
            DeptNG pch121 = nsmNG.insertNode(new DeptNG("121 ПЧ", "Микунь"), sq12.getId());
            nsmNG.insertNode(new DeptNG("1 ОП 121 ПЧ", "Кожмудор"), pch121.getId());
            DeptNG rootNode = nsmNG.getRootNode();
            session.refresh(rootNode);
            assertEquals(1L, rootNode.getId().longValue());
            assertEquals(1L, rootNode.getLeftNum().longValue());
            assertEquals(12L, rootNode.getRightNum().longValue());
            return null;
        }
    });

}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:25,代码来源:GWTUtilTest.java

示例15: testMoveNGToChild

import ru.ppsrk.gwt.server.HibernateUtil; //导入方法依赖的package包/类
@Test
public void testMoveNGToChild() throws GwtUtilException {
    HibernateUtil.exec(new HibernateCallback<Void>() {

        @Override
        public Void run(Session session) throws GwtUtilException {
            NestedSetManagerNG<DeptNG> nsmNG = new NestedSetManagerNG<>(DeptNG.class, session, lock);
            try {
                nsmNG.move(2L, 4L); // move to sq11
            } catch (NestedSetManagerException e) {
                assertEquals("Can't move node to its own child or itself.", e.getMessage());
            }
            return null;
        }
    });
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:17,代码来源:GWTUtilTest.java


注:本文中的ru.ppsrk.gwt.server.HibernateUtil.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。