cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amedeo Mantica <amedeomant...@me.com>
Subject Re: Play framework support
Date Fri, 03 Mar 2017 18:20:35 GMT
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 <kmunaf@hotmail.com> wrote:
> 
> Hi,
> 
> Am writing a java app using play framework. Is there a cayenne plugin available for play?
> 
> 
> Regards,
> 
> Munaf


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message