Skip to content

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

@chiaradiamarcelo

Description

@chiaradiamarcelo

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.

Metadata

Metadata

Labels

refactoringCode improvement without behavior change

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions