Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace to QueryDsl #360

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/main/java/sample/FruitResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.seasar.doma.jdbc.criteria.Entityql;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand All @@ -20,6 +19,8 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.seasar.doma.jdbc.criteria.QueryDsl;

import java.util.List;

@Path("fruits")
Expand All @@ -30,19 +31,20 @@ public class FruitResource {

private static final Logger LOGGER = Logger.getLogger(FruitResource.class.getName());

@Inject Entityql entityql;
@Inject
QueryDsl queryDsl;

@GET
public List<Fruit> get() {
var f = new Fruit_();
return entityql.from(f).orderBy(c -> c.asc(f.name)).fetch();
return queryDsl.from(f).orderBy(c -> c.asc(f.name)).fetch();
}

@GET
@Path("{id}")
public Fruit getSingle(@PathParam Integer id) {
var f = new Fruit_();
Fruit entity = entityql.from(f).where(c -> c.eq(f.id, id)).fetchOne();
Fruit entity = queryDsl.from(f).where(c -> c.eq(f.id, id)).fetchOne();
if (entity == null) {
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404);
}
Expand All @@ -57,7 +59,7 @@ public Response create(Fruit fruit) {
}

var f = new Fruit_();
entityql.insert(f, fruit).execute();
queryDsl.insert(f).single(fruit).execute();
return Response.ok(fruit).status(201).build();
}

Expand All @@ -70,14 +72,14 @@ public Fruit update(@PathParam Integer id, Fruit fruit) {
}

var f = new Fruit_();
Fruit entity = entityql.from(f).where(c -> c.eq(f.id, id)).fetchOne();
Fruit entity = queryDsl.from(f).where(c -> c.eq(f.id, id)).fetchOne();

if (entity == null) {
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404);
}

entity.setName(fruit.getName());
entityql.update(f, entity).execute();
queryDsl.update(f).single(entity).execute();

return entity;
}
Expand All @@ -87,11 +89,11 @@ public Fruit update(@PathParam Integer id, Fruit fruit) {
@Transactional
public Response delete(@PathParam Integer id) {
var f = new Fruit_();
Fruit entity = entityql.from(f).where(c -> c.eq(f.id, id)).fetchOne();
Fruit entity = queryDsl.from(f).where(c -> c.eq(f.id, id)).fetchOne();
if (entity == null) {
throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404);
}
entityql.delete(f, entity).execute();
queryDsl.delete(f).single(entity).execute();
return Response.status(204).build();
}

Expand Down
Loading