Skip to content

Fix Sonar problems #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public void saveSingleCustomer(final SpringState state)
customerRepository2.findAll().forEach(
customer ->
{
customer.setFirstName("Another" + customer.getFirstName());
customer.setLastName("Another" + customer.getLastName());
this.changeCustomerName(customer);
customerRepository2.save(customer);
});
}
Expand All @@ -42,8 +41,7 @@ protected void saveCustomerInForEach(final SpringState state, final int entityCo
customerRepository2.findAll().forEach(
customer ->
{
customer.setFirstName("Another" + customer.getFirstName());
customer.setLastName("Another" + customer.getLastName());
this.changeCustomerName(customer);
customerRepository2.save(customer);
});
}
Expand All @@ -62,13 +60,14 @@ protected void saveCustomerInSaveAll(final SpringState state, final int entityCo

final CustomerRepository customerRepository2 = state.getBean(CustomerRepository.class);
final Iterable<Customer> all = customerRepository2.findAll();
all.forEach(
customer ->
{
customer.setFirstName("Another" + customer.getFirstName());
customer.setLastName("Another" + customer.getLastName());
});
all.forEach(this::changeCustomerName);

customerRepository2.saveAll(all);
}

private void changeCustomerName(final Customer customer)
{
customer.setFirstName("Another" + customer.getFirstName());
customer.setLastName("Another" + customer.getLastName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* In contrast to {@link CustomNameScript} the version of this script is defined by
* <b>the name of the class defines the version</b>.
*/
@SuppressWarnings("checkstyle:TypeName")
@SuppressWarnings({"checkstyle:TypeName", "java:S101"})
@Component
public class v1_0_0_Init extends ReflectiveDataMigrationScript
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -44,7 +45,7 @@ static void clearPreviousData()
void checkPossibilityToSimplyStartAndRestartApplication()
{
this.configuration.getStorageInstance().stop();
ComplexDemoApplication.main(new String[]{});
Assertions.assertDoesNotThrow(() -> ComplexDemoApplication.main(new String[]{}));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -39,6 +40,6 @@ void checkPossibilityToSimplyStartAndRestartApplication()
{
this.invoiceConfiguration.getStorageInstance().stop();
this.personConfiguration.getStorageInstance().stop();
DualStorageDemoApplication.main(new String[]{});
Assertions.assertDoesNotThrow(() -> DualStorageDemoApplication.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -34,6 +35,6 @@ static void clearPreviousData()
void checkPossibilityToSimplyStartAndRestartApplication()
{
this.configuration.getStorageInstance().stop();
LazyDemoApplication.main(new String[]{});
Assertions.assertDoesNotThrow(() -> LazyDemoApplication.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -34,6 +35,6 @@ static void clearPreviousData()
void checkPossibilityToSimplyStartAndRestartApplication()
{
this.configuration.getStorageInstance().stop();
SimpleDemoApplication.main(new String[]{});
Assertions.assertDoesNotThrow(() -> SimpleDemoApplication.main(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private EntityManagerSupplierRepositoryListPair createEclipseStoreRepositoriesFr
);

return new EntityManagerSupplierRepositoryListPair(
() -> entityManagerFactory.createEntityManager(),
entityManagerFactory::createEntityManager,
repositoryList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReadWriteLock;


@SuppressWarnings("java:S119")
public interface StorageCommunicator
{
ReadWriteLock getReadWriteLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void writeValueOfField(
}
}

private IllegalAccessException createIllegalAccessToField(final Field field) throws IllegalAccessException
private IllegalAccessException createIllegalAccessToField(final Field field)
{
return new IllegalAccessException(
("Could not access field %s#%s. Make sure that the module is open e.g. with following VM option: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.data.repository.core.RepositoryMetadata;

import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository;
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCustomRepository;
Expand Down Expand Up @@ -138,10 +137,4 @@ protected Collection<Class<?>> getIdentifyingTypes()
LazyEclipseStoreListCrudRepository.class
);
}

@Override
protected boolean useRepositoryConfiguration(final RepositoryMetadata metadata)
{
return super.useRepositoryConfiguration(metadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.lang.reflect.Field;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;

import org.eclipse.serializer.collections.HashEnum;
Expand Down Expand Up @@ -77,7 +76,6 @@ final class Default<T> implements SpringDataEclipseStoreLazy<T>
private transient ObjectSwizzling loader;
private transient WorkingCopier<T> copier;
private transient boolean isStored;
private final transient ReentrantLock usageMarksLock = new ReentrantLock();
private final transient HashEnum<Object> usageMarks = HashEnum.New();

private Default(final Lazy<T> lazySubject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public EclipseStoreFetchableFluentQuery(
@Override
public FetchableFluentQuery<S> sortBy(final Sort sort)
{
return new EclipseStoreFetchableFluentQuery(
return new EclipseStoreFetchableFluentQuery<>(
this.copier,
this.example,
this.domainClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ public boolean evaluate(final T object)
return this.predicate.test(object);
}

private <T> Predicate<ExampleMatcher.PropertySpecifier> createPredicateForSpecifier(
@SuppressWarnings("unchecked")
private <E> Predicate<ExampleMatcher.PropertySpecifier> createPredicateForSpecifier(
final Example<S> example,
final T entity)
final E entity)
{
return specifier ->
{
final ReflectedField<T, Object> reflectedField =
(ReflectedField<T, Object>)ReflectedField.createReflectedField(
final ReflectedField<E, Object> reflectedField =
(ReflectedField<E, Object>)ReflectedField.createReflectedField(
example.getProbeType(),
specifier.getPath());

final Object exampleValue = reflectedField.readValue((T)example.getProbe());
final Object exampleValue = reflectedField.readValue((E)example.getProbe());
final Optional<Object> transformedExampledValue =
specifier.getPropertyValueTransformer().apply(Optional.ofNullable(exampleValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

public final class EclipseStoreMigrator
{
@SuppressWarnings("java:S2386")
public static final VersionAgnosticMigrationScript<?, ?>[] SCRIPTS =
new VersionAgnosticMigrationScript[]{
new v2_0_0_InitializeVersioning(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void loggedMigrate(final Context<VersionedRoot, MigrationEmbeddedStorageM
LOG.warn("Dropping entities {} because there is no repository in the new root.", entityName);
return;
}
entities.forEach(entity -> entityData.ensureEntityAndReturnObjectsToStore(entity));
entities.forEach(entityData::ensureEntityAndReturnObjectsToStore);
context.getStorageManager().getNativeStorageManager().storeAll(entityData.getObjectsToStore());
LOG.info("Migrated entities {}.", entityName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.eclipse.serializer.reference.Lazy;
Expand Down Expand Up @@ -187,8 +188,8 @@ public Collection<Object> removeAllEntitiesAndReturnObjectsToStore()
return this.getObjectsToStore();
}

public HashMap<ID, Lazy<T>> getNativeLazyEntitiesById()
public Map<ID, Lazy<T>> getNativeLazyEntitiesById()
{
return entitiesById;
return this.entitiesById;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

import jakarta.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
Expand All @@ -47,7 +44,6 @@
public class EclipseStoreRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
extends RepositoryFactoryBeanSupport<T, S, ID>
{
private static final Logger LOG = LoggerFactory.getLogger(EclipseStoreRepositoryFactoryBean.class);
private Class<?> configurationClass;
@Autowired
private List<EclipseStoreClientConfiguration> configurations;
Expand Down Expand Up @@ -90,30 +86,19 @@ protected RepositoryFactorySupport createRepositoryFactory()
* should be injected into the {@link #configurations} and get returned.
* </p>
*/
@SuppressWarnings("java:S1872")
private EclipseStoreClientConfiguration getSuitableConfiguration()
{
if(this.configurationClass == null && this.configurations.size() == 1)
{
return this.configurations.get(0);
}
final Optional<EclipseStoreClientConfiguration> definedConfiguration = this.configurations

return this.configurations
.stream()
.filter(
configuration ->
{
if(this.configurationClass != null)
{
return this.configurationClass.getName()
.equals(ClassUtils.getUserClass(configuration).getName());
}
return false;
}
)
.findAny();
if(definedConfiguration.isEmpty())
{
throw new NoSuchBeanDefinitionException(this.configurationClass);
}
return definedConfiguration.get();
.filter(configuration -> this.configurationClass != null
&& this.configurationClass.getName().equals(ClassUtils.getUserClass(configuration).getName()))
.findAny()
.orElseThrow(() -> new NoSuchBeanDefinitionException(this.configurationClass));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private <S extends T> void uncachedStore(final Collection<S> entities)
* and
* would be stuck in a deadlock.
*/
private <S extends T> boolean isMergeParallelizable()
private boolean isMergeParallelizable()
{
return !this.idManager.hasIdField();
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public Optional<T> findById(@Nonnull final ID id)
{
return this.storage.getReadWriteLock().read(
() -> this.idManager.findById(id)
.map(foundEntity -> this.copier.copy(foundEntity))
.map(this.copier::copy)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
public abstract class AbstractRegisteringCopier implements RegisteringObjectCopier
{
private final EclipseSerializerRegisteringCopier actualCopier;
private ClassLoader currentClassLoader;

protected AbstractRegisteringCopier(
final SupportedChecker supportedChecker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import software.xdev.spring.data.eclipse.store.repository.root.data.version.ReflectiveDataMigrationScript;


@SuppressWarnings("checkstyle:TypeName")
@SuppressWarnings({"checkstyle:TypeName", "java:S101"})
public class v1_0_0_Init extends ReflectiveDataMigrationScript
{
private final PersistedEntityRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot;
import software.xdev.spring.data.eclipse.store.repository.root.data.version.ReflectiveDataMigrationScript;

@SuppressWarnings("checkstyle:TypeName")

@SuppressWarnings({"checkstyle:TypeName", "java:S101"})
@Component
public class v1_0_0_Init extends ReflectiveDataMigrationScript
{
private final PersistedEntityRepository
repository;
private final PersistedEntityRepository repository;

public v1_0_0_Init(@Autowired final PersistedEntityRepository repository)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import software.xdev.spring.data.eclipse.store.repository.root.data.version.ReflectiveDataMigrationScript;


@SuppressWarnings("checkstyle:TypeName")
@SuppressWarnings({"checkstyle:TypeName", "java:S101"})
@Component
public class v1_0_0_Init extends ReflectiveDataMigrationScript
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void saveBulkWithAutoIdInt(@Autowired final CustomerWithIdIntRepository customer
this.configuration,
() -> {
Assertions.assertEquals(2, customerRepository.count());
final Iterable<CustomerWithIdInt> all = customerRepository.findAll();
customerRepository.findAll();

final Optional<CustomerWithIdInt> loadedCustomer1 = customerRepository.findById(1);
Assertions.assertTrue(loadedCustomer1.isPresent());
Expand Down
Loading
Loading