exasol / test-db-builder-java

Java library for creating and cleaning up test database structures and contents for integration tests
MIT License
2 stars 1 forks source link

Move `DatabaseObjectWriter.write(object)` calls away from constructors #53

Closed chiaradiamarcelo closed 1 year ago

chiaradiamarcelo commented 3 years ago

At the moment, every time we are instantiating a new object to be save in the database, we do the saving inside the constructor as in https://github.com/exasol/test-db-builder-java/blob/main/src/main/java/com/exasol/dbbuilder/dialects/postgres/PostgreSqlSchema.java#L21. This might be dangerous as the objects are not fully created at that point, specially if we keep instantiating fields after this call.

At the same time, we are providing the user of the API a clear entry point for creating these objects (https://github.com/exasol/test-db-builder-java/blob/main/src/main/java/com/exasol/dbbuilder/dialects/postgres/PostgreSqlObjectFactory.java).

We should move this behavior outside the constructor, and probably add it to the factories that create these objects after they are fully initialized.

Another approach might be to provide a builder for each of these objects, and call this behavior in in the buildes, and have the factories call the builders instead of the constructors.

In any case, the constructors should not be part of the public API, as we are providing already a clear entry point for creating objects.

kaklakariada commented 1 year ago

Already implemented before

Implemented in PR https://github.com/exasol/test-db-builder-java/pull/116

Todo

redcatbear commented 1 year ago

Blocked until maintainer back.

ckunki commented 1 year ago

Approved from my side

kaklakariada commented 1 year ago

First part implemented in #116, the rest will be implemented in #119