Play framework support

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Play framework support

Munaf K
Hi,

Am writing a java app using play framework. Is there a cayenne plugin available for play?


Regards,

Munaf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Play framework support

Amedeo Mantica
Hi,

it is pretty easy to use cayenne into play

in your build.sbt add


libraryDependencies += "org.apache.cayenne" % "cayenne-client" % "3.1.2-SNAPSHOT"
libraryDependencies += "org.apache.cayenne" % "cayenne-lifecycle" % "3.1.2-SNAPSHOT"
libraryDependencies += "org.apache.cayenne" % "cayenne-project" % "3.1.2-SNAPSHOT"
libraryDependencies += "org.apache.cayenne" % "cayenne-server" % "3.1.2-SNAPSHOT"

then I just created a Play Module

public class CayenneModule implements Module {

    private static Logger.ALogger log = Logger.of(CayenneModule.class);

    private Environment env;

    public CayenneModule(Environment env) {
        this.env = env;
    }

    @Override
    public void configure(Binder binder) {

        File rootPath = env.rootPath();
        String projectPath = rootPath.getParent();

        File dir1 = new File(projectPath + File.separator + "your resource path");

        binder.bind(ResourceLocator.class).toInstance(new FilesystemResourceLocator(dir1));
    }
}

and a simple controller:


@Singleton
public class DatabaseController {

    private ServerRuntime serverRuntime;

    @Inject
    public DatabaseController(Environment env) {

        Logger.getAnonymousLogger().info("loading DatabaseController");
        Module extensions = new CayenneModule(env);
        serverRuntime = new ServerRuntime("cayenne/your cayenne project.xml", extensions);

    }

    public ServerRuntime runtime() {
        return serverRuntime;
    }

    public ObjectContext newContext() {
        return serverRuntime.getContext();
    }

    public ObjectContext newContext(DataChannel parent) {
        return serverRuntime.getContext(parent);
    }

}

Thank you
Amedeo

> On 3 Mar 2017, at 17:19, Munaf K <[hidden email]> wrote:
>
> Hi,
>
> Am writing a java app using play framework. Is there a cayenne plugin available for play?
>
>
> Regards,
>
> Munaf

Loading...