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


Java SessionImpl类代码示例

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


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

示例1: initEntityManager

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
/**
 * Set up memory database and insert data from test-dataset.xml
 * 
 * @throws DatabaseUnitException
 * @throws HibernateException
 * @throws SQLException
 */
@BeforeClass
public static void initEntityManager() throws HibernateException, DatabaseUnitException, SQLException {
    entityManagerFactory = Persistence.createEntityManagerFactory("listing-test-db");
    entityManager = entityManagerFactory.createEntityManager();
    connection = new DatabaseConnection(((SessionImpl) (entityManager.getDelegate())).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetXml);
    if (inputStream != null) {
        FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
        flatXmlDataSetBuilder.setColumnSensing(true);
        dataset = flatXmlDataSetBuilder.build(inputStream);
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
    }
}
 
开发者ID:coodoo-io,项目名称:coodoo-listing,代码行数:23,代码来源:AbstractDbUnitTest.java

示例2: createConnection

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
/**
 * unfortunately there is no standard way to get jdbc connection from JPA entity manager
 *
 * @return JDBC connection
 */
private Connection createConnection() {
    try {
        EntityTransaction tx = this.em.getTransaction();
        if (isHibernatePresentOnClasspath() && em.getDelegate() instanceof Session) {
            connection = ((SessionImpl) em.unwrap(Session.class)).connection();
        } else {
            /**
             * see here:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager
             */
            tx.begin();
            connection = em.unwrap(Connection.class);
            tx.commit();
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not create database connection", e);
    }

    return connection;
}
 
开发者ID:database-rider,项目名称:database-rider,代码行数:25,代码来源:DataSetProcessor.java

示例3: init

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
private void init(String unitName) {
    if (emf == null) {
        log.debug("creating emf for unit "+unitName);
        emf = Persistence.createEntityManagerFactory(unitName);
        em = emf.createEntityManager();
        tx = em.getTransaction();
        if (isHibernateOnClasspath() && em.getDelegate() instanceof Session) {
            conn = ((SessionImpl) em.unwrap(Session.class)).connection();
        } else{
            /**
             * see here:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager
             */
            tx.begin();
            conn = em.unwrap(Connection.class);
            tx.commit();
        }

    }
    emf.getCache().evictAll();
}
 
开发者ID:database-rider,项目名称:database-rider,代码行数:21,代码来源:EntityManagerProvider.java

示例4: preHandle

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
    try {
        HandlerMethod handlerMethod = (HandlerMethod) o;

        Transactional transactional = handlerMethod.getMethodAnnotation(Transactional.class);

        if (transactional != null) {

            SessionImpl session = (SessionImpl) DatabaseManager.getSession();
            session.beginTransaction();

            httpServletRequest.setAttribute("session", session);
        }
    } catch (Exception ignored) {
    }

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

示例5: postHandle

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
@Override
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
    try {
        HandlerMethod handlerMethod = (HandlerMethod) o;

        Transactional transactional = handlerMethod.getMethodAnnotation(Transactional.class);

        if (transactional != null) {
            SessionImpl session = (SessionImpl) httpServletRequest.getAttribute("session");

            session.getTransaction().commit();
            session.close();
        }
    } catch (Exception ignored) {
    }
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:17,代码来源:TransactionalInterceptor.java

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

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

示例8: forfeitUser

import org.hibernate.internal.SessionImpl; //导入依赖的package包/类
/**
 * Removes a user from the game and penlizes them with some value
 *
 * @param session
 * @param player  The player to remove
 * @return
 */
@Transactional
@PreAuthorization(minRole = User.Role.ADMIN)
@RequestMapping(value = "/forfeituser", method = RequestMethod.POST)
public ResponseEntity forfeitUser(SessionImpl session,
                                  @JSONParam("player") Player player) {
    player = (Player) session.get(Player.class, player.getId());

    Ranking ranking = player.getUser().getRanking();
    ranking.addPoints(-50);
    ranking.addXP(-50);

    session.delete(player);

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

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

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

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

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

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

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

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


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