Skip to content

Commit

Permalink
Fix README.md formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinand-swoboda committed Nov 7, 2021
1 parent 98f6ee2 commit 2e3868d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
66 changes: 26 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
)
Expand Down Expand Up @@ -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<Dog> 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<Dog> 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:
Expand All @@ -127,16 +124,16 @@ class Repository {

void dogLog() {
List<Dog> 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());
}
}
}
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/main/java/tech/picnic/jolo/Relation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <L> The Java class that the left-hand side of the relation is mapped to.
* @param <R> The Java class that the right-hand side of the relation is mapped to.
Expand Down

0 comments on commit 2e3868d

Please sign in to comment.