本文整理汇总了Java中play.db.jpa.Transactional类的典型用法代码示例。如果您正苦于以下问题:Java Transactional类的具体用法?Java Transactional怎么用?Java Transactional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transactional类属于play.db.jpa包,在下文中一共展示了Transactional类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getNovidades
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result getNovidades(int pagina, int tamanhoPagina) {
if (pagina < 0 || tamanhoPagina <= 0 || tamanhoPagina > 500) {
return badRequest("Página, Tamanho de página e Máximo de resultados devem ser maiores que zero. "
+ "Tamanho de página deve ser menor ou igual a 500.");
}
Cidadao cidadao = daoCidadao
.find(UUID.fromString(request().username()));
List<Novidade> recentes = daoCidadao.getNovidadesRecentes(cidadao.getId(),
pagina, tamanhoPagina);
for (Novidade novidade : recentes) {
if(TipoDaNovidade.NOVA_OPINIAO.equals(novidade.getTipo())){
novidade.getOpiniao().setApoiada(cidadao);
}
}
return ok(toJson(recentes));
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:21,代码来源:FeedController.java
示例2: save
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
@BodyParser.Of(BodyParser.Json.class)
public Result save() {
Cidadao cidadao = daoCidadao
.find(UUID.fromString(request().username()));
if (!cidadao.isFuncionario()) {
return unauthorized("Cidadão não autorizado");
}
Form<Mensagem> form = formFactory.form(Mensagem.class).bindFromRequest();
if (form.hasErrors()) {
String recebido = Controller.request().body().asJson().toString();
if (recebido.length() > 30) {
recebido = recebido.substring(0, 30) + "...";
}
Logger.debug("Submissão com erros: " + recebido + "; Erros: " + form.errorsAsJson());
return badRequest(form.errorsAsJson());
}
Mensagem mensagem = daoMensagem.create(form.get());
mensagem.setAutor(cidadao.getMinisterioDeAfiliacao());
return created(toJson(mensagem));
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:26,代码来源:MensagemController.java
示例3: delete
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result delete(String id) {
Cidadao cidadao = daoCidadao
.find(UUID.fromString(request().username()));
if (!cidadao.isFuncionario()) {
return unauthorized("Cidadão não autorizado");
}
Mensagem mensagem = daoMensagem.find(UUID.fromString(id));
if (mensagem != null) {
daoMensagem.delete(mensagem);
return ok(toJson("Deleted: " + id));
} else {
return notFound(toJson("id : " + id));
}
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:MensagemController.java
示例4: get
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional(readOnly = true)
public Result get(Long id) {
Cidade cidade = dao.find(id);
if (cidade == null) {
ObjectNode result = Json.newObject();
result.put("error", "Not found " + id);
return notFound(toJson(result));
}
Cidadao cidadao = getCidadaoLogado();
cidade.setSeguidaPeloRequisitante(cidadao.isInscritoEm(cidade));
Logger.debug("Acesso a " + cidade.getNome());
ObjectNode node = (ObjectNode) toJson(cidade);
node.set("scores", Json.toJson(cidade.getScores()));
return ok(node);
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:22,代码来源:CidadeController.java
示例5: getNovidades
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional(readOnly = true)
public Result getNovidades(Long id, int pagina, int tamanhoPagina) {
if (pagina < 0 || tamanhoPagina <= 0 || tamanhoPagina > 500) {
return badRequest("Página, Tamanho de página e Máximo de resultados devem ser maiores que zero. " +
"Tamannho de página deve ser menor ou igual a 500.");
}
Cidade cidade = dao.find(id);
if (cidade == null) {
ObjectNode result = Json.newObject();
result.put("error", "Not found " + id);
return notFound(toJson(result));
}
return ok(toJson(dao.getNovidades(id, pagina, tamanhoPagina)));
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:CidadeController.java
示例6: similares
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional(readOnly = true)
public CompletionStage<Result> similares(Long id, Long quantidade) {
Cidadao cidadao = getCidadaoLogado();
Hibernate.initialize(cidadao.getIniciativasAcompanhadas());// TODO isso não devia estar aqui na fachada...
return CompletableFuture.supplyAsync(
() -> (iniciativaDAO.findSimilares(id, quantidade, cidadao)))
.thenApply((iniciativas) -> {
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
for (Iniciativa iniciativa : iniciativas) {
ObjectNode node = (ObjectNode)Json.toJson(iniciativa);
node.set("cidade", Json.toJson(iniciativa.getCidade()));
arrayNode.add(node);
}
return ok(arrayNode);
});
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:17,代码来源:IniciativaController.java
示例7: getOpinioes
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional(readOnly = true)
public Result getOpinioes(Long idIniciativa, int pagina, int tamanhoPagina) {
if (pagina < 0 || tamanhoPagina <= 0 || tamanhoPagina > 500) {
return badRequest("Página, Tamanho de página e Máximo de resultados devem ser maiores que zero. " +
"Tamannho de página deve ser menor ou igual a 500.");
}
Iniciativa iniciativa = iniciativaDAO.find(idIniciativa);
if (iniciativa == null) {
return notFound("Iniciativa não encontrada");
}
List<Opiniao> opinioes = opiniaoDAO.findByIniciativa(idIniciativa, pagina, tamanhoPagina);
for (Opiniao opiniao : opinioes) {
opiniao.setApoiada(getUsuarioLogado());
}
return ok(toJson(opinioes));
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:19,代码来源:OpiniaoController.java
示例8: addJoinha
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result addJoinha(Long idIniciativa, String idOpiniao){
Cidadao apoiador = getUsuarioLogado();
try{
UUID id = UUID.fromString(idOpiniao);
Opiniao opiniao = opiniaoDAO.find(id);
if(opiniao.addApoiador(apoiador)){
return ok();
}else{
return status(play.mvc.Http.Status.CONFLICT);
}
}catch(IllegalArgumentException e){
return notFound(idOpiniao);
}
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:OpiniaoController.java
示例9: removeJoinha
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result removeJoinha(Long idIniciativa, String idOpiniao){
Cidadao apoiador = getUsuarioLogado();
try{
UUID id = UUID.fromString(idOpiniao);
Opiniao opiniao = opiniaoDAO.find(id);
if(opiniao.removeApoiador(apoiador)){
return ok();
}else{
return badRequest("O cidadão já não apoia essa opinião");
}
}catch(IllegalArgumentException e){
return notFound(idOpiniao);
}
}
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:OpiniaoController.java
示例10: login
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public static Result login() {
String nombre = request().getQueryString("nombre");
String clave = request().getQueryString("clave");
List<User> us = JPA.em()
.createQuery("SELECT u FROM User u WHERE u.login = :nombre AND u.password = :clave", User.class)
.setParameter("nombre", nombre)
.setParameter("clave", clave)
.setMaxResults(1)
.getResultList();
if (us.size() == 0) {
flash("mensaje", "Nombre de usuario o contraseña no validos");
return redirect("/");
}
else {
return redirect("/categorias");
}
}
开发者ID:Arquisoft,项目名称:Trivial5b,代码行数:23,代码来源:Application.java
示例11: preguntaAPIRest
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public static Result preguntaAPIRest() {
Pregunta p = JPA.em()
.createQuery("SELECT p FROM Pregunta p WHERE p.categoria LIKE :categoria ORDER BY rand()", Pregunta.class)
.setParameter("categoria", "%" + session("categoria") + "%")
.setMaxResults(1)
.getSingleResult();
ObjectNode resultado = Json.newObject();
resultado.put("enunciado", p.getEnunciado());
ArrayNode opciones = resultado.putArray("respuestas");
for (Object [] r: p.getRespuestas()) {
ObjectNode respuesta = Json.newObject();
respuesta.put("correcta", (Boolean)r[0]);
respuesta.put("valor", (String)r[1]);
opciones.add(respuesta);
}
return ok(resultado);
}
开发者ID:Arquisoft,项目名称:Trivial5b,代码行数:21,代码来源:Application.java
示例12: index
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result index() {
ImmutableMap.Builder<String, String> clientMapBuilder = ImmutableMap.builder();
for (int i=0;i<JophielProperties.getInstance().getJophielClientLabels().size();++i) {
String target = JophielProperties.getInstance().getJophielClientTargets().get(i);
String label = JophielProperties.getInstance().getJophielClientLabels().get(i);
clientMapBuilder.put(target, label);
}
LazyHtml content = new LazyHtml(welcomeView.render(clientMapBuilder.build()));
content.appendLayout(c -> headingLayout.render(Messages.get("welcome.welcome"), c));
ControllerUtils.getInstance().appendSidebarLayout(content);
ControllerUtils.getInstance().appendBreadcrumbsLayout(content, ImmutableList.of(
new InternalLink(Messages.get("welcome.welcome"), routes.WelcomeController.index()))
);
ControllerUtils.getInstance().appendTemplateLayout(content, "Welcome");
ControllerUtils.getInstance().addActivityLog(userActivityService, "View welcome page <a href=\"" + "http://" + Http.Context.current().request().host() + Http.Context.current().request().uri() + "\">link</a>.");
return ControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels-deprecated,项目名称:judgels-jophiel,代码行数:25,代码来源:WelcomeController.java
示例13: listUsers
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Authorized(value = {"admin"})
@Transactional
public Result listUsers(long pageIndex, String orderBy, String orderDir, String filterString) {
Page<UserInfo> currentPage = userService.pageUsers(pageIndex, PAGE_SIZE, orderBy, orderDir, filterString);
LazyHtml content = new LazyHtml(listUsersView.render(currentPage, orderBy, orderDir, filterString));
content.appendLayout(c -> tabLayout.render(ImmutableList.of(
new InternalLink(Messages.get("user.users"), routes.UserController.index()),
new InternalLink(Messages.get("user.unverifiedUsers"), routes.UserController.viewUnverifiedUsers())
), c));
content.appendLayout(c -> headingWithActionLayout.render(Messages.get("user.list"), new InternalLink(Messages.get("commons.create"), routes.UserController.createUser()), c));
ControllerUtils.getInstance().appendSidebarLayout(content);
ControllerUtils.getInstance().appendBreadcrumbsLayout(content, ImmutableList.of(
new InternalLink(Messages.get("user.users"), routes.UserController.index())
));
ControllerUtils.getInstance().appendTemplateLayout(content, "Users");
ControllerUtils.getInstance().addActivityLog(userActivityService, "Open all users <a href=\"" + "http://" + Http.Context.current().request().host() + Http.Context.current().request().uri() + "\">link</a>.");
return ControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels-deprecated,项目名称:judgels-jophiel,代码行数:23,代码来源:UserController.java
示例14: listUnverifiedUsers
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Authorized(value = {"admin"})
@Transactional
public Result listUnverifiedUsers(long pageIndex, String orderBy, String orderDir, String filterString) {
Page<UserInfo> currentPage = userService.pageUnverifiedUsers(pageIndex, PAGE_SIZE, orderBy, orderDir, filterString);
LazyHtml content = new LazyHtml(listUnverifiedUsersView.render(currentPage, orderBy, orderDir, filterString));
content.appendLayout(c -> tabLayout.render(ImmutableList.of(
new InternalLink(Messages.get("user.users"), routes.UserController.index()),
new InternalLink(Messages.get("user.unverifiedUsers"), routes.UserController.viewUnverifiedUsers())
), c));
content.appendLayout(c -> headingLayout.render(Messages.get("user.unverifiedUsers.list"), c));
ControllerUtils.getInstance().appendSidebarLayout(content);
ControllerUtils.getInstance().appendBreadcrumbsLayout(content, ImmutableList.of(
new InternalLink(Messages.get("user.unverifiedUsers"), routes.UserController.viewUnverifiedUsers())
));
ControllerUtils.getInstance().appendTemplateLayout(content, "Users");
ControllerUtils.getInstance().addActivityLog(userActivityService, "Open unverified users <a href=\"" + "http://" + Http.Context.current().request().host() + Http.Context.current().request().uri() + "\">link</a>.");
return ControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels-deprecated,项目名称:judgels-jophiel,代码行数:23,代码来源:UserController.java
示例15: editContestModuleConfig
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Transactional(readOnly = true)
public Result editContestModuleConfig(long contestId) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (!ContestControllerUtils.getInstance().isAllowedToManageContest(contest, IdentityUtils.getUserJid())) {
return ContestControllerUtils.getInstance().tryEnteringContest(contest, IdentityUtils.getUserJid());
}
LazyHtml content = new LazyHtml(listModulesView.render(contest));
appendConfigSubtabLayout(content, contest);
UrielControllerUtils.getInstance().appendSidebarLayout(content);
appendBreadcrumbsLayout(content, contest,
new InternalLink(Messages.get("commons.update"), org.iatoki.judgels.uriel.contest.routes.ContestController.editContestModuleConfig(contest.getId()))
);
UrielControllerUtils.getInstance().appendTemplateLayout(content, "Contest - Update Module");
return UrielControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels,项目名称:uriel,代码行数:20,代码来源:ContestController.java
示例16: listAllowedContests
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = GuestView.class)
@Transactional(readOnly = true)
public Result listAllowedContests(long pageIndex, String orderBy, String orderDir, String filterString) {
Page<Contest> pageOfContests;
if (UrielControllerUtils.getInstance().isAdmin()) {
pageOfContests = contestService.getPageOfContests(pageIndex, PAGE_SIZE, orderBy, orderDir, filterString);
} else {
pageOfContests = contestService.getPageOfAllowedContests(pageIndex, PAGE_SIZE, orderBy, orderDir, filterString, IdentityUtils.getUserJid());
}
LazyHtml content = new LazyHtml(listContestsView.render(pageOfContests, pageIndex, orderBy, orderDir, filterString));
if (UrielControllerUtils.getInstance().isAdmin()) {
content.appendLayout(c -> headingWithActionLayout.render(Messages.get("contest.list"), new InternalLink(Messages.get("commons.create"), org.iatoki.judgels.uriel.contest.routes.ContestController.createContest()), c));
} else {
content.appendLayout(c -> headingLayout.render(Messages.get("contest.list"), c));
}
UrielControllerUtils.getInstance().appendSidebarLayout(content);
UrielControllerUtils.getInstance().appendBreadcrumbsLayout(content, ImmutableList.of(
new InternalLink(Messages.get("contest.contests"), org.iatoki.judgels.uriel.contest.routes.ContestController.index())
));
UrielControllerUtils.getInstance().appendTemplateLayout(content, "Contests");
return UrielControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels,项目名称:uriel,代码行数:25,代码来源:ContestController.java
示例17: unlockContest
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Authorized("admin")
@Transactional
public Result unlockContest(long contestId) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (!contest.isLocked() || !ContestControllerUtils.getInstance().hasContestEnded(contest)) {
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.viewContest(contest.getId()));
}
contestService.unlockContest(contest.getJid(), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
UrielControllerUtils.getInstance().addActivityLog(UrielActivityKeys.UNLOCK.construct(CONTEST, contest.getJid(), contest.getName()));
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.viewContest(contest.getId()));
}
开发者ID:judgels,项目名称:uriel,代码行数:17,代码来源:ContestController.java
示例18: listPublishedAnnouncements
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
public Result listPublishedAnnouncements(long contestId, long pageIndex, String orderBy, String orderDir, String filterString) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (!ContestControllerUtils.getInstance().isAllowedToEnterContest(contest, IdentityUtils.getUserJid())) {
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.viewContest(contest.getId()));
}
Page<ContestAnnouncement> pageOfContestAnnouncements = contestAnnouncementService.getPageOfAnnouncementsInContest(contest.getJid(), pageIndex, PAGE_SIZE, orderBy, orderDir, filterString, ContestAnnouncementStatus.PUBLISHED.name());
contestAnnouncementService.readContestAnnouncements(IdentityUtils.getUserJid(), pageOfContestAnnouncements.getData().stream().map(c -> c.getJid()).collect(Collectors.toList()), IdentityUtils.getIpAddress());
LazyHtml content = new LazyHtml(listPublishedAnnouncementsView.render(contest.getId(), pageOfContestAnnouncements, pageIndex, orderBy, orderDir, filterString));
content.appendLayout(c -> heading3Layout.render(Messages.get("announcement.list"), c));
if (isAllowedToSuperviseAnnouncements(contest)) {
appendSubtabsLayout(content, contest);
}
ContestControllerUtils.getInstance().appendTabsLayout(content, contest, IdentityUtils.getUserJid());
UrielControllerUtils.getInstance().appendSidebarLayout(content);
appendBreadcrumbsLayout(content, contest,
new InternalLink(Messages.get("announcement.list"), routes.ContestAnnouncementController.viewPublishedAnnouncements(contest.getId()))
);
UrielControllerUtils.getInstance().appendTemplateLayout(content, "Contest - Announcements");
return UrielControllerUtils.getInstance().lazyOk(content);
}
开发者ID:judgels,项目名称:uriel,代码行数:25,代码来源:ContestAnnouncementController.java
示例19: postChangePassword
import play.db.jpa.Transactional; //导入依赖的package包/类
@Transactional
@RequireCSRFCheck
public Result postChangePassword(String code) {
if ((IdentityUtils.getUserJid() == null) || (!userService.existsByUserJid(IdentityUtils.getUserJid()))) {
Form<ChangePasswordForm> form = Form.form(ChangePasswordForm.class).bindFromRequest();
if (userAccountService.isValidToChangePassword(code, System.currentTimeMillis())) {
if (form.hasErrors()) {
return showChangePassword(form, code);
} else {
ChangePasswordForm changeData = form.get();
if (!changeData.password.equals(changeData.confirmPassword)) {
form.reject("change_password.error.passwordsDidntMatch");
return showChangePassword(form, code);
} else {
userAccountService.changePassword(code, changeData.password);
return redirect(routes.UserAccountController.afterChangePassword());
}
}
} else {
return notFound();
}
} else {
return redirect(routes.WelcomeController.index());
}
}
开发者ID:judgels-deprecated,项目名称:judgels-jophiel,代码行数:26,代码来源:UserAccountController.java
示例20: disableModule
import play.db.jpa.Transactional; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Transactional
public Result disableModule(long contestId, String contestModule) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (contest.isLocked() || !EnumUtils.isValidEnum(ContestModules.class, contestModule) || !ContestControllerUtils.getInstance().isAllowedToManageContest(contest, IdentityUtils.getUserJid())) {
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestModuleConfig(contest.getId()));
}
ContestModules contestModuleType = ContestModules.valueOf(contestModule);
if (contest.getModulesSet().containsAll(ContestModuleUtils.getDependedModules(contestModuleType)) && !ContestModuleUtils.getDependedModules(contestModuleType).isEmpty()) {
flashError(Messages.get("contest.module.disable.error.dependencies", ContestModuleUtils.getDependedModules(contestModuleType).toString()));
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestModuleConfig(contest.getId()));
}
contestModuleService.disableModule(contest.getJid(), contestModuleType, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestModuleConfig(contest.getId()));
}
开发者ID:judgels,项目名称:uriel,代码行数:19,代码来源:ContestController.java
注:本文中的play.db.jpa.Transactional类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论