DB Injection for Static and Instance Availability

I have a POJO that is used with the GWT RequestFactory and its associated proxy. POJO has both static methods ( list()) and instance methods ( persist()) that need access to my database. My database connection pool is configured to enter as a single item through Guice. I'm not sure how accurately I can inject so that both of these types of methods can access it?

In addition, POJO instances are created using an empty constructor, which negates the possibility of using constructor injection.

Here is a sample POJO for reference:

public class Person {
    private Integer id;
    private String name;

    public Integer getId() { return this.id; }
    public void setId(Integer id) { this.id = id; }
    public String getName() { return this.name; }
    public void setName(String name) { this.name = name; }

    public void persist() {
        //TODO: save state to DB
    }
    public static List<Person> list() {
        //TODO: get all people from DB
        return null;
    }
}
+3
source share
2 answers

- GWT . - - , (, , , GWT Guice .)

, , Guice "" , . " " http://code.google.com/docreader/#p=google-guice&s=google-guice&t=Injections). , EntityManager/EntityManagerFactory ( , ) .

, . (, @RequestScoped), .

. ( ), RequestFactory . , , (?)

+2

, Locator, , RequestFactory POJO, Locator.find() . , getId() / getVersion().

@ProxyFor(value = Person.class, locator = PersonLocator.class)
interface PersonProxy extends EntityProxy { .... }

pojos, ServiceLayerDecorator, createDomainObject() loadDomainObject().

+2

Source: https://habr.com/ru/post/1791319/


All Articles