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


Java SessionImpl.save方法代码示例

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


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

示例1: createBlog

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Created new blog post
 *
 * @param blogPost JSON of the new post
 * @param user
 * @param session
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.BLOGGER)
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResponseEntity createBlog(@JSONParam("post") BlogPost blogPost,
                                 @AuthedUser User user,
                                 SessionImpl session) {

    Errors errors = new BeanPropertyBindingResult(blogPost, "blogPost");
    blogPostValidator.validate(blogPost, errors);

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

    blogPost.setUser(user);

    session.save(blogPost);

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

示例2: create

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Feedback for users : Puts new contact row in DB and sends email
 *
 * @param session
 * @param name    Name of the user
 * @param email   Email of the user
 * @param text    Text we should see
 * @param type    Type of feedback
 * @return
 */
@Transactional
@RequestMapping("/create")
public ResponseEntity create(SessionImpl session,
                             @RequestParam("name") String name,
                             @RequestParam("email") String email,
                             @RequestParam("text") String text,
                             @RequestParam("type") String type) {
    if (text.length() <= 1000 && type.length() < 255) {
        Contact contact = new Contact(name, email, type, text);

        String subject = "New " + type + " Inquiry from " + name;
        String message = "Name: " + name + "\nEmail: " + email + "\nText: " + text + "\nType: " + type;

        Util.sendEmail(Reference.getEnvironmentProperty("emailUsername"), Reference.getEnvironmentProperty("emailPassword"), subject, message, "[email protected]");

        session.save(contact);

        return new ResponseEntity(contact, HttpStatus.OK);
    } else {
        return new ResponseEntity("Enquiry is too long", HttpStatus.BAD_REQUEST);
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:33,代码来源:ContactController.java

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

示例4: createGame

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Creates a game with the default information
 *
 * @param timestamp The time in UTC which the game will start
 * @param name      Name of the game (Classic or Zen Garden)
 * @return New game
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping("/create")
public ResponseEntity createGame(SessionImpl session,
                                 @RequestParam(value = "time", required = false, defaultValue = "0") long timestamp,
                                 @RequestParam(required = false, value = "name") String name,
                                 @RequestParam(required = false, value = "tournament") Integer tournamentID) {

    Tournament tournament = tournamentID == null ? null : tournamentService.byID(tournamentID);

    Game game = gameService.defaultGame(tournament);

    if (name != null) {
        game.setName(name);

        if (name.equals("Team Classic")) {
            game.setTeamGame(true);
        }
    }

    if (timestamp != 0) {
        game.setTimestamp(new Timestamp(timestamp));
    }

    session.save(game);

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

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

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

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

示例8: invitePlayer

import org.hibernate.internal.SessionImpl; //导入方法依赖的package包/类
/**
 * Invites a player to a roster
 *
 * @param session    (Resolved)
 * @param teamID     ID of the team to invite player to
 * @param user       (Resolved)
 * @param inviteUser The ID of the user to invite
 * @return Message
 */
@Transactional
@PreAuthorization(minRole = User.Role.PENDING)
@RequestMapping("/{id}/invite")
public ResponseEntity invitePlayer(SessionImpl session, @PathVariable("id") int teamID, @AuthedUser User user, @RequestParam("user") int inviteUser) {
    UserTeam userTeam = (UserTeam) session.get(UserTeam.class, teamID);
    User invitedUser = (User) session.get(User.class, inviteUser);

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

    if (userTeam.getMembers().size() >= 3)
        return new ResponseEntity("This team has too many players", HttpStatus.CONFLICT);

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

    if (invitedUser == null)
        return new ResponseEntity("User does not exist", HttpStatus.NOT_FOUND);

    if (invitedUser.getWarrior() == null)
        return new ResponseEntity("You cannot invite non warriors", HttpStatus.CONFLICT);

    if (userTeamService.inviteUserToTeam(invitedUser, userTeam)) {
        Activity activity = new Activity(invitedUser, user, "You were invited to the team : " + userTeam.getName(), 0, 0);
        Notification notification = new Notification(invitedUser, "You were invited to the team : " + userTeam.getName(), false);

        session.save(activity);
        session.save(notification);

        return new ResponseEntity("Successfully Invited User", HttpStatus.OK);
    } else {
        return new ResponseEntity("User already has an invite", HttpStatus.BAD_REQUEST);
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:44,代码来源:UserTeamController.java

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


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