{"id":22707598,"url":"https://github.com/xvik/guice-persist-orient-play-example","last_synced_at":"2025-03-29T21:10:19.054Z","repository":{"id":145081939,"uuid":"69292863","full_name":"xvik/guice-persist-orient-play-example","owner":"xvik","description":"Play framework integration sample for guice-persist-orient","archived":false,"fork":false,"pushed_at":"2016-09-26T22:16:33.000Z","size":1046,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-04T21:45:47.649Z","etag":null,"topics":["guice","orientdb","play"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xvik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-26T21:07:20.000Z","updated_at":"2016-09-26T21:15:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"0c6b8715-f8c2-432f-92df-bec2125aa284","html_url":"https://github.com/xvik/guice-persist-orient-play-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvik%2Fguice-persist-orient-play-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvik%2Fguice-persist-orient-play-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvik%2Fguice-persist-orient-play-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvik%2Fguice-persist-orient-play-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xvik","download_url":"https://codeload.github.com/xvik/guice-persist-orient-play-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246243569,"owners_count":20746311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["guice","orientdb","play"],"created_at":"2024-12-10T10:13:31.285Z","updated_at":"2025-03-29T21:10:19.025Z","avatar_url":"https://github.com/xvik.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Play](https://www.playframework.com/) integration for [guice-persist-orient](https://github.com/xvik/guice-persist-orient) example\n\n### About\n\nSample prepared with activator 1.3.10 for play 2.5.8 using guice-persist-orient 3.2.0 (orient 2.1.23).\n[Official Java seed](https://github.com/playframework/playframework/tree/master/templates/play-java) was used.\n\n[play java docs](https://www.playframework.com/documentation/2.5.x/JavaHome)\n\n### Run\n\nRun app either from IDE or using activator:\n\n```\n$ bin/activator run\n```\n\nOpen [http://localhost:9000](http://localhost:9000) to see default home screen. Useful to check that guice context correctly started.\n\nNext open [http://localhost:9000/samples](http://localhost:9000/samples) to see sample json output - demo of using repository for accessing db.\n\n### Integration\n\nguice-persist-orient dependency ([build.sbt](build.sbt)):\n\n```scala\nlibraryDependencies ++= Seq(\n  javaJdbc,\n  cache,\n  javaWs,\n  \"ru.vyarus\" % \"guice-persist-orient\" % \"3.2.0\"\n)\n```\n\nGuice module (recognized by play convention) ([Module](app/Module.java)):\n\n```java\n @Override\n    public void configure() {\n        // in normal application fb config should be obtained from configuration\n        install(new OrientModule(\"memory:test\", \"admin\", \"admin\"));\n        // initialize scheme from models in package\n        install(new PackageSchemeModule(Sample.class.getPackage().getName()));\n        // enable repositories support\n        install(new RepositoryModule());\n\n        // custom data initializer\n        bind(DataInitializer.class).to(Bootstrap.class);\n        // bind to play lifecycle (to start / stop persistence support)\n        bind(PersistenceLifecycle.class).asEagerSingleton();\n    }\n```\n\n[Sample](app/model/Sample.java) class will be registered as scheme orient.\n\n[Bootstrap](app/Bootstrap.java) will insert 10 `Sample` records on startup (if table is empty)\n\n[PersistentLifecycle](app/PersistentLifecycle) will start/stop orient persistence support (lifecycle hook).\n\nDue to new play guidelines, global object usage is deprecated and now it's recommended to use \n[constructor as startup hook](https://www.playframework.com/documentation/2.5.x/GlobalSettings#Java).\n\n```java\n@Inject\n    public PersistenceLifecycle(final PersistService persist,\n                                final ApplicationLifecycle shutdown) {\n        preloadOrientEngine();\n        persist.start();\n\n        shutdown.addStopHook(() -\u003e {\n            persist.stop();\n            return null;\n        });\n    }\n```\n\n**IMPORTANT** pay attention to [preloadOrientEngine()](app/PersistenceLifecycle.java#L30) method, which is a hack to pre-initialize orient\nand avoid NoClassDefFound errors on start.\n\n### Sample\n\nActual sample is very simple: [SampleController](app/controllers/SampleController.java). It simply loads all records in `Sample` table and renders it as json.\n\n[Repository](app/repositories/SampleRepository.java) used for accessing database:\n\n```\n    @Query(\"select from Sample\")\n    @DetachResult\n    List\u003cSample\u003e allSamples();\n```\n\nNote that `@DetachResult` used to convert returned orient proxies to simple pojos (which play could serialize to json).\nIn normal application, such logic will be in service level or even in controller (for example, using repository.detach(..) method \n(which is inherited from object mixin)). But make sure detaching occur inside transaction (@Transactional)).\n.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxvik%2Fguice-persist-orient-play-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxvik%2Fguice-persist-orient-play-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxvik%2Fguice-persist-orient-play-example/lists"}