本文整理汇总了Java中ru.ppsrk.gwt.server.HibernateUtil类的典型用法代码示例。如果您正苦于以下问题:Java HibernateUtil类的具体用法?Java HibernateUtil怎么用?Java HibernateUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HibernateUtil类属于ru.ppsrk.gwt.server包,在下文中一共展示了HibernateUtil类的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;
}
});
}
示例2: NS2GServiceImpl
import ru.ppsrk.gwt.server.HibernateUtil; //导入依赖的package包/类
public NS2GServiceImpl() {
ServerUtils.setMappingFile("dozerMapping.xml");
debug = HibernateUtil.initSessionFactoryDebugRelease(forceDebug, forceRelease, "hibernate_dev.cfg.xml", "hibernate.cfg.xml");
try {
resetVotes(null, ResetType.ALL);
} catch (LogicException | ClientAuthException e) {
e.printStackTrace();
}
serverManager = new ServerManager(new ServersChangeCallback() {
@Override
public void onChange() {
try {
messageManager.postMessage(MessageType.SERVER_UPDATE, "", null);
} catch (LogicException | ClientAuthException e) {
e.printStackTrace();
}
}
});
cleanupManager.add(connectedPlayers);
cleanupManager.add(messageManager);
cleanupManager.add(serverManager);
}
示例3: 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);
}
}
}
示例4: 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);
}
}
示例5: 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;
}
});
}
示例6: 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();
}
});
}
}
示例7: 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;
}
});
}
}
示例8: 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;
}
});
}
示例9: 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;
}
});
}
示例10: 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;
}
});
}
示例11: 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 "";
}
示例12: getTarget
import ru.ppsrk.gwt.server.HibernateUtil; //导入依赖的package包/类
public static CheckedDTO getTarget(Session session, GatherPlayers gatherPlayers, VoteType type, Long targetId) throws LogicException {
CheckedDTO target = null;
switch (type) {
case COMM:
target = gatherPlayers.getParticipant(targetId);
if (target == null) {
target = gatherPlayers.getPlayer(targetId);
if (target == null) {
throw LogicExceptionFormatted.format("Игрок %d не найден.", targetId);
}
}
break;
case MAP:
Map map = HibernateUtil.tryGetObject(targetId, Map.class, session, "Карта не найдена.");
target = ServerUtils.mapModel(map, MapDTO.class);
break;
case SERVER:
Server server = HibernateUtil.tryGetObject(targetId, Server.class, session, "Сервер не найден.");
target = ServerUtils.mapModel(server, ServerDTO.class);
break;
}
return target;
}
示例13: 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;
}
});
}
示例14: 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);
}
});
}
示例15: 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;
}
});
}