Make entities final to perhaps prevent lazy loading?

This commit is contained in:
TheOtherP 2023-01-06 11:38:17 +01:00
parent c313df320a
commit c2ec5a43f4
20 changed files with 44 additions and 46 deletions

View File

@ -18,7 +18,7 @@ import java.sql.Timestamp;
@Table(name = "persistent_logins")
@Data
@ReflectionMarker
public class PersistentLoginsEntity {
public final class PersistentLoginsEntity {
@Id
@NotNull

View File

@ -30,7 +30,7 @@ import java.time.temporal.ChronoUnit;
@ReflectionMarker
@Entity
@Table(name = "indexernzbdownload", indexes = {@Index(name = "NZB_DOWNLOAD_EXT_ID", columnList = "EXTERNAL_ID")})
public class FileDownloadEntity {
public final class FileDownloadEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -27,7 +27,7 @@ import java.util.Objects;
@Entity
@NoArgsConstructor
@Table(name = "indexerapiaccess")
public class IndexerApiAccessEntity {
public final class IndexerApiAccessEntity {
@Id
@SequenceGenerator(allocationSize = 1, name = "INDEXERAPIACCESS_SEQ")

View File

@ -26,7 +26,7 @@ import java.time.Instant;
@Entity
@NoArgsConstructor
@Table(name = "indexerapiaccess_short")
public class IndexerApiAccessEntityShort {
public final class IndexerApiAccessEntityShort {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)

View File

@ -18,12 +18,12 @@ import java.util.Objects;
@ReflectionMarker
@Entity
@Table(name = "indexer")
public class IndexerEntity {
public final class IndexerEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SequenceGenerator(allocationSize = 1, name = "INDEXER_SEQ")
protected int id;
private int id;
@Column(unique = true)
private String name;

View File

@ -21,7 +21,7 @@ import java.util.Objects;
@ReflectionMarker
@Entity
@Table(name = "indexersearch", indexes = {@Index(name = "ISINDEX1", columnList = "INDEXER_ENTITY_ID"), @Index(name = "ISINDEX2", columnList = "SEARCH_ENTITY_ID")})
public class IndexerSearchEntity {
public final class IndexerSearchEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)

View File

@ -18,7 +18,7 @@ import java.time.Instant;
@Entity
@Table(name = "indexerlimit")
public class IndexerLimit {
public final class IndexerLimit {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -17,7 +17,7 @@ import java.util.Optional;
@Entity
@Table(name = "movieinfo")
public class MovieInfo implements Comparable<MovieInfo> {
public final class MovieInfo implements Comparable<MovieInfo> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -17,7 +17,7 @@ import java.util.Optional;
@ReflectionMarker
@Entity
@Table(name = "tvinfo")
public class TvInfo implements Comparable<TvInfo> {
public final class TvInfo implements Comparable<TvInfo> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -13,7 +13,7 @@ import org.nzbhydra.springnative.ReflectionMarker;
@ReflectionMarker
@Entity
@Table(name = "shownnews")
public class ShownNews {
public final class ShownNews {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -19,7 +19,7 @@ import java.time.Instant;
@ReflectionMarker
@Entity
@Table(name = "notification")
public class NotificationEntity {
public final class NotificationEntity {
public enum MessageType {
INFO,

View File

@ -32,7 +32,7 @@ import java.util.Objects;
@ReflectionMarker
@Entity
@NoArgsConstructor
public class IdentifierKeyValuePair {
public final class IdentifierKeyValuePair {
@Id
@GeneratedValue

View File

@ -46,7 +46,7 @@ import java.util.Set;
@ReflectionMarker
@Entity
@Table(name = "search")
public class SearchEntity {
public final class SearchEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -45,10 +45,10 @@ import java.time.Instant;
@Entity
@Getter
@Table(name = "searchresult"
, indexes = {
@Index(columnList = "indexer_id,indexerguid", unique = true)}
, indexes = {
@Index(columnList = "indexer_id,indexerguid", unique = true)}
)
public class SearchResultEntity {
public final class SearchResultEntity {
@GenericGenerator(
@ -66,31 +66,31 @@ public class SearchResultEntity {
@Id
@GeneratedValue(generator = "search-result-sequence", strategy = GenerationType.SEQUENCE)
@JsonSerialize(using = ToStringSerializer.class) //JS cannot handle long. We don't need to calculate with this so string is fine to not lose any digits
protected long id;
private long id;
@ManyToOne
@NotNull
@OnDelete(action = OnDeleteAction.CASCADE)
protected IndexerEntity indexer;
private IndexerEntity indexer;
@Convert(converter = org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters.InstantConverter.class)
protected Instant firstFound;
private Instant firstFound;
@NotNull
@Column(length = 4000)
protected String title;
private String title;
@Column(name = "indexerguid")
@NotNull
protected String indexerGuid;
private String indexerGuid;
@Column(length = 4000)
protected String link;
private String link;
@Column(length = 4000)
protected String details;
private String details;
@Enumerated(EnumType.STRING)
protected DownloadType downloadType;
private DownloadType downloadType;
@Convert(converter = org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters.InstantConverter.class)
protected Instant pubDate;
private Instant pubDate;
@Column(name = "INDEXERSEARCHENTITY")
private Integer indexerSearchEntityId;

View File

@ -35,7 +35,7 @@ import org.nzbhydra.springnative.ReflectionMarker;
@Data
@ReflectionMarker
@Table(name = "indexeruniquenessscore")
public class IndexerUniquenessScoreEntity {
public final class IndexerUniquenessScoreEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)

View File

@ -17,6 +17,7 @@ import org.nzbhydra.config.BaseConfigHandler;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.config.SearchSource;
import org.nzbhydra.config.SearchSourceRestriction;
import org.nzbhydra.config.downloading.DownloadType;
import org.nzbhydra.config.indexer.IndexerConfig;
import org.nzbhydra.config.mediainfo.MediaIdType;
import org.nzbhydra.config.searching.SearchType;
@ -60,13 +61,12 @@ import static org.mockito.Mockito.*;
public class IndexerTest {
private BaseConfig baseConfig;
@Mock
private IndexerEntity indexerEntityMock;
private IndexerEntity indexerEntityMock = new IndexerEntity("indexerName");
private IndexerConfig indexerConfig = new IndexerConfig();
@Mock
private Indexer indexerMock;
@Mock
private SearchResultEntity searchResultEntityMock;
private SearchResultEntity searchResultEntityMock = new SearchResultEntity(indexerEntityMock, Instant.now(), "title", "guid", "link", "details", DownloadType.NZB, Instant.now());
@Mock
private IndexerRepository indexerRepositoryMock;
@Mock
@ -147,7 +147,7 @@ public class IndexerTest {
MockitoAnnotations.initMocks(this);
when(indexerMock.getIndexerEntity()).thenReturn(indexerEntityMock);
when(indexerMock.getConfig()).thenReturn(indexerConfig);
when(indexerEntityMock.getName()).thenReturn("indexerName");
when(indexerMock.getName()).thenReturn("indexerName");
testee.indexer = indexerEntityMock;
@ -201,7 +201,7 @@ public class IndexerTest {
SearchResultItem item = new SearchResultItem();
item.setIndexerGuid("guid");
item.setIndexer(indexerMock);
when(searchResultEntityMock.getIndexerGuid()).thenReturn("guid");
searchResultEntityMock.setIndexerGuid("guid");
when(searchResultRepositoryMock.findAllIdsByIdIn(anyList())).thenReturn(Sets.newHashSet(299225959498991027L));
testee.persistSearchResults(Collections.singletonList(item), new IndexerSearchResult());

View File

@ -78,8 +78,8 @@ public class NewznabTest {
private InfoProvider infoProviderMock;
@Mock
private IndexerWebAccess indexerWebAccessMock;
@Mock
private IndexerEntity indexerEntityMock;
private IndexerEntity indexerEntityMock = new IndexerEntity("indexer");
@Mock
private CategoryProvider categoryProviderMock;
@Mock
@ -143,6 +143,7 @@ public class NewznabTest {
testee.config = new IndexerConfig();
testee.config.setSupportedSearchIds(Lists.newArrayList(MediaIdType.TMDB, MediaIdType.TVRAGE));
testee.config.setHost("http://127.0.0.1:1234");
testee.indexer = indexerEntityMock;
baseConfig = new BaseConfig();
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);

View File

@ -75,8 +75,8 @@ public class TorznabTest {
private InfoProvider infoProviderMock;
@Mock
private IndexerWebAccess indexerWebAccessMock;
@Mock
private IndexerEntity indexerEntityMock;
private IndexerEntity indexerEntityMock = new IndexerEntity("indexer");
@Mock
private CategoryProvider categoryProviderMock;
@Mock

View File

@ -60,8 +60,7 @@ public class IndexerForSearchSelectorTest {
private SearchModuleProvider searchModuleProviderMock;
@Mock
private Indexer indexer;
@Mock
private IndexerEntity indexerEntity;
private IndexerEntity indexerEntity = new IndexerEntity("indexer");
@Mock
private InfoProvider infoProviderMock;
@Mock

View File

@ -71,12 +71,11 @@ public class SearcherUnitTest {
private IndexerSearchResult searchResultMock2;
@Mock
private SearchRepository searchRepositoryMock;
@Mock
private IndexerEntity indexerEntity;
private IndexerEntity indexerEntity = new IndexerEntity();
@Mock
private SearchResultRepository searchResultRepositoryMock;
@Mock
private SearchResultEntity searchResultEntityMock;
private SearchResultEntity searchResultEntityMock = new SearchResultEntity();
@Mock
private InfoProvider infoProviderMock;
@Mock
@ -91,8 +90,7 @@ public class SearcherUnitTest {
private ArgumentCaptor<List<SearchResultItem>> searchResultItemsCaptor;
@Mock
private IndexerForSearchSelection pickingResultMock;
@Mock
private IndexerSearchEntity indexerSearchEntityMock;
private IndexerSearchEntity indexerSearchEntityMock = new IndexerSearchEntity();
@Mock
private ApplicationEventPublisher applicationEventPublisherMock;
@Mock
@ -103,7 +101,7 @@ public class SearcherUnitTest {
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
when(searchResultEntityMock.getIndexer()).thenReturn(indexerEntity);
searchResultEntityMock.setIndexer(indexerEntity);
searcher.duplicateDetector = duplicateDetector;
when(indexer1.getName()).thenReturn("indexer1");