You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@polygene.apache.org by Prince Arora <ar...@gmail.com> on 2016/08/27 21:45:20 UTC

Entity Store

Hi Everyone,

I just started using zest and creating an application with MongoDB as data
storage. I have gone through the documentations Its all good i understood
the consent of application, mixins, concerns and all. But not sure how i
can configure and entity store using Mongodb extension. How do i define the
mongo connections configurations for Mongo assembler?

I have gone through Zest core apis and documents and seems a good framework
to develop applications. The only thing that can be a pain is the
Application assembly. As the applications goes bigger the assembly will get
more harder to manage for developers as we have to add all entities,
concerns and everything we are using inside our application/module. Are we
developing any configurations system to assemble applications or do we have
one? And also we can make it easier if we add an option register these
composites with package name. Like for entity one can give a package name
where we can scan all the entities and register them for that module. It is
just a suggestion though. Let me know what others think about this.

I will keep working on this and will write if i find any other issue or
suggestions. Since this is my first contribution to a open source project i
will not be much of help in starting and plus i am also learning zest from
scratch but i will try my best to contribute as much as i can.


Thanks,

Re: Entity Store

Posted by Prince Arora <ar...@gmail.com>.
Thanks, Niclas

On Sun, Aug 28, 2016 at 6:20 AM, Niclas Hedhman <ni...@hedhman.org> wrote:

> Hi,
> In 2.1 and earlier, the assembly was quite tedious and error-prone. For the
> 'develop' branch (to become 3.0), we are working at making it easier.
>
> 1. The LayeredApplicationAssembler with its associated LayerAssembler and
> ModuleAssembler, tries to make it a lot easier (and keep it a lot neater)
> to create layered application assembly. See
> https://zest.apache.org/java/2.1/core-bootstrap-assembly.html and find
> section "Layered Application Assembler (RECOMMENDED)"
>
> 2. I am currently working on a Yeoman generator, which will set up the
> application skeleton using the LayeredApplicationAssembler mentioned above.
> Answer a couple of questions and you have a project structure, build system
> and possibly an sample application created for you. This needs help to test
> out and expand. See below what is generated at the moment, incl a "heroes"
> webapp sample
>
> 3. In general, I am against scanning for classes, as it both slows
> everything down and that it becomes unpredictable and fragile.
>
>
> Ok, so for MongoDB you do two things,
>
> 1. You need to use an assembler and do something like this;
> public class MongoDBStorageModule
>     implements ModuleAssembler
> {
>     public static final String NAME = "MongoDB Storage Module";
>     private final ModuleAssembly configModule;
>
>     public MongoDBStorageModule( ModuleAssembly configModule )
>     {
>         this.configModule = configModule;
>     }
>
>     @Override
>     public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly
> module )
>         throws AssemblyException
>     {
>         module.withDefaultUnitOfWorkFactory();
>         new MongoDBEntityStoreAssembler()
>             .visibleIn( Visibility.application  )
>             .withConfig( configModule, Visibility.application )
>             .identifiedBy( "MongoDBstore" )
>             .assemble( module );
>         return module;
>     }
> }
> (The above is generated in my new Yeoman generator)
>
> The identifiedBy("MongoDBstore") is the key to find the bootstrap
> configuration for the service.
> If you look at
> org.apache.zest.entitystore.mongodb.MongoEntityStoreConfiguration it
> contains the configuration that has been made available.
> Configuration can be initialized from files in the classpath, and the
> location is from the identifiedBy() above. We are trying to support
> properties, json, yaml and xml files as the configuration bootstrap format.
> So you could create a MongoDBstore.json file with the following content;
>
> {
>     "hostname" : "n1.hedhman.org",
>     "port" : 27017,
>     "username" : "mongo",
>     "password" : "secret",
>     "database" : "heroes_app",
>     "collection" : "heroes",
>     "writeConcern" : "NORMAL"
> }
>
>
> I just realize that the nodes() property in the configuration can probably
> not be initialized from file at the moment, as it takes a ServerAddress
> list as argument. That should be fixed...
>
> A general note though; Be careful with MongoDB... It is not particularly
> resilient to failures.
>
> Hope this helps.
>
> -o-o-o-o-o-
>
> niclas-249:heroes2 niclas$ find .
> .
> ./app
> ./app/build.gradle
> ./app/src
> ./app/src/main
> ./app/src/main/java
> ./app/src/main/java/heroes2
> ./app/src/main/java/heroes2/app
> ./app/src/main/java/heroes2/app/Heroes.java
> ./app/src/main/webapp
> ./app/src/main/webapp/app
> ./app/src/main/webapp/app/app.component.css
> ./app/src/main/webapp/app/app.component.js
> ./app/src/main/webapp/app/app.component.js.map
> ./app/src/main/webapp/app/app.component.ts
> ./app/src/main/webapp/app/dashboard.component.css
> ./app/src/main/webapp/app/dashboard.component.html
> ./app/src/main/webapp/app/dashboard.component.js
> ./app/src/main/webapp/app/dashboard.component.js.map
> ./app/src/main/webapp/app/dashboard.component.ts
> ./app/src/main/webapp/app/hero-detail.component.css
> ./app/src/main/webapp/app/hero-detail.component.html
> ./app/src/main/webapp/app/hero-detail.component.js
> ./app/src/main/webapp/app/hero-detail.component.js.map
> ./app/src/main/webapp/app/hero-detail.component.ts
> ./app/src/main/webapp/app/hero.js
> ./app/src/main/webapp/app/hero.js.map
> ./app/src/main/webapp/app/hero.service.js
> ./app/src/main/webapp/app/hero.service.js.map
> ./app/src/main/webapp/app/hero.service.ts
> ./app/src/main/webapp/app/hero.ts
> ./app/src/main/webapp/app/heroes.component.css
> ./app/src/main/webapp/app/heroes.component.html
> ./app/src/main/webapp/app/heroes.component.js
> ./app/src/main/webapp/app/heroes.component.js.map
> ./app/src/main/webapp/app/heroes.component.ts
> ./app/src/main/webapp/app/main.js
> ./app/src/main/webapp/app/main.js.map
> ./app/src/main/webapp/app/main.ts
> ./app/src/main/webapp/app/mock-heroes.js
> ./app/src/main/webapp/app/mock-heroes.js.map
> ./app/src/main/webapp/app/mock-heroes.ts
> ./app/src/main/webapp/index.html
> ./app/src/main/webapp/styles.css
> ./app/src/main/webapp/WEB-INF
> ./app/src/main/webapp/WEB-INF/web.xml
> ./bootstrap
> ./bootstrap/build.gradle
> ./bootstrap/src
> ./bootstrap/src/main
> ./bootstrap/src/main/java
> ./bootstrap/src/main/java/heroes2
> ./bootstrap/src/main/java/heroes2/bootstrap
> ./bootstrap/src/main/java/heroes2/bootstrap/config
> ./bootstrap/src/main/java/heroes2/bootstrap/config/ConfigModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/config/ConfigurationLayer.java
> ./bootstrap/src/main/java/heroes2/bootstrap/connectivity
> ./bootstrap/src/main/java/heroes2/bootstrap/connectivity/
> ConnectivityLayer.java
> ./bootstrap/src/main/java/heroes2/bootstrap/connectivity/RestApiModule.
> java
> ./bootstrap/src/main/java/heroes2/bootstrap/domain
> ./bootstrap/src/main/java/heroes2/bootstrap/domain/CrudModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/domain/DomainLayer.java
> ./bootstrap/src/main/java/heroes2/bootstrap/domain/SecurityModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/HeroesApplicationAssembler.
> java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> FileConfigurationModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> InfrastructureLayer.java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> JacksonSerializationModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> MongoDBStorageModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> NoCachingModule.java
> ./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/
> RdfIndexingModule.java
> ./build.gradle
> ./gradle
> ./gradle/wrapper
> ./gradle/wrapper/gradle-wrapper.jar
> ./gradle/wrapper/gradle-wrapper.properties
> ./gradlew
> ./gradlew.bat
> ./model
> ./model/build.gradle
> ./model/src
> ./model/src/main
> ./model/src/main/java
> ./model/src/main/java/heroes2
> ./model/src/main/java/heroes2/model
> ./model/src/main/java/heroes2/model/heroes
> ./model/src/main/java/heroes2/model/heroes/Hero.java
> ./model/src/main/java/heroes2/model/security
> ./model/src/main/java/heroes2/model/security/
> HardcodedSecurityRepositoryMixin.java
> ./model/src/main/java/heroes2/model/security/SecurityRepository.java
> ./rest
> ./rest/build.gradle
> ./rest/src
> ./rest/src/main
> ./rest/src/main/java
> ./rest/src/main/java/heroes2
> ./rest/src/main/java/heroes2/rest
> ./rest/src/main/java/heroes2/rest/security
> ./rest/src/main/java/heroes2/rest/security/SimpleEnroler.java
> ./rest/src/main/java/heroes2/rest/security/SimpleVerifier.java
> ./settings.gradle
>
>
> On Sun, Aug 28, 2016 at 5:45 AM, Prince Arora <ar...@gmail.com>
> wrote:
>
> > Hi Everyone,
> >
> > I just started using zest and creating an application with MongoDB as
> data
> > storage. I have gone through the documentations Its all good i understood
> > the consent of application, mixins, concerns and all. But not sure how i
> > can configure and entity store using Mongodb extension. How do i define
> the
> > mongo connections configurations for Mongo assembler?
> >
> > I have gone through Zest core apis and documents and seems a good
> framework
> > to develop applications. The only thing that can be a pain is the
> > Application assembly. As the applications goes bigger the assembly will
> get
> > more harder to manage for developers as we have to add all entities,
> > concerns and everything we are using inside our application/module. Are
> we
> > developing any configurations system to assemble applications or do we
> have
> > one? And also we can make it easier if we add an option register these
> > composites with package name. Like for entity one can give a package name
> > where we can scan all the entities and register them for that module. It
> is
> > just a suggestion though. Let me know what others think about this.
> >
> > I will keep working on this and will write if i find any other issue or
> > suggestions. Since this is my first contribution to a open source
> project i
> > will not be much of help in starting and plus i am also learning zest
> from
> > scratch but i will try my best to contribute as much as i can.
> >
> >
> > Thanks,
> >
>
>
>
> --
> Niclas Hedhman, Software Developer
> http://zest.apache.org - New Energy for Java
>

Re: Entity Store

Posted by Niclas Hedhman <ni...@hedhman.org>.
Hi,
In 2.1 and earlier, the assembly was quite tedious and error-prone. For the
'develop' branch (to become 3.0), we are working at making it easier.

1. The LayeredApplicationAssembler with its associated LayerAssembler and
ModuleAssembler, tries to make it a lot easier (and keep it a lot neater)
to create layered application assembly. See
https://zest.apache.org/java/2.1/core-bootstrap-assembly.html and find
section "Layered Application Assembler (RECOMMENDED)"

2. I am currently working on a Yeoman generator, which will set up the
application skeleton using the LayeredApplicationAssembler mentioned above.
Answer a couple of questions and you have a project structure, build system
and possibly an sample application created for you. This needs help to test
out and expand. See below what is generated at the moment, incl a "heroes"
webapp sample

3. In general, I am against scanning for classes, as it both slows
everything down and that it becomes unpredictable and fragile.


Ok, so for MongoDB you do two things,

1. You need to use an assembler and do something like this;
public class MongoDBStorageModule
    implements ModuleAssembler
{
    public static final String NAME = "MongoDB Storage Module";
    private final ModuleAssembly configModule;

    public MongoDBStorageModule( ModuleAssembly configModule )
    {
        this.configModule = configModule;
    }

    @Override
    public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly
module )
        throws AssemblyException
    {
        module.withDefaultUnitOfWorkFactory();
        new MongoDBEntityStoreAssembler()
            .visibleIn( Visibility.application  )
            .withConfig( configModule, Visibility.application )
            .identifiedBy( "MongoDBstore" )
            .assemble( module );
        return module;
    }
}
(The above is generated in my new Yeoman generator)

The identifiedBy("MongoDBstore") is the key to find the bootstrap
configuration for the service.
If you look at
org.apache.zest.entitystore.mongodb.MongoEntityStoreConfiguration it
contains the configuration that has been made available.
Configuration can be initialized from files in the classpath, and the
location is from the identifiedBy() above. We are trying to support
properties, json, yaml and xml files as the configuration bootstrap format.
So you could create a MongoDBstore.json file with the following content;

{
    "hostname" : "n1.hedhman.org",
    "port" : 27017,
    "username" : "mongo",
    "password" : "secret",
    "database" : "heroes_app",
    "collection" : "heroes",
    "writeConcern" : "NORMAL"
}


I just realize that the nodes() property in the configuration can probably
not be initialized from file at the moment, as it takes a ServerAddress
list as argument. That should be fixed...

A general note though; Be careful with MongoDB... It is not particularly
resilient to failures.

Hope this helps.

-o-o-o-o-o-

niclas-249:heroes2 niclas$ find .
.
./app
./app/build.gradle
./app/src
./app/src/main
./app/src/main/java
./app/src/main/java/heroes2
./app/src/main/java/heroes2/app
./app/src/main/java/heroes2/app/Heroes.java
./app/src/main/webapp
./app/src/main/webapp/app
./app/src/main/webapp/app/app.component.css
./app/src/main/webapp/app/app.component.js
./app/src/main/webapp/app/app.component.js.map
./app/src/main/webapp/app/app.component.ts
./app/src/main/webapp/app/dashboard.component.css
./app/src/main/webapp/app/dashboard.component.html
./app/src/main/webapp/app/dashboard.component.js
./app/src/main/webapp/app/dashboard.component.js.map
./app/src/main/webapp/app/dashboard.component.ts
./app/src/main/webapp/app/hero-detail.component.css
./app/src/main/webapp/app/hero-detail.component.html
./app/src/main/webapp/app/hero-detail.component.js
./app/src/main/webapp/app/hero-detail.component.js.map
./app/src/main/webapp/app/hero-detail.component.ts
./app/src/main/webapp/app/hero.js
./app/src/main/webapp/app/hero.js.map
./app/src/main/webapp/app/hero.service.js
./app/src/main/webapp/app/hero.service.js.map
./app/src/main/webapp/app/hero.service.ts
./app/src/main/webapp/app/hero.ts
./app/src/main/webapp/app/heroes.component.css
./app/src/main/webapp/app/heroes.component.html
./app/src/main/webapp/app/heroes.component.js
./app/src/main/webapp/app/heroes.component.js.map
./app/src/main/webapp/app/heroes.component.ts
./app/src/main/webapp/app/main.js
./app/src/main/webapp/app/main.js.map
./app/src/main/webapp/app/main.ts
./app/src/main/webapp/app/mock-heroes.js
./app/src/main/webapp/app/mock-heroes.js.map
./app/src/main/webapp/app/mock-heroes.ts
./app/src/main/webapp/index.html
./app/src/main/webapp/styles.css
./app/src/main/webapp/WEB-INF
./app/src/main/webapp/WEB-INF/web.xml
./bootstrap
./bootstrap/build.gradle
./bootstrap/src
./bootstrap/src/main
./bootstrap/src/main/java
./bootstrap/src/main/java/heroes2
./bootstrap/src/main/java/heroes2/bootstrap
./bootstrap/src/main/java/heroes2/bootstrap/config
./bootstrap/src/main/java/heroes2/bootstrap/config/ConfigModule.java
./bootstrap/src/main/java/heroes2/bootstrap/config/ConfigurationLayer.java
./bootstrap/src/main/java/heroes2/bootstrap/connectivity
./bootstrap/src/main/java/heroes2/bootstrap/connectivity/ConnectivityLayer.java
./bootstrap/src/main/java/heroes2/bootstrap/connectivity/RestApiModule.java
./bootstrap/src/main/java/heroes2/bootstrap/domain
./bootstrap/src/main/java/heroes2/bootstrap/domain/CrudModule.java
./bootstrap/src/main/java/heroes2/bootstrap/domain/DomainLayer.java
./bootstrap/src/main/java/heroes2/bootstrap/domain/SecurityModule.java
./bootstrap/src/main/java/heroes2/bootstrap/HeroesApplicationAssembler.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/FileConfigurationModule.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/InfrastructureLayer.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/JacksonSerializationModule.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/MongoDBStorageModule.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/NoCachingModule.java
./bootstrap/src/main/java/heroes2/bootstrap/infrastructure/RdfIndexingModule.java
./build.gradle
./gradle
./gradle/wrapper
./gradle/wrapper/gradle-wrapper.jar
./gradle/wrapper/gradle-wrapper.properties
./gradlew
./gradlew.bat
./model
./model/build.gradle
./model/src
./model/src/main
./model/src/main/java
./model/src/main/java/heroes2
./model/src/main/java/heroes2/model
./model/src/main/java/heroes2/model/heroes
./model/src/main/java/heroes2/model/heroes/Hero.java
./model/src/main/java/heroes2/model/security
./model/src/main/java/heroes2/model/security/HardcodedSecurityRepositoryMixin.java
./model/src/main/java/heroes2/model/security/SecurityRepository.java
./rest
./rest/build.gradle
./rest/src
./rest/src/main
./rest/src/main/java
./rest/src/main/java/heroes2
./rest/src/main/java/heroes2/rest
./rest/src/main/java/heroes2/rest/security
./rest/src/main/java/heroes2/rest/security/SimpleEnroler.java
./rest/src/main/java/heroes2/rest/security/SimpleVerifier.java
./settings.gradle


On Sun, Aug 28, 2016 at 5:45 AM, Prince Arora <ar...@gmail.com>
wrote:

> Hi Everyone,
>
> I just started using zest and creating an application with MongoDB as data
> storage. I have gone through the documentations Its all good i understood
> the consent of application, mixins, concerns and all. But not sure how i
> can configure and entity store using Mongodb extension. How do i define the
> mongo connections configurations for Mongo assembler?
>
> I have gone through Zest core apis and documents and seems a good framework
> to develop applications. The only thing that can be a pain is the
> Application assembly. As the applications goes bigger the assembly will get
> more harder to manage for developers as we have to add all entities,
> concerns and everything we are using inside our application/module. Are we
> developing any configurations system to assemble applications or do we have
> one? And also we can make it easier if we add an option register these
> composites with package name. Like for entity one can give a package name
> where we can scan all the entities and register them for that module. It is
> just a suggestion though. Let me know what others think about this.
>
> I will keep working on this and will write if i find any other issue or
> suggestions. Since this is my first contribution to a open source project i
> will not be much of help in starting and plus i am also learning zest from
> scratch but i will try my best to contribute as much as i can.
>
>
> Thanks,
>



-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Re: Entity Store

Posted by Prince Arora <ar...@gmail.com>.
Hi Paul,

Thank you for the reply, And I was suffering from Viral Fever thats why I
was not able to reply you.
ClassScanner is the one i was looking for. I will have a look.

Thanks

On Mon, Sep 5, 2016 at 4:49 AM, Paul Merlin <pa...@apache.org> wrote:

> Le 2016-08-27 14:45, Prince Arora a écrit :
>
>> Hi Everyone,
>>
>> And also we can make it easier if we add an option register these
>> composites with package name. Like for entity one can give a package name
>> where we can scan all the entities and register them for that module. It
>> is
>> just a suggestion though. Let me know what others think about this.
>>
>
> Hi Prince,
>
> We have something to do that. It is called ClassScanner.
> It allows you to declare Entities/Values etc.. in batches in your
> Application assembly.
> You can use it to look up all classes matching some criteria from packages.
> Have a look at ClassScannerTest, it shows how to use it.
>
> HTH
>
>

Re: Entity Store

Posted by Paul Merlin <pa...@apache.org>.
Le 2016-08-27 14:45, Prince Arora a �crit�:
> Hi Everyone,
> 
> And also we can make it easier if we add an option register these
> composites with package name. Like for entity one can give a package 
> name
> where we can scan all the entities and register them for that module. 
> It is
> just a suggestion though. Let me know what others think about this.

Hi Prince,

We have something to do that. It is called ClassScanner.
It allows you to declare Entities/Values etc.. in batches in your 
Application assembly.
You can use it to look up all classes matching some criteria from 
packages.
Have a look at ClassScannerTest, it shows how to use it.

HTH