Search in sources :

Example 1 with Transactional

use of org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional in project jersey by jersey.

the class BookmarkResource method putBookmark.

@PUT
@Consumes("application/json")
public void putBookmark(JSONObject jsonEntity) throws JSONException {
    bookmarkEntity.setLdesc(jsonEntity.getString("ldesc"));
    bookmarkEntity.setSdesc(jsonEntity.getString("sdesc"));
    bookmarkEntity.setUpdated(new Date());
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(bookmarkEntity);
        }
    });
}
Also used : Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with Transactional

use of org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional in project jersey by jersey.

the class BookmarksResource method postForm.

@POST
@Consumes("application/json")
public Response postForm(JSONObject bookmark) throws JSONException {
    final BookmarkEntity bookmarkEntity = new BookmarkEntity(getBookmarkId(bookmark.getString("uri")), userResource.getUserEntity().getUserid());
    bookmarkEntity.setUri(bookmark.getString("uri"));
    bookmarkEntity.setUpdated(new Date());
    bookmarkEntity.setSdesc(bookmark.getString("sdesc"));
    bookmarkEntity.setLdesc(bookmark.getString("ldesc"));
    userResource.getUserEntity().getBookmarkEntityCollection().add(bookmarkEntity);
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(userResource.getUserEntity());
        }
    });
    URI bookmarkUri = uriInfo.getAbsolutePathBuilder().path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
    return Response.created(bookmarkUri).build();
}
Also used : BookmarkEntity(org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity) URI(java.net.URI) Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 3 with Transactional

use of org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional in project jersey by jersey.

the class UserResource method putUser.

@PUT
@Consumes("application/json")
public Response putUser(JSONObject jsonEntity) throws JSONException {
    String jsonUserid = jsonEntity.getString("userid");
    if ((null != jsonUserid) && !jsonUserid.equals(userid)) {
        return Response.status(409).entity("userids differ!\n").build();
    }
    // insert or update ?
    final boolean newRecord = (null == userEntity);
    if (newRecord) {
        // new user record to be inserted
        userEntity = new UserEntity();
        userEntity.setUserid(userid);
    }
    userEntity.setUsername(jsonEntity.getString("username"));
    userEntity.setEmail(jsonEntity.getString("email"));
    userEntity.setPassword(jsonEntity.getString("password"));
    if (newRecord) {
        TransactionManager.manage(utx, new Transactional(em) {

            public void transact() {
                em.joinTransaction();
                em.persist(userEntity);
            }
        });
        return Response.created(uriInfo.getAbsolutePath()).build();
    } else {
        TransactionManager.manage(utx, new Transactional(em) {

            public void transact() {
                em.merge(userEntity);
            }
        });
        return Response.noContent().build();
    }
}
Also used : UserEntity(org.glassfish.jersey.examples.bookmark_em.entity.UserEntity) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)3 Transactional (org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional)3 Date (java.util.Date)2 PUT (javax.ws.rs.PUT)2 URI (java.net.URI)1 POST (javax.ws.rs.POST)1 BookmarkEntity (org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity)1 UserEntity (org.glassfish.jersey.examples.bookmark_em.entity.UserEntity)1