use of org.glassfish.jersey.examples.bookmark.util.tx.Transactional in project jersey by jersey.
the class BookmarkResource method putBookmark.
@PUT
@Consumes(MediaType.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(new Transactional(em) {
public void transact() {
em.merge(bookmarkEntity);
}
});
}
use of org.glassfish.jersey.examples.bookmark.util.tx.Transactional in project jersey by jersey.
the class BookmarksResource method postForm.
@POST
@Consumes(MediaType.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(new Transactional(em) {
public void transact() {
em.merge(userResource.getUserEntity());
}
});
URI bookmarkUri = uriInfo.getAbsolutePathBuilder().path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
return Response.created(bookmarkUri).build();
}
use of org.glassfish.jersey.examples.bookmark.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(new Transactional(em) {
public void transact() {
em.persist(userEntity);
}
});
return Response.created(uriInfo.getAbsolutePath()).build();
} else {
TransactionManager.manage(new Transactional(em) {
public void transact() {
em.merge(userEntity);
}
});
return Response.noContent().build();
}
}
Aggregations