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


Java SessionImpl.get方法代码示例

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


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

示例1: activateGame

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Sets the game to active and all other games to inactive (Allows the currentGame method to bring back result)
 *
 * @param id ID of game to activate
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping("/{id}/activate")
public ResponseEntity activateGame(SessionImpl session, @PathVariable("id") int id) {
    Game game = (Game) session.get(Game.class, id);

    if (game != null) {
        Query query = session.createQuery("update Game set active = false where active = true");
        query.executeUpdate();

        game.setActive(true);

        return new ResponseEntity(game, HttpStatus.OK);
    } else {
        return new ResponseEntity(HttpMessages.NO_GAME_FOUND, HttpStatus.NOT_FOUND);
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:24,代码来源:GameController.java

示例2: resetGameWinner

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping("/{id}/resetwinner")
public ResponseEntity resetGameWinner(@PathVariable("id") int id, SessionImpl session) {
    Game game = (Game) session.get(Game.class, id);

    game.getTeams().values().stream()
        .forEach(team -> {
            team.setWin(false);

            team.getPlayers().stream().forEach(player -> {
                int xpChanged = player.getXpChanged();
                int pointsChanged = player.getPointsChanged();

                player.getUser().getRanking().addPoints(pointsChanged * -1);
                player.getUser().getRanking().addXP(xpChanged * -1);

                player.setXpChanged(0);
                player.setPointsChanged(0);
            });
        });

    return new ResponseEntity("Successfully reset game winner", HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:25,代码来源:GameController.java

示例3: resignFromGame

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/{id}/resign")
public ResponseEntity resignFromGame(SessionImpl session, @AuthedUser User user, @PathVariable("id") int id) {
    Game game = (Game) session.get(Game.class, id);

    Optional<GameSignup> foundSignup = game.getSignups().stream()
        .filter(a -> a.getUser().getId() == user.getId())
        .findFirst();

    if (foundSignup.isPresent()) {
        session.delete(foundSignup.get());

        return new ResponseEntity("Successfully resigned", HttpStatus.OK);
    }

    return new ResponseEntity("Sign Up not found", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:19,代码来源:GameController.java

示例4: changeAvatar

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Change a teams avatar
 *
 * @param session       (Resolved)
 * @param multipartFile (Image)
 * @param id            ID of team to change picture
 * @return Response
 * @throws IOException
 */
@UnitOfWork
@RequestMapping(value = "/{id}/avatar", method = RequestMethod.POST)
public ResponseEntity changeAvatar(SessionImpl session,
                                   @AuthedUser User user,
                                   @RequestParam("image") MultipartFile multipartFile,
                                   @PathVariable("id") int id) throws IOException, DbxException {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, id);

    if (userTeam == null)
        return new ResponseEntity("Team not found", HttpStatus.NOT_FOUND);

    if (!userTeamService.doesUserHaveAuthorization(user, userTeam))
        return new ResponseEntity("You cannot do that", HttpStatus.FORBIDDEN);

    userTeamService.changeTeamPicture(userTeam, multipartFile.getInputStream());

    return new ResponseEntity("Successfully changed picture", HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:28,代码来源:UserTeamController.java

示例5: deleteTeam

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Deletes a team
 *
 * @param session  (Resolved)
 * @param id       ID of the team to delete
 * @param teamName Team name confirmation
 * @return Message
 */
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping(value = "/{id}/delete", method = RequestMethod.GET)
public ResponseEntity deleteTeam(SessionImpl session, @AuthedUser User user, @PathVariable("id") int id, @RequestParam("name") String teamName, @RequestParam(value = "newOwner", required = false) Integer newOwner) {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, id);

    if (!teamName.equals(userTeam.getName()))
        return new ResponseEntity("Team name did not match", HttpStatus.BAD_REQUEST);

    if (!userTeamService.doesUserHaveAuthorization(user, userTeam))
        return new ResponseEntity("You are not allowed to do this", HttpStatus.FORBIDDEN);

    userTeamService.disbandTeam(userTeam, newOwner);
    user.setTeam(null);

    return new ResponseEntity(userTeam, HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:26,代码来源:UserTeamController.java

示例6: kickUser

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Kick a player from a team
 *
 * @param session (Resolved)
 * @param id      ID Of the team to kick from
 * @param userID  User to kick
 * @return Response
 */
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/{id}/kick/{user}")
public ResponseEntity kickUser(SessionImpl session,
                               @AuthedUser User authedUser,
                               @PathVariable("id") int id,
                               @PathVariable("user") int userID) {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, id);

    if (userTeam == null)
        return new ResponseEntity("Team not found", HttpStatus.NOT_FOUND);

    if (!userTeamService.doesUserHaveAuthorization(authedUser, userTeam))
        return new ResponseEntity("You're not allowed to do that", HttpStatus.FORBIDDEN);

    userTeam.getMembers().removeIf(
        user -> user.getId() == userID);

    return new ResponseEntity("Successfully kicked player", HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:29,代码来源:UserTeamController.java

示例7: leaveTeam

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Leave the team (Remove yourself from the member list)
 *
 * @param session (Resolved)
 * @param user    (Resolved)
 * @param id      The ID of the team to leave
 * @return Response
 */
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/{id}/leave")
public ResponseEntity leaveTeam(SessionImpl session,
                                @AuthedUser User user,
                                @PathVariable("id") int id) {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, id);

    if (userTeam == null)
        return new ResponseEntity("Team not found", HttpStatus.NOT_FOUND);

    userTeam.getMembers().removeIf(currentUser ->
        currentUser.getId() == user.getId());

    return new ResponseEntity("Successfully left team", HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:25,代码来源:UserTeamController.java

示例8: getHistory

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Gets the game history of a team
 *
 * @param session (Resolved)
 * @param id      ID of the team
 * @param page    Page offset
 * @param count   Number of results
 * @return history
 */
@UnitOfWork
@RequestMapping("/{id}/history")
public ResponseEntity getHistory(SessionImpl session,
                                 @PathVariable("id") int id,
                                 @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                 @RequestParam(value = "count", defaultValue = "8", required = false) int count) {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, id);

    if (userTeam != null) {
        page = page < 1 ? 1 : page;
        count = count < 1 || count > 8 ? 8 : count;

        List<Game> games = userTeamService.getGamesForUserTeam(userTeam, page, count);

        return new ResponseEntity(games, HttpStatus.OK);
    }

    return new ResponseEntity("That team was not found", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:29,代码来源:UserTeamController.java

示例9: updateBlog

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Updates a blog posts with given information
 *
 * @param session
 * @param id       The ID of the blog post to update
 * @param blogPost JSON of post to update with
 * @return The new blog post
 */
@Transactional
@PreAuthorization(minRole = User.Role.BLOGGER)
@RequestMapping(value = "/{id}/update", method = RequestMethod.POST)
public ResponseEntity updateBlog(SessionImpl session,
                                 @PathVariable("id") int id,
                                 @JSONParam("post") BlogPost blogPost) {
    BlogPost oldPost = (BlogPost) session.get(BlogPost.class, id);

    if (oldPost != null) {
        blogPost.setId(id);

        session.merge(blogPost);

        return new ResponseEntity(blogPost, HttpStatus.OK);
    } else {
        return new ResponseEntity("No post found", HttpStatus.NOT_FOUND);
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:27,代码来源:BlogController.java

示例10: removePlayer

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Removes a player from a team without penalizing
 *
 * @param playerID ID of player to remove
 * @return The player which was removed
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping("/{playerID}/remove")
public ResponseEntity removePlayer(SessionImpl session, @PathVariable("playerID") int playerID) {
    Player player = (Player) session.get(Player.class, playerID);

    if (player != null) {
        session.delete(player);

        return new ResponseEntity("Successfully deleted player", HttpStatus.OK);
    }

    return new ResponseEntity("Player could not be found", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:21,代码来源:PlayerController.java

示例11: addPlayer

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Adds a player to a team
 *
 * @param teamID   ID of team to add to
 * @param language The language that the user will be playing
 * @param newUser  The user that will be playing
 * @return The newly added player
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity addPlayer(@RequestParam("teamID") int teamID,
                                @RequestParam("language") String language,
                                @JSONParam("user") User newUser,
                                @AuthedUser User user,
                                SessionImpl session) {
    Team team = (Team) session.get(Team.class, teamID);

    if (team != null) {
        Player newPlayer = new Player(team, newUser, language);

        session.save(newPlayer);

        String message = "You were added to the game on " + new SimpleDateFormat("EEE, MMM d @ K:mm a").format(new Date(team.getGame().getTimestamp().getTime()));
        Activity activity = new Activity(newPlayer.getUser(), user, message, 0, 0);

        session.save(activity);

        if (newPlayer.getUser().getEmail() != null) {
            String subject = "Accepted to play a game of DevWars";
            String activityMessage = "Dear " + newPlayer.getUser().getUsername() + ", you've been accepted to play a game of DevWars on " + new Date(team.getGame().getTimestamp().getTime()).toString();

            Util.sendEmail(Reference.getEnvironmentProperty("emailUsername"), Reference.getEnvironmentProperty("emailPassword"), subject, activityMessage, newPlayer.getUser().getEmail());
        }

        return new ResponseEntity(newPlayer, HttpStatus.OK);
    }

    return null;
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:41,代码来源:PlayerController.java

示例12: uploadSite

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Upload for the teams data straight from cloud nine
 *
 * @param session
 * @param id      ID of team to set
 * @param zipFile tar.gz file from Cloud Nine
 * @return
 * @throws IOException
 */
@PreAuthorization(minRole = User.Role.ADMIN)
@UnitOfWork
@RequestMapping(value = "/{id}/upload", method = RequestMethod.POST)
public ResponseEntity uploadSite(SessionImpl session, @PathVariable("id") int id, @RequestPart("zip") MultipartFile zipFile) throws IOException, DbxException {
    Team team = (Team) session.get(Team.class, id);

    TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new GZIPInputStream(zipFile.getInputStream()));

    String destPath = fileStorage.SITE_STORAGE_PATH + "/" + team.getGame().getId() + "/" + team.getName();

    TarArchiveEntry tarArchiveEntry = null;
    while ((tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) != null) {
        String fileName = tarArchiveEntry.getName();

        fileName = fileName.split("_")[fileName.split("_").length - 1];
        fileName = fileName.replace("workspace", "");

        boolean isIgnored = Arrays.asList(ignored).stream().anyMatch(fileName::contains);

        if (!isIgnored) {
            System.out.println(fileName);

            if (!tarArchiveEntry.isDirectory()) {
                fileStorage.uploadFile(destPath + fileName, tarArchiveInputStream);
            }
        }

    }

    return new ResponseEntity("Successfully Uploaded Team's files", HttpStatus.OK);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:41,代码来源:TeamController.java

示例13: deactivateGame

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Sets the game to inactive
 *
 * @param id ID of game to deactivate
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping("/{id}/deactivate")
public ResponseEntity deactivateGame(SessionImpl session, @PathVariable("id") int id) {
    Game game = (Game) session.get(Game.class, id);

    if (game != null) {
        game.setActive(false);

        return new ResponseEntity(game, HttpStatus.OK);
    } else {
        return new ResponseEntity(HttpMessages.NO_GAME_FOUND, HttpStatus.NOT_FOUND);
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:21,代码来源:GameController.java

示例14: signUpForGame

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Signs a user up for a game
 *
 * @param id ID of game to sign up for
 * @return Message
 */
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/{id}/signup")
public ResponseEntity signUpForGame(SessionImpl session, @AuthedUser User user, @PathVariable("id") int id) {
    Game game = (Game) session.get(Game.class, id);

    if (game != null) {
        boolean hasSignedUp = game.getSignups().stream()
            .anyMatch(signup -> signup.getUser().getId() == user.getId());

        if (!hasSignedUp) {

            GameSignup gameSignup = new GameSignup(user, game);

            Activity activity = new Activity(user, user, "Signed up for game on " + new SimpleDateFormat("EEE, MMM d @ K:mm a").format(new Date(game.getTimestamp().getTime())), 0, 0);

            session.save(gameSignup);
            session.save(activity);

            return new ResponseEntity("Signed up user", HttpStatus.OK);
        } else {
            return new ResponseEntity("You have already signed up for that game", HttpStatus.CONFLICT);
        }
    }

    return new ResponseEntity(HttpMessages.NO_GAME_FOUND, HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:34,代码来源:GameController.java

示例15: signUpTwitchUser

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Method to sign up a twitch user (Meant for chat command)
 *
 * @param username Username of twitch user to apply
 * @param id       ID of game to apply user to
 * @return Response Entity
 */
@PreAuthorization(minRole = User.Role.ADMIN)
@Transactional
@RequestMapping(value = "/{id}/signuptwitchuser", method = RequestMethod.POST)
public ResponseEntity signUpTwitchUser(@RequestParam("username") String username, @PathVariable("id") int id, SessionImpl session) {
    User theTwitchUser = userService.userForTwitchUsername(username);

    if (theTwitchUser != null) {
        User twitchUser = (User) session.merge(theTwitchUser);

        Game game = (Game) session.get(Game.class, id);

        if (game == null) {
            return new ResponseEntity("Game not found", HttpStatus.NOT_FOUND);
        }

        boolean isUserApplied = game.getSignups().stream()
            .anyMatch(signup -> signup.getUser().getId() == twitchUser.getId());

        if (!isUserApplied) {
            if (twitchUser.getWarrior() == null) {
                return new ResponseEntity("You are not a warrior, click http://devwars.tv/warrior-signup to sign up.", HttpStatus.CONFLICT);
            }

            GameSignup gameSignup = new GameSignup(twitchUser, game);

            session.save(gameSignup);

            return new ResponseEntity("Successfully signed up " + twitchUser.getUsername(), HttpStatus.OK);
        } else return new ResponseEntity("You are already signed up for that game.", HttpStatus.CONFLICT);

    } else
        return new ResponseEntity("Twitch user not found. Please connect your twitch account with your DevWars account.", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:41,代码来源:GameController.java


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