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


Java SessionImpl.merge方法代码示例

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


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

示例1: 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

示例2: earnBetsForUsers

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Adds a watched game to a user
 *
 * @param session
 * @param usernames JSON Array of twitch usernames
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping(value = "/watched", method = RequestMethod.POST)
public ResponseEntity earnBetsForUsers(SessionImpl session, @JSONParam("usernames") String[] usernames) {
    List<User> updatedUsers = new ArrayList<>();

    for (String username : usernames) {
        User user = userService.userForTwitchUsername(username);

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

            user.setGamesWatched(user.getGamesWatched() + 1);
            updatedUsers.add(user);
        }
    }

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

示例3: 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

示例4: createTeam

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Creates a team and adds the user to it
 *
 * @param session (Resolved)
 * @param user    (Resolved)
 * @param name    The name of the team
 * @return A message for the user
 */
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResponseEntity createTeam(SessionImpl session,
                                 @AuthedUser User user,
                                 @RequestParam("name") String name,
                                 @RequestParam("tag") String tag) throws IOException {
    user = (User) session.merge(user);


    if (userTeamService.doesUserBelongToTeam(user))
        return new ResponseEntity("You already belong to a team", HttpStatus.CONFLICT);

    if (user.getWarrior() == null)
        return new ResponseEntity("You must be a warrior", HttpStatus.CONFLICT);

    UserTeam userTeam = new UserTeam(name, tag, user);

    Errors errors = new BeanPropertyBindingResult(userTeam, "userTeam");
    validator.validate(userTeam, errors);

    if (errors.hasErrors()) {
        return new ResponseEntity(errors.getAllErrors(), HttpStatus.BAD_REQUEST);
    }

    session.save(userTeam);
    session.flush();
    session.refresh(userTeam);

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

示例5: getOwnedTeam

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Returns the team that the current user owns
 *
 * @param user (Resolved) The user requesting the data
 * @return Response Entity for the request
 */
@UnitOfWork
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/ownedteam")
public ResponseEntity getOwnedTeam(SessionImpl session, @AuthedUser User user) {
    UserTeam userTeam = user.getOwnedTeam();

    if (userTeam != null) {
        userTeam = (UserTeam) session.merge(userTeam);

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

    return new ResponseEntity("You don't own a team", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:21,代码来源:UserController.java

示例6: getMyTeam

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Returns the team that the current user belongs to
 *
 * @param user (Resolved) The user requesting the data
 * @return Response Entity for the request
 */
@UnitOfWork
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping("/myteam")
public ResponseEntity getMyTeam(SessionImpl session, @AuthedUser User user) {
    UserTeam userTeam = user.getTeam();

    if (userTeam != null && userTeam.getOwner() != null) {
        userTeam = (UserTeam) session.merge(userTeam);

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

    return new ResponseEntity("You don't belong to a team", HttpStatus.NOT_FOUND);
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:21,代码来源:UserController.java

示例7: register

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Cloud Nine registration
 *
 * @param request
 * @param response
 * @param firstName
 * @param email
 * @param month
 * @param day
 * @param year
 * @param htmlRate
 * @param cssRate
 * @param jsRate
 * @param c9Name
 * @param favFood
 * @param favTool
 * @param location
 * @param company
 * @param about
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.PENDING)
@RequestMapping("/register")
public ResponseEntity register(HttpServletRequest request, HttpServletResponse response,
                               @RequestParam("firstName") String firstName,
                               @RequestParam("email") String email,
                               @RequestParam("month") int month,
                               @RequestParam("day") int day,
                               @RequestParam("year") int year,
                               @RequestParam("htmlRate") int htmlRate,
                               @RequestParam("cssRate") int cssRate,
                               @RequestParam("jsRate") int jsRate,
                               @RequestParam("c9Name") String c9Name,
                               @RequestParam("favFood") String favFood,
                               @RequestParam("favTool") String favTool,
                               @RequestParam("location") String location,
                               @RequestParam(value = "company", required = false) String company,
                               @RequestParam("about") String about,
                               SessionImpl session) {
    User user = (User) request.getAttribute("user");
    user = (User) session.merge(user);

    if (user.getEmail() == null) {
        user.setEmail(email);
    }

    if (month < 1) {
        return new ResponseEntity("Invalid DOB entered", HttpStatus.CONFLICT);
    }

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month - 1, day);

    Warrior warrior = new Warrior(firstName, favFood, favTool, about, c9Name, company, location, htmlRate, cssRate, jsRate, calendar.getTime(), user.getId());

    if (user.getWarrior() != null) return new ResponseEntity("You are already a warrior", HttpStatus.CONFLICT);

    session.save(warrior);

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

示例8: updateWarrior

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
@Transactional
@PreAuthorization(minRole = User.Role.USER)
@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResponseEntity updateWarrior(@AuthedUser User user,
                                    @JSONParam("warrior") Warrior warrior,
                                    SessionImpl session) throws JsonProcessingException {

    Errors errors = new BeanPropertyBindingResult(warrior, warrior.getClass().getName());
    validator.validate(warrior, errors);

    if (errors.hasErrors()) {
        return new ResponseEntity(errors.getAllErrors(), HttpStatus.BAD_REQUEST);
    }

    if (user.getWarrior() == null) return new ResponseEntity("You are not a warrior", HttpStatus.CONFLICT);

    user = (User) session.merge(user);

    Warrior oldWarrior = user.getWarrior();

    if (!oldWarrior.getHtmlRate().equals(warrior.getHtmlRate()) ||
        !oldWarrior.getCssRate().equals(warrior.getCssRate()) ||
        !oldWarrior.getJsRate().equals(warrior.getJsRate())) {
        if (oldWarrior.getUpdatedAt() == null) {
            warrior.setUpdatedAt(new Date());
        } else {
            long now = new Date().getTime();
            long then = oldWarrior.getUpdatedAt().getTime();

            if (now - then < (86400 * 7 * 2 * 1000))
                return new ResponseEntity("You can only change your ratings once every two weeks", HttpStatus.CONFLICT);

            warrior.setUpdatedAt(new Date());
        }

    }

    warrior.setId(user.getWarrior().getId());
    session.merge(warrior);

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


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