Skip to content

Commit

Permalink
fix(EntityRepository): correct constructor check (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Jun 15, 2024
1 parent e5c334b commit b3f7ec1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public interface EntityRepository<V extends Entity> {
* @param entityClass The class to check for the constructor.
* @throws NoSuchConstructorException If no suitable constructor is found.
*/
default void checkForConstructorWithSingleVarargString(@NotNull Class<V> entityClass) throws NoSuchConstructorException {
default void checkForConstructorWithSingleString(@NotNull Class<V> entityClass) throws NoSuchConstructorException {
Constructor<?>[] constructors = entityClass.getConstructors();

for (Constructor<?> constructor : constructors) {
Parameter[] parameters = constructor.getParameters();
if (parameters.length == 1 && parameters[0].getType().equals(String.class) && parameters[0].isVarArgs()) {
if (parameters.length == 1 && parameters[0].getType().equals(String.class)) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CompletableFuture<V> load(@NotNull String entityId) {

if (document != null) {
try {
this.checkForConstructorWithSingleVarargString(this.entityClass);
this.checkForConstructorWithSingleString(this.entityClass);
V entity = this.entityClass.getConstructor(String.class).newInstance(entityId);

for (Map.Entry<String, Object> key : document.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public CompletableFuture<V> load(@NotNull String entityId) {
return null;
}
if (resultSet.next()) {
this.checkForConstructorWithSingleVarargString(this.entityClass);
this.checkForConstructorWithSingleString(this.entityClass);
V entity = this.entityClass.getConstructor(String.class).newInstance(entityId);
for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
String columnName = resultSet.getMetaData().getColumnName(i + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CompletableFuture<V> load(@NotNull String entityId) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);

try {
this.checkForConstructorWithSingleVarargString(this.entityClass);
this.checkForConstructorWithSingleString(this.entityClass);
V entity = this.entityClass.getConstructor(String.class).newInstance(entityId);
for (String key : config.getKeys(false)) {
entity.setValue(key, config.get(key));
Expand Down

0 comments on commit b3f7ec1

Please sign in to comment.