diff --git a/README.md b/README.md index be03fcb..50710f4 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,7 @@ dependencies { can additionally call setters to instantiate relationships between entities. - Performs foreign key checks to see whether the defined relationships make sense. - Extra checks on field names of returned records to prevent loading fields from one table as fields of another (no - implicit conversion of `FOO.FIELD` to - `BAR.FIELD`). + implicit conversion of `FOO.FIELD` to `BAR.FIELD`). - Supports circular references. - Supports adding extra (non-table) fields to entities. @@ -59,16 +58,14 @@ dependencies { Let's assume we are working with the following table structure: ```sql -CREATE TABLE Dog -( - id bigserial PRIMARY KEY, - name text, +CREATE TABLE Dog ( + id bigserial PRIMARY KEY, + name text, weight int ); -CREATE TABLE Flea -( - id bigserial PRIMARY KEY, +CREATE TABLE Flea ( + id bigserial PRIMARY KEY, dog_id bigint REFERENCES Dog, weight int ) @@ -107,14 +104,14 @@ Using this library, you can specify how to instantiate the relationship between (i.e., how to fill the `fleas` property of `Dog`): ```java -LoaderFactory createLoaderFactory(){ - var dog=new Entity<>(Tables.DOG,Dog.class); - var flea=new Entity<>(Tables.FLEA,Flea.class); - return LoaderFactory.create(dog) - .oneToMany(dog,flea) - .setManyLeft(Dog::setFleas) - .build(); - } +LoaderFactory createLoaderFactory() { + var dog = new Entity<>(Tables.DOG, Dog.class); + var flea = new Entity<>(Tables.FLEA, Flea.class); + return LoaderFactory.create(dog) + .oneToMany(dog, flea) + .setManyLeft(Dog::setFleas) + .build(); +} ``` Then in the code that executes the query, you can use the loader to instantiate and link POJO classes: @@ -127,16 +124,16 @@ class Repository { void dogLog() { List dogs = context.select() - .from(DOG) - .leftJoin(FLEA) - .on(FLEA.DOG_ID.eq(DOG.ID)) - .collect(LOADER_FACTORY.newLoader()); + .from(DOG) + .leftJoin(FLEA) + .on(FLEA.DOG_ID.eq(DOG.ID)) + .collect(LOADER_FACTORY.newLoader()); for (Dog dog : dogs) { int fleaWeight = dog.getFleas().stream().mapToInt(Flea::getWeight).sum(); LOG.info("%s is %.0f%% fleas", - dog.getName(), - fleaWeight * 100.0 / dog.getWeight()); + dog.getName(), + fleaWeight * 100.0 / dog.getWeight()); } } } @@ -152,37 +149,26 @@ readable as possible. New code must be covered by tests. As a rule of thumb, ove decrease. (There are exceptions to this rule, e.g. when more code is deleted than added.) [bettercodehub-badge]: https://bettercodehub.com/edge/badge/PicnicSupermarket/jolo?branch=master - [bettercodehub-results]: https://bettercodehub.com/results/PicnicSupermarket/jolo - [jolo-image]: https://i.imgur.com/MThi0ae.jpg - [jooq]: https://www.jooq.org - [maven-central-badge]: https://img.shields.io/maven-central/v/tech.picnic.jolo/jolo.svg - [maven-central-browse]: https://repo1.maven.org/maven2/tech/picnic/jolo/ - [new-issue]: https://github.com/PicnicSupermarket/jolo/issues/new - [new-pr]: https://github.com/PicnicSupermarket/jolo/compare - [sonarcloud-badge-bugs]: https://sonarcloud.io/api/project_badges/measure?project=tech.picnic.jolo%3Ajolo&metric=bugs - [sonarcloud-badge-maintainability]: https://sonarcloud.io/api/project_badges/measure?project=tech.picnic.jolo%3Ajolo&metric=sqale_rating - [sonarcloud-badge-quality-gate]: https://sonarcloud.io/api/project_badges/measure?project=tech.picnic.jolo%3Ajolo&metric=alert_status - [sonarcloud-badge-vulnerabilities]: https://sonarcloud.io/api/project_badges/measure?project=tech.picnic.jolo%3Ajolo&metric=vulnerabilities - [sonarcloud-dashboard]: https://sonarcloud.io/dashboard?id=tech.picnic.jolo%3Ajolo - [sonarcloud-measure-reliability]: https://sonarcloud.io/component_measures?id=tech.picnic.jolo%3Ajolo&metric=Reliability - [sonarcloud-measure-security]: https://sonarcloud.io/component_measures?id=tech.picnic.jolo%3Ajolo&metric=Security - [sonarcloud-measure-maintainability]: https://sonarcloud.io/component_measures?id=tech.picnic.jolo%3Ajolo&metric=Maintainability - [travisci-badge]: https://travis-ci.org/PicnicSupermarket/jolo.svg?branch=master - [travisci-builds]: https://travis-ci.org/PicnicSupermarket/jolo + +## todo +- make Loader implement Collector + - test against WMS Insight (locally) +- Implement Copyable to replace prototype pattern or use immutables +- Adopt Java modules diff --git a/src/main/java/tech/picnic/jolo/Relation.java b/src/main/java/tech/picnic/jolo/Relation.java index bed4033..1e11c03 100644 --- a/src/main/java/tech/picnic/jolo/Relation.java +++ b/src/main/java/tech/picnic/jolo/Relation.java @@ -20,7 +20,7 @@ /** * Represents a relation between two {@link Entity entities}. This class is used to extract links - * betweens a data set's rows and set their corresponding objects' references. + * between a data set's rows and set their corresponding objects' references. * * @param The Java class that the left-hand side of the relation is mapped to. * @param The Java class that the right-hand side of the relation is mapped to.