diff --git a/gemma-cli/src/main/java/ubic/gemma/core/apps/GenericGenelistDesignGenerator.java b/gemma-cli/src/main/java/ubic/gemma/core/apps/GenericGenelistDesignGenerator.java index 9cf90200a5..3fb0be8ff0 100644 --- a/gemma-cli/src/main/java/ubic/gemma/core/apps/GenericGenelistDesignGenerator.java +++ b/gemma-cli/src/main/java/ubic/gemma/core/apps/GenericGenelistDesignGenerator.java @@ -14,15 +14,10 @@ */ package ubic.gemma.core.apps; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.lang3.StringUtils; - import ubic.gemma.core.analysis.report.ArrayDesignReportService; import ubic.gemma.core.analysis.service.ArrayDesignAnnotationService; import ubic.gemma.core.apps.GemmaCLI.CommandGroup; @@ -49,6 +44,12 @@ import ubic.gemma.persistence.service.genome.sequenceAnalysis.AnnotationAssociationService; import ubic.gemma.persistence.service.genome.taxon.TaxonService; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Create (or update) an array design based on the current set of transcripts for a taxon. * This is used to create a 'platform' for linking non-array based data to the system, or data for which we have only @@ -116,9 +117,9 @@ protected void doWork() throws Exception { arrayDesign.setDescription( "Created by Gemma" ); arrayDesign.setTechnologyType( TechnologyType.GENELIST ); // this is key - if ( arrayDesignService.find( arrayDesign ) != null ) { + if ( arrayDesignService.find( byIdentifiable( arrayDesign ) ) != null ) { AbstractCLI.log.info( "Platform for " + taxon + " already exists, will update" ); - arrayDesign = arrayDesignService.findOrFail( arrayDesign ); + arrayDesign = arrayDesignService.findOrFail( byIdentifiable( arrayDesign ) ); arrayDesignService.deleteGeneProductAnnotationAssociations( arrayDesign ); arrayDesign = arrayDesignService.loadOrFail( arrayDesign.getId() ); diff --git a/gemma-core/src/main/java/ubic/gemma/core/annotation/reference/BibliographicReferenceService.java b/gemma-core/src/main/java/ubic/gemma/core/annotation/reference/BibliographicReferenceService.java index 3795d6e1f2..2e8d26e5a0 100644 --- a/gemma-core/src/main/java/ubic/gemma/core/annotation/reference/BibliographicReferenceService.java +++ b/gemma-core/src/main/java/ubic/gemma/core/annotation/reference/BibliographicReferenceService.java @@ -27,6 +27,7 @@ import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.BaseImmutableService; import ubic.gemma.persistence.service.BaseVoEnabledService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.ParametersAreNonnullByDefault; import java.util.Collection; @@ -45,18 +46,9 @@ public interface BibliographicReferenceService List browse( int start, int limit, String orderField, boolean descending ); - /** - * check to see if the object already exists - * - * @param bibliographicReference reference - * @return reference - */ - @Override - BibliographicReference find( BibliographicReference bibliographicReference ); - @Override @Secured({ "GROUP_USER" }) - BibliographicReference findOrCreate( BibliographicReference BibliographicReference ); + BibliographicReference findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) @@ -74,7 +66,7 @@ public interface BibliographicReferenceService * @param id id * @return reference */ - BibliographicReference findByExternalId( java.lang.String id ); + BibliographicReference findByExternalId( String id ); /** * Retrieve a reference by identifier, qualified by the database name (such as 'pubmed'). @@ -83,7 +75,7 @@ public interface BibliographicReferenceService * @param databaseName db name * @return reference */ - BibliographicReference findByExternalId( java.lang.String id, java.lang.String databaseName ); + BibliographicReference findByExternalId( String id, String databaseName ); /** *

@@ -93,7 +85,7 @@ public interface BibliographicReferenceService * @param id id * @return reference VO */ - BibliographicReferenceValueObject findVOByExternalId( java.lang.String id ); + BibliographicReferenceValueObject findVOByExternalId( String id ); /** * Return all the BibRefs that are linked to ExpressionExperiments. diff --git a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/DataUpdaterImpl.java b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/DataUpdaterImpl.java index 36692411e4..e61505394e 100644 --- a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/DataUpdaterImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/DataUpdaterImpl.java @@ -64,6 +64,8 @@ import java.io.IOException; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Update or fill in the data associated with an experiment. Cases include reprocessing data from CEL files (Affymetrix, * GEO only), inserting data for RNA-seq data sets but also generic cases where data didn't come from GEO and we need to @@ -993,7 +995,7 @@ private Collection makeNewVectors( ExpressionExperiment assert bioAssayDimension != null; assert !bioAssayDimension.getBioAssays().isEmpty(); - bioAssayDimension = assayDimensionService.findOrCreate( bioAssayDimension ); + bioAssayDimension = assayDimensionService.findOrCreate( byIdentifiable( bioAssayDimension ) ); assert !bioAssayDimension.getBioAssays().isEmpty(); diff --git a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/arrayDesign/ArrayDesignSequenceProcessingServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/arrayDesign/ArrayDesignSequenceProcessingServiceImpl.java index 19636d8248..b14411728e 100644 --- a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/arrayDesign/ArrayDesignSequenceProcessingServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/arrayDesign/ArrayDesignSequenceProcessingServiceImpl.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.method.P; import org.springframework.stereotype.Component; import ubic.gemma.core.analysis.report.ArrayDesignReportService; import ubic.gemma.core.analysis.sequence.SequenceManipulation; @@ -47,6 +46,8 @@ import java.io.*; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Handles collapsing the sequences, attaching sequences to DesignElements, either from provided input or via a fetch. * @@ -650,14 +651,14 @@ private BioSequence createOrUpdateGenbankSequence( BioSequence found, boolean fo BioSequence existing; - existing = bioSequenceService.findByAccession( sequenceDatabaseEntry ); + existing = bioSequenceService.findByAccession( byIdentifiable( sequenceDatabaseEntry ) ); BioSequence result; if ( existing == null ) { if ( ArrayDesignSequenceProcessingServiceImpl.log.isDebugEnabled() ) ArrayDesignSequenceProcessingServiceImpl.log.debug( "Find (or creating) new sequence " + found ); - result = bioSequenceService.find( found ); // there still might be a match. + result = bioSequenceService.find( byIdentifiable( found ) ); // there still might be a match. if ( result == null ) { result = bioSequenceService.create( found ); @@ -722,7 +723,7 @@ private Map findLocalSequences( Collection identifi BioSequence template = BioSequence.Factory.newInstance(); template.setTaxon( taxon ); template.setName( id ); - BioSequence seq = bioSequenceService.find( template ); + BioSequence seq = bioSequenceService.find( byIdentifiable( template ) ); if ( seq != null ) { seq = bioSequenceService.thaw( seq ); found.put( id, seq ); diff --git a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/simple/SimpleExpressionDataLoaderServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/simple/SimpleExpressionDataLoaderServiceImpl.java index a0d0300168..5014bd49d7 100644 --- a/gemma-core/src/main/java/ubic/gemma/core/loader/expression/simple/SimpleExpressionDataLoaderServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/core/loader/expression/simple/SimpleExpressionDataLoaderServiceImpl.java @@ -27,7 +27,6 @@ import ubic.basecode.dataStructure.matrix.DoubleMatrixFactory; import ubic.basecode.io.ByteArrayConverter; import ubic.basecode.io.reader.DoubleMatrixReader; -import ubic.gemma.core.analysis.preprocess.PreprocessingException; import ubic.gemma.core.analysis.preprocess.PreprocessorService; import ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher; import ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData; @@ -51,6 +50,8 @@ import java.io.InputStream; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Convert a simple matrix and some meta-data into an ExpressionExperiment. Used to handle flat file conversion. * @@ -357,7 +358,7 @@ private Taxon convertTaxon( Taxon taxon ) { if ( taxonService == null ) { return taxon; // for tests } - return taxonService.findOrCreate( taxon ); + return taxonService.findOrCreate( byIdentifiable( taxon ) ); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/persister/CommonPersister.java b/gemma-core/src/main/java/ubic/gemma/persistence/persister/CommonPersister.java index 0a81c35b19..22ce9f0a72 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/persister/CommonPersister.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/persister/CommonPersister.java @@ -40,6 +40,8 @@ import java.util.Collection; import java.util.Map; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Persister for ubic.gemma.model.common package classes. * @@ -128,7 +130,7 @@ protected AuditTrail persistAuditTrail( AuditTrail entity ) { } protected Contact persistContact( Contact contact ) { - return this.contactDao.findOrCreate( contact ); + return this.contactDao.findOrCreate( byIdentifiable( contact ) ); } protected ExternalDatabase persistExternalDatabase( ExternalDatabase database, Caches caches ) { @@ -140,7 +142,7 @@ protected ExternalDatabase persistExternalDatabase( ExternalDatabase database, C return seenDatabases.get( name ); } - ExternalDatabase existingDatabase = externalDatabaseDao.find( database ); + ExternalDatabase existingDatabase = externalDatabaseDao.find( byIdentifiable( database ) ); // don't use findOrCreate to avoid flush. if ( existingDatabase == null ) { @@ -196,16 +198,17 @@ protected QuantitationType persistQuantitationType( QuantitationType qType, Cach } protected Unit persistUnit( Unit unit ) { - return this.unitDao.findOrCreate( unit ); + return this.unitDao.findOrCreate( byIdentifiable( unit ) ); } private Object persistBibliographicReference( BibliographicReference reference, Caches caches ) { this.fillInDatabaseEntry( reference.getPubAccession(), caches ); - return this.bibliographicReferenceDao.findOrCreate( reference ); + return this.bibliographicReferenceDao.findOrCreate( byIdentifiable( reference ) ); } + @Deprecated private Person persistPerson( Person person ) { - return this.personDao.findOrCreate( person ); + return this.personDao.findOrCreate( byIdentifiable( person ) ); } } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/persister/ExpressionPersister.java b/gemma-core/src/main/java/ubic/gemma/persistence/persister/ExpressionPersister.java index 0090635a5c..a4d6131306 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/persister/ExpressionPersister.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/persister/ExpressionPersister.java @@ -45,6 +45,8 @@ import javax.annotation.Nullable; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * @author pavlidis */ @@ -390,7 +392,7 @@ private BioAssayDimension persistBioAssayDimension( BioAssayDimension bioAssayDi assert persistedBioAssays.size() > 0; bioAssayDimension.setBioAssays( persistedBioAssays ); // bioAssayDimension.setId( null ); // in case of retry. - return bioAssayDimensionDao.findOrCreate( bioAssayDimension ); + return bioAssayDimensionDao.findOrCreate( byIdentifiable( bioAssayDimension ) ); } private BioMaterial persistBioMaterial( BioMaterial entity, Caches caches ) { @@ -408,14 +410,14 @@ private BioMaterial persistBioMaterial( BioMaterial entity, Caches caches ) { AbstractPersister.log.debug( "taxon done" ); AbstractPersister.log.debug( "start save" ); - BioMaterial bm = bioMaterialDao.findOrCreate( entity ); + BioMaterial bm = bioMaterialDao.findOrCreate( byIdentifiable( entity ) ); AbstractPersister.log.debug( "save biomaterial done" ); return bm; } private Compound persistCompound( Compound compound ) { - return compoundDao.findOrCreate( compound ); + return compoundDao.findOrCreate( byIdentifiable( compound ) ); } /** @@ -434,7 +436,7 @@ private ExpressionExperimentSubSet persistExpressionExperimentSubSet( Expression throw new IllegalArgumentException( "Subsets are only supported for expression experiments that are already persistent" ); } else { - return expressionExperimentSubSetDao.findOrCreate( entity ); + return expressionExperimentSubSetDao.findOrCreate( byIdentifiable( entity ) ); } } @@ -447,7 +449,7 @@ private FactorValue persistFactorValue( FactorValue factorValue, Caches caches ) "You must fill in the experimental factor before persisting a factorvalue" ); } this.fillInFactorValueAssociations( factorValue, caches ); - return factorValueDao.findOrCreate( factorValue ); + return factorValueDao.findOrCreate( byIdentifiable( factorValue ) ); } /** diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/persister/GenomePersister.java b/gemma-core/src/main/java/ubic/gemma/persistence/persister/GenomePersister.java index 7716eec3f1..6f8f491015 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/persister/GenomePersister.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/persister/GenomePersister.java @@ -43,6 +43,8 @@ import javax.annotation.Nullable; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * @author pavlidis */ @@ -207,7 +209,7 @@ private Gene updateGene( Gene existingGene, Gene newGeneInfo, Caches caches ) { GeneProduct existingGeneProduct = updatedGpMap.get( newGeneProductInfo.getNcbiGi() ); this.updateGeneProduct( existingGeneProduct, newGeneProductInfo, caches ); } else { - GeneProduct existingGeneProduct = geneProductDao.find( newGeneProductInfo ); + GeneProduct existingGeneProduct = geneProductDao.find( byIdentifiable( newGeneProductInfo ) ); if ( existingGeneProduct == null ) { // it is, in fact, new, so far as we can tell. newGeneProductInfo.setGene( existingGene ); @@ -297,7 +299,7 @@ private Gene updateGene( Gene existingGene, Gene newGeneInfo, Caches caches ) { } protected BioSequence persistBioSequence( BioSequence bioSequence, Caches caches ) { - BioSequence existingBioSequence = bioSequenceDao.find( bioSequence ); + BioSequence existingBioSequence = bioSequenceDao.find( byIdentifiable( bioSequence ) ); // try to avoid making the instance 'dirty' if we don't have to, to avoid updates. if ( existingBioSequence != null ) { @@ -328,7 +330,7 @@ protected Taxon persistTaxon( Taxon taxon, Caches caches ) { } else if ( commonName != null && seenTaxa.containsKey( commonName.toLowerCase() ) ) { return seenTaxa.get( commonName.toLowerCase() ); } else { - Taxon fTaxon = taxonDao.findOrCreate( taxon ); + Taxon fTaxon = taxonDao.findOrCreate( byIdentifiable( taxon ) ); assert fTaxon != null; assert fTaxon.getId() != null; @@ -377,7 +379,7 @@ private void removeGeneProducts( Collection toRemove ) { Collection accessions = gpt.getAccessions(); Collection toRelease = new HashSet<>(); for ( DatabaseEntry de : accessions ) { - if ( this.bioSequenceDao.findByAccession( de ) != null ) { + if ( this.bioSequenceDao.findByAccession( byIdentifiable( de ) ) != null ) { toRelease.add( de ); } } @@ -420,7 +422,7 @@ private BioSequence2GeneProduct persistBlatAssociation( BlatAssociation associat private Gene persistGene( Gene gene, boolean checkFirst, Caches caches ) { if ( checkFirst ) { - Gene existingGene = geneDao.find( gene ); + Gene existingGene = geneDao.find( byIdentifiable( gene ) ); if ( existingGene != null ) { if ( AbstractPersister.log.isDebugEnabled() ) @@ -450,7 +452,7 @@ private Gene persistGene( Gene gene, boolean checkFirst, Caches caches ) { Set geneProductsForNewGene = new HashSet<>(); for ( GeneProduct product : tempGeneProduct ) { - GeneProduct existingProduct = geneProductDao.find( product ); + GeneProduct existingProduct = geneProductDao.find( byIdentifiable( product ) ); if ( existingProduct != null ) { /* * A geneProduct is being moved to a gene that didn't exist in the system already @@ -494,7 +496,7 @@ private Gene persistGene( Gene gene, boolean checkFirst, Caches caches ) { } private GeneProduct persistGeneProduct( GeneProduct geneProduct, Caches caches ) { - GeneProduct existing = geneProductDao.find( geneProduct ); + GeneProduct existing = geneProductDao.find( byIdentifiable( geneProduct ) ); if ( existing != null ) { if ( AbstractPersister.log.isDebugEnabled() ) @@ -525,7 +527,7 @@ private GeneProduct persistGeneProduct( GeneProduct geneProduct, Caches caches ) private BioSequence persistOrUpdateBioSequence( BioSequence bioSequence, Caches caches ) { // Note that this method is only really used by the ArrayDesignSequencePersister: it's for filling in //information about probes on arrays. - BioSequence existingBioSequence = bioSequenceDao.find( bioSequence ); + BioSequence existingBioSequence = bioSequenceDao.find( byIdentifiable( bioSequence ) ); if ( existingBioSequence == null ) { if ( AbstractPersister.log.isDebugEnabled() ) @@ -597,7 +599,7 @@ private Gene persistOrUpdateGene( Gene gene, Caches caches ) { if ( gene.getId() != null ) { existingGene = geneDao.load( gene.getId() ); } else { - existingGene = geneDao.find( gene ); + existingGene = geneDao.find( byIdentifiable( gene ) ); } if ( existingGene == null ) { @@ -615,7 +617,7 @@ private GeneProduct persistOrUpdateGeneProduct( GeneProduct geneProduct, Caches if ( geneProduct.getId() != null ) { existing = geneProductDao.load( geneProduct.getId() ); } else { - existing = geneProductDao.find( geneProduct ); + existing = geneProductDao.find( byIdentifiable( geneProduct ) ); } if ( existing == null ) { diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractDao.java index 1839da95fe..83f3a5e781 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractDao.java @@ -21,12 +21,15 @@ import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hibernate.*; +import org.hibernate.FlushMode; +import org.hibernate.Hibernate; +import org.hibernate.SessionFactory; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.hibernate.metadata.ClassMetadata; import org.springframework.util.Assert; import ubic.gemma.model.common.Identifiable; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -292,7 +295,7 @@ public void remove( Long id ) { if ( entity != null ) { this.remove( entity ); } else { - AbstractDao.log.trace( String.format( "No %s entity with ID %d, no need to remove anything.", elementClass.getSimpleName(), id ) ); + AbstractDao.log.trace( String.format( "No %s spec with ID %d, no need to remove anything.", elementClass.getSimpleName(), id ) ); } } @@ -350,23 +353,23 @@ public void update( T entity ) { } @Override - public T find( T entity ) { - if ( entity.getId() != null ) { - return this.load( entity.getId() ); + public T find( Specification spec ) { + if ( spec.getId() != null ) { + return this.load( spec.getId() ); } else { - AbstractDao.log.trace( String.format( "No persistent entity found for %s, returning null.", formatEntity( entity ) ) ); + AbstractDao.log.trace( String.format( "No persistent spec found for %s, returning null.", formatEntity( spec.getEntity() ) ) ); return null; } } @Override - public T findOrCreate( T entity ) { - T found = this.find( entity ); + public T findOrCreate( Specification spec ) { + T found = this.find( spec ); if ( found != null ) { return found; } else { - AbstractDao.log.trace( String.format( "No persistent entity found for %s, creating a new one...", formatEntity( entity ) ) ); - return this.create( entity ); + AbstractDao.log.trace( String.format( "No persistent spec found for %s, creating a new one...", formatEntity( spec.getEntity() ) ) ); + return this.create( spec.getEntity() ); } } @@ -375,14 +378,14 @@ protected final SessionFactory getSessionFactory() { } /** - * Retrieve one entity whose given property matches the given value. + * Retrieve one spec whose given property matches the given value. *

* Note: the property should have a unique index, otherwise a {@link org.hibernate.NonUniqueResultException} will be * raised. * * @param propertyName the name of property to be matched. * @param propertyValue the value to look for. - * @return an entity whose property matched the given value + * @return an spec whose property matched the given value */ protected T findOneByProperty( String propertyName, Object propertyValue ) { //noinspection unchecked @@ -397,7 +400,7 @@ protected T findOneByProperty( String propertyName, Object propertyValue ) { * * @param propertyName the name of property to be matched. * @param propertyValue the value to look for. - * @return an entity whose property first matched the given value. + * @return an spec whose property first matched the given value. */ protected List findByProperty( String propertyName, Object propertyValue ) { //noinspection unchecked @@ -465,11 +468,11 @@ private String formatEntity( @Nullable T entity ) { if ( entity == null ) { return String.format( "null %s", elementClass.getSimpleName() ); } else if ( entity.getId() == null ) { - return String.format( String.format( "transient %s entity", elementClass.getSimpleName() ) ); + return String.format( String.format( "transient %s spec", elementClass.getSimpleName() ) ); } else if ( sessionFactory.getCurrentSession().contains( entity ) ) { - return String.format( String.format( "persistent %s entity with ID %d", elementClass.getSimpleName(), entity.getId() ) ); + return String.format( String.format( "persistent %s spec with ID %d", elementClass.getSimpleName(), entity.getId() ) ); } else { - return String.format( String.format( "detached %s entity with ID %d", elementClass.getSimpleName(), entity.getId() ) ); + return String.format( String.format( "detached %s spec with ID %d", elementClass.getSimpleName(), entity.getId() ) ); } } } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractService.java index 782212de39..231cb83963 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/AbstractService.java @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional; import ubic.gemma.core.util.ListUtils; import ubic.gemma.model.common.Identifiable; +import ubic.gemma.persistence.util.Specification; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; @@ -36,22 +37,22 @@ public Class getElementClass() { @Override @Transactional(readOnly = true) - public O find( O entity ) { - return mainDao.find( entity ); + public O find( Specification spec ) { + return mainDao.find( spec ); } @Nonnull @Override @Transactional(readOnly = true) - public O findOrFail( O entity ) { - return requireNonNull( mainDao.find( entity ), - String.format( "No %s matching %s could be found.", mainDao.getElementClass().getName(), entity ) ); + public O findOrFail( Specification spec ) { + return requireNonNull( mainDao.find( spec ), + String.format( "No %s matching %s could be found.", mainDao.getElementClass().getName(), spec ) ); } @Override @Transactional - public O findOrCreate( O entity ) { - return mainDao.findOrCreate( entity ); + public O findOrCreate( Specification spec ) { + return mainDao.findOrCreate( spec ); } @Override diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseDao.java index e1c52e6673..8bfac1af5d 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseDao.java @@ -19,6 +19,7 @@ package ubic.gemma.persistence.service; import ubic.gemma.model.common.Identifiable; +import ubic.gemma.persistence.util.Specification; import javax.annotation.*; import java.io.Serializable; @@ -197,7 +198,7 @@ public interface BaseDao { */ @Nullable @CheckReturnValue - T find( T entity ); + T find( Specification entity ); /** * Calls the find method, and if this method returns null, creates a new instance in the persistent storage. @@ -206,5 +207,5 @@ public interface BaseDao { * @return the given entity, guaranteed to be representing an entity present in the persistent storage. */ @CheckReturnValue - T findOrCreate( T entity ); + T findOrCreate( Specification entity ); } \ No newline at end of file diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseImmutableService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseImmutableService.java index c61dccb5ca..10f314d2eb 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseImmutableService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseImmutableService.java @@ -1,8 +1,10 @@ package ubic.gemma.persistence.service; import ubic.gemma.model.common.Identifiable; +import ubic.gemma.persistence.util.Specification; import javax.annotation.CheckReturnValue; +import javax.annotation.Nullable; import java.util.Collection; /** @@ -16,11 +18,11 @@ public interface BaseImmutableService extends BaseReadOn /** * Does a search for the entity in the persistent storage, and if not found, creates it. * - * @param entity the entity to look for, and create if not found. + * @param spec the entity to look for, and create if not found. * @return the entity retrieved from the persistent storage, either found or created. */ @CheckReturnValue - O findOrCreate( O entity ); + O findOrCreate( Specification spec ); /** * Creates all the given entities in a persistent storage diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseReadOnlyService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseReadOnlyService.java index 9f9993cc5f..6174f223a0 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseReadOnlyService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/BaseReadOnlyService.java @@ -1,7 +1,7 @@ package ubic.gemma.persistence.service; import ubic.gemma.model.common.Identifiable; -import ubic.gemma.persistence.service.BaseDao; +import ubic.gemma.persistence.util.Specification; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; @@ -20,16 +20,16 @@ public interface BaseReadOnlyService { /** * Does a search for the entity in the persistent storage * - * @param entity the entity to be searched for + * @param spec the entity to be searched for * @return the version of entity retrieved from the persistent storage, if found, otherwise null. */ @Nullable @CheckReturnValue - O find( O entity ); + O find( Specification spec ); @Nonnull @CheckReturnValue - O findOrFail( O entity ); + O findOrFail( Specification spec ); /** * Loads objects with given ids. diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDao.java index 3c10c0882c..8fba821b3e 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDao.java @@ -33,12 +33,6 @@ */ public interface Gene2GOAssociationDao extends BaseDao { - @Override - Gene2GOAssociation find( Gene2GOAssociation gene2GOAssociation ); - - @Override - Gene2GOAssociation findOrCreate( Gene2GOAssociation gene2GOAssociation ); - Collection findAssociationByGene( Gene gene ); Collection findAssociationByGenes( Collection genes ); @@ -55,6 +49,4 @@ public interface Gene2GOAssociationDao extends BaseDao { Collection getGenes( Collection ids ); Collection getGenes( Collection ids, @Nullable Taxon taxon ); - - void removeAllInBatch(); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDaoImpl.java index b1769f171c..691abbbe31 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationDaoImpl.java @@ -21,7 +21,6 @@ import org.apache.commons.lang3.time.StopWatch; import org.hibernate.Criteria; import org.hibernate.Query; -import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -32,6 +31,7 @@ import ubic.gemma.persistence.service.AbstractDao; import ubic.gemma.persistence.util.BusinessKey; import ubic.gemma.persistence.util.EntityUtils; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nullable; import java.util.*; @@ -49,14 +49,13 @@ protected Gene2GOAssociationDaoImpl( SessionFactory sessionFactory ) { } @Override - public Gene2GOAssociation find( Gene2GOAssociation gene2GOAssociation ) { - BusinessKey.checkValidKey( gene2GOAssociation ); + public Gene2GOAssociation find( Specification spec ) { + BusinessKey.checkValidKey( spec ); Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( Gene2GOAssociation.class ); - BusinessKey.addRestrictions( queryObject, gene2GOAssociation ); + BusinessKey.addRestrictions( queryObject, spec ); return ( Gene2GOAssociation ) queryObject.uniqueResult(); } - @SuppressWarnings("unchecked") @Override public Collection findAssociationByGene( Gene gene ) { return this.findByProperty( "gene", gene ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationService.java index 09c4ea0e28..20ae12f486 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/association/Gene2GOAssociationService.java @@ -25,6 +25,7 @@ import ubic.gemma.model.genome.Taxon; import ubic.gemma.persistence.service.BaseImmutableService; import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nullable; import java.util.Collection; @@ -37,7 +38,7 @@ public interface Gene2GOAssociationService extends BaseImmutableService spec ); @Override @Secured({ "GROUP_ADMIN" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/ContactService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/ContactService.java index eedc76a665..f4a1c4bb0d 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/ContactService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/ContactService.java @@ -21,6 +21,7 @@ import org.springframework.security.access.annotation.Secured; import ubic.gemma.model.common.auditAndSecurity.Contact; import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; /** * @author kelsey @@ -29,11 +30,11 @@ public interface ContactService extends BaseService { @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ_QUIET" }) - Contact find( Contact contact ); + Contact find( Specification contact ); @Override @Secured({ "GROUP_USER" }) - Contact findOrCreate( Contact contact ); + Contact findOrCreate( Specification contact ); @Override @Secured({ "GROUP_USER", "ACL_SECURABLE_EDIT" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserDaoImpl.java index a6bfd97f65..84ce9c1ca7 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserDaoImpl.java @@ -15,9 +15,7 @@ package ubic.gemma.persistence.service.common.auditAndSecurity; import gemma.gsec.AuthorityConstants; -import org.hibernate.FlushMode; import org.hibernate.SessionFactory; -import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import ubic.gemma.model.common.auditAndSecurity.GroupAuthority; @@ -25,6 +23,7 @@ import ubic.gemma.model.common.auditAndSecurity.UserGroup; import ubic.gemma.persistence.service.AbstractDao; import ubic.gemma.persistence.util.BusinessKey; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.Objects; @@ -74,7 +73,7 @@ public Collection loadGroups( User user ) { public void remove( User user ) { if ( user.getName() != null && user.getName().equals( AuthorityConstants.REQUIRED_ADMINISTRATOR_USER_NAME ) ) { throw new IllegalArgumentException( - "Cannot remove user " + AuthorityConstants.REQUIRED_ADMINISTRATOR_USER_NAME ); + "Cannot remove spec " + AuthorityConstants.REQUIRED_ADMINISTRATOR_USER_NAME ); } super.remove( user ); } @@ -90,15 +89,15 @@ public void update( User user ) { if ( Objects.equals( user.getId(), AuthorityConstants.REQUIRED_ADMINISTRATOR_ID ) && !AuthorityConstants.REQUIRED_ADMINISTRATOR_USER_NAME.equals( user.getName() ) ) { throw new IllegalArgumentException( - "Cannot modify name of user ID=" + AuthorityConstants.REQUIRED_ADMINISTRATOR_ID ); + "Cannot modify name of spec ID=" + AuthorityConstants.REQUIRED_ADMINISTRATOR_ID ); } super.update( user ); } @Override - public User find( User user ) { - BusinessKey.checkKey( user ); - return this.findByUserName( user.getUserName() ); + public User find( Specification spec ) { + BusinessKey.checkKey( spec ); + return this.findByUserName( spec.getEntity().getUserName() ); } } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserGroupDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserGroupDaoImpl.java index b3c17c8f9b..c481d20c94 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserGroupDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/auditAndSecurity/UserGroupDaoImpl.java @@ -26,9 +26,9 @@ import ubic.gemma.model.common.auditAndSecurity.User; import ubic.gemma.model.common.auditAndSecurity.UserGroup; import ubic.gemma.persistence.service.AbstractDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; -import java.util.Iterator; import java.util.Objects; /** @@ -118,11 +118,11 @@ public void update( UserGroup userGroup ) { } @Override - public UserGroup find( UserGroup entity ) { - if ( entity.getId() != null ) { - return this.load( entity.getId() ); + public UserGroup find( Specification spec ) { + if ( spec.getId() != null ) { + return this.load( spec.getId() ); } else { - return this.findByName( entity.getName() ); + return this.findByName( spec.getEntity().getName() ); } } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseDaoImpl.java index cf10e8faa1..0319d24027 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseDaoImpl.java @@ -19,6 +19,7 @@ import org.springframework.stereotype.Repository; import ubic.gemma.model.common.description.ExternalDatabase; import ubic.gemma.persistence.service.AbstractDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.List; @@ -36,8 +37,8 @@ public ExternalDatabaseDaoImpl( SessionFactory sessionFactory ) { } @Override - public ExternalDatabase find( ExternalDatabase externalDatabase ) { - return this.findOneByProperty( "name", externalDatabase.getName() ); + public ExternalDatabase find( Specification spec ) { + return this.findOneByProperty( "name", spec.getEntity().getName() ); } @Override diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseService.java index b970142289..b6da049146 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/description/ExternalDatabaseService.java @@ -21,6 +21,7 @@ import org.springframework.security.access.annotation.Secured; import ubic.gemma.model.common.description.ExternalDatabase; import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nullable; import java.net.URL; @@ -52,7 +53,7 @@ public interface ExternalDatabaseService extends BaseService { @Override @Secured({ "GROUP_ADMIN" }) - ExternalDatabase findOrCreate( ExternalDatabase externalDatabase ); + ExternalDatabase findOrCreate( Specification spec ); @Override @Secured({ "GROUP_AGENT" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDao.java index 35807d0bf0..fd4d603ec0 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDao.java @@ -28,10 +28,4 @@ @Repository public interface UnitDao extends BaseDao { - @Override - Unit find( Unit unit ); - - @Override - Unit findOrCreate( Unit unit ); - } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDaoImpl.java index d80e7d3e99..82ea78b1da 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/measurement/UnitDaoImpl.java @@ -25,6 +25,7 @@ import ubic.gemma.model.common.measurement.Unit; import ubic.gemma.persistence.service.AbstractDao; import ubic.gemma.persistence.util.BusinessKey; +import ubic.gemma.persistence.util.Specification; /** *

@@ -44,9 +45,9 @@ public UnitDaoImpl( SessionFactory sessionFactory ) { } @Override - public Unit find( Unit unit ) { - BusinessKey.checkValidKey( unit ); - Criteria queryObject = BusinessKey.createQueryObject( this.getSessionFactory().getCurrentSession(), unit ); + public Unit find( Specification spec ) { + BusinessKey.checkValidKey( spec ); + Criteria queryObject = BusinessKey.createQueryObject( this.getSessionFactory().getCurrentSession(), spec ); return ( Unit ) queryObject.uniqueResult(); } } \ No newline at end of file diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolDao.java index 701632aa17..733f37cbb6 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolDao.java @@ -28,10 +28,4 @@ @Repository public interface ProtocolDao extends BaseDao { - @Override - Protocol find( Protocol protocol ); - - @Override - Protocol findOrCreate( Protocol protocol ); - } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolService.java index c9cdb1fd79..4cb65b8cef 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/protocol/ProtocolService.java @@ -21,6 +21,7 @@ import org.springframework.security.access.annotation.Secured; import ubic.gemma.model.common.protocol.Protocol; import ubic.gemma.persistence.service.BaseImmutableService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nonnull; import java.util.Collection; @@ -32,16 +33,16 @@ public interface ProtocolService extends BaseImmutableService { @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ" }) - Protocol find( Protocol protocol ); + Protocol find( Specification spec ); @Override @Nonnull @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ" }) - Protocol findOrFail( Protocol protocol ); + Protocol findOrFail( Specification spec ); @Override @Secured({ "GROUP_USER", "AFTER_ACL_READ" }) - Protocol findOrCreate( Protocol protocol ); + Protocol findOrCreate( Specification spec ); @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_COLLECTION_READ" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDao.java index 142650e874..5a4895649b 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDao.java @@ -1,8 +1,8 @@ /* * The Gemma project. - * + * * Copyright (c) 2006-2007 University of British Columbia - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,7 @@ import ubic.gemma.model.expression.bioAssayData.DesignElementDataVector; import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.FilteringVoEnabledDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.List; @@ -38,10 +39,10 @@ public interface QuantitationTypeDao extends FilteringVoEnabledDao quantitationType ); QuantitationType findByIdAndDataVectorType( ExpressionExperiment ee, Long id, Class dataVectorClass ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDaoImpl.java index 6df3b99ed9..9ea4ad285d 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeDaoImpl.java @@ -33,6 +33,7 @@ import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.AbstractCriteriaFilteringVoEnabledDao; import ubic.gemma.persistence.util.BusinessKey; +import ubic.gemma.persistence.util.Specification; import java.util.*; import java.util.stream.Collectors; @@ -55,9 +56,9 @@ public QuantitationTypeDaoImpl( SessionFactory sessionFactory ) { } @Override - public QuantitationType find( QuantitationType quantitationType ) { + public QuantitationType find( Specification spec ) { // Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( QuantitationType.class ); - // BusinessKey.addRestrictions( queryObject, quantitationType ); + // BusinessKey.addRestrictions( queryObject, spec ); // return ( QuantitationType ) queryObject.uniqueResult(); /* * Using this method doesn't really make sense, since QTs are EE-specific not re-usable outside of the context @@ -68,7 +69,7 @@ public QuantitationType find( QuantitationType quantitationType ) { } @Override - public QuantitationType find( ExpressionExperiment ee, QuantitationType quantitationType ) { + public QuantitationType find( ExpressionExperiment ee, Specification quantitationType ) { // find all QTs for the experiment //language=HQL @@ -76,13 +77,13 @@ public QuantitationType find( ExpressionExperiment ee, QuantitationType quantita + "inner join ee.quantitationTypes as quantType where ee = :ee "; //noinspection unchecked - List list = this.getSessionFactory().getCurrentSession().createQuery( queryString ) + List list = this.getSessionFactory().getCurrentSession().createQuery( queryString ) .setParameter( "ee", ee ).list(); // find all matching QTs; not necessarily for this experiment. This is lazy - we could go through the above to check each for a match. Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( QuantitationType.class ); BusinessKey.addRestrictions( queryObject, quantitationType ); - Collection qts = queryObject.list(); + Collection qts = queryObject.list(); // intersect that with the ones the experiment has (again, this is the lazy way to do this) list.retainAll( qts ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeService.java index c42dc25bd3..d13518f017 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeService.java @@ -25,6 +25,8 @@ import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.FilteringVoEnabledService; +import ubic.gemma.persistence.util.Specification; +import ubic.gemma.persistence.util.Specifications; import java.util.Collection; import java.util.List; @@ -41,7 +43,7 @@ public interface QuantitationTypeService extends BaseService, * @return found QT */ @Secured({ "GROUP_USER" }) - QuantitationType find( ExpressionExperiment ee, QuantitationType quantitationType ); + QuantitationType find( ExpressionExperiment ee, Specification quantitationType ); /** * Find a quantitation type by ID and vector type. @@ -58,7 +60,7 @@ public interface QuantitationTypeService extends BaseService, @Override @Secured({ "GROUP_USER" }) - QuantitationType findOrCreate( QuantitationType quantitationType ); + QuantitationType findOrCreate( Specification quantitationType ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeServiceImpl.java index f58fbb681d..99f9c6c23f 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/common/quantitationtype/QuantitationTypeServiceImpl.java @@ -26,6 +26,7 @@ import ubic.gemma.model.expression.bioAssayData.DesignElementDataVector; import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.AbstractFilteringVoEnabledService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.List; @@ -61,7 +62,7 @@ public List loadValueObjectsWithExpressionExperimen @Override @Transactional(readOnly = true) - public QuantitationType find( ExpressionExperiment ee, QuantitationType quantitationType ) { + public QuantitationType find( ExpressionExperiment ee, Specification quantitationType ) { return this.quantitationTypeDao.find( ee, quantitationType ); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/ArrayDesignDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/ArrayDesignDaoImpl.java index 6c39f6eec4..2a2be18816 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/ArrayDesignDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/ArrayDesignDaoImpl.java @@ -237,10 +237,10 @@ public Collection findByName( String name ) { } @Override - public ArrayDesign find( ArrayDesign entity ) { - BusinessKey.checkValidKey( entity ); + public ArrayDesign find( Specification spec ) { + BusinessKey.checkValidKey( spec ); Criteria query = super.getSessionFactory().getCurrentSession().createCriteria( ArrayDesign.class ); - BusinessKey.addRestrictions( query, entity ); + BusinessKey.addRestrictions( query, spec ); return ( ArrayDesign ) query.uniqueResult(); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/CuratableService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/CuratableService.java index 94c3acb602..7c3bc22845 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/CuratableService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/arrayDesign/CuratableService.java @@ -8,6 +8,7 @@ import ubic.gemma.persistence.util.Filters; import ubic.gemma.persistence.util.Slice; import ubic.gemma.persistence.util.Sort; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,11 +25,11 @@ public interface CuratableService spec ); @Override @Secured({ "GROUP_USER", "AFTER_ACL_READ" }) - C findOrCreate( C curatable ); + C findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssay/BioAssayService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssay/BioAssayService.java index a0bae43aff..28b47a237d 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssay/BioAssayService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssay/BioAssayService.java @@ -30,9 +30,10 @@ import ubic.gemma.persistence.service.FilteringVoEnabledDao; import ubic.gemma.persistence.util.Filter; import ubic.gemma.persistence.util.Sort; +import ubic.gemma.persistence.util.Specification; -import javax.annotation.Nullable; import javax.annotation.CheckReturnValue; +import javax.annotation.Nullable; import java.util.Collection; import java.util.List; import java.util.Set; @@ -70,7 +71,7 @@ public interface BioAssayService extends BaseService, BaseVoEnabledSer @Override @Secured({ "GROUP_USER", "AFTER_ACL_READ" }) - BioAssay findOrCreate( BioAssay bioAssay ); + BioAssay findOrCreate( Specification bioAssay ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/BioAssayDimensionService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/BioAssayDimensionService.java index 77d9f3ef68..821e9c0349 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/BioAssayDimensionService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/BioAssayDimensionService.java @@ -23,6 +23,7 @@ import ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject; import ubic.gemma.persistence.service.BaseImmutableService; import ubic.gemma.persistence.service.BaseVoEnabledService; +import ubic.gemma.persistence.util.Specification; /** * @author Paul @@ -32,7 +33,7 @@ public interface BioAssayDimensionService @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY" }) - BioAssayDimension findOrCreate( BioAssayDimension bioAssayDimension ); + BioAssayDimension findOrCreate( Specification spec ); @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/ProcessedExpressionDataVectorCreateHelperServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/ProcessedExpressionDataVectorCreateHelperServiceImpl.java index 27d79ddaec..1eed2d8e19 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/ProcessedExpressionDataVectorCreateHelperServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/ProcessedExpressionDataVectorCreateHelperServiceImpl.java @@ -24,7 +24,6 @@ import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.math3.analysis.function.Exp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,7 +32,6 @@ import ubic.basecode.math.Rank; import ubic.gemma.core.analysis.preprocess.ExpressionDataMatrixBuilder; import ubic.gemma.core.datastructure.matrix.*; -import ubic.gemma.model.common.auditAndSecurity.eventType.ProcessedVectorComputationEvent; import ubic.gemma.model.common.quantitationtype.QuantitationType; import ubic.gemma.model.expression.arrayDesign.ArrayDesign; import ubic.gemma.model.expression.arrayDesign.TechnologyType; @@ -44,12 +42,13 @@ import ubic.gemma.model.expression.biomaterial.BioMaterial; import ubic.gemma.model.expression.designElement.CompositeSequence; import ubic.gemma.model.expression.experiment.ExpressionExperiment; -import ubic.gemma.persistence.service.common.auditAndSecurity.AuditTrailService; import ubic.gemma.persistence.service.common.quantitationtype.QuantitationTypeService; import ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService; import java.util.*; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Transactional methods. * @@ -87,7 +86,7 @@ public void replaceProcessedDataVectors( ExpressionExperiment ee, // assumption: all the same QT. Further assumption: bioassaydimension already persistent. QuantitationType qt = vecs.iterator().next().getQuantitationType(); if ( qt.getId() == null ) { - QuantitationType existingQt = quantitationTypeService.find( ee, qt ); + QuantitationType existingQt = quantitationTypeService.find( ee, byIdentifiable( qt ) ); if ( existingQt != null ) { qt = existingQt; } else { diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/RawAndProcessedExpressionDataVectorDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/RawAndProcessedExpressionDataVectorDaoImpl.java index 95eb1db454..1d8c0ca4e1 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/RawAndProcessedExpressionDataVectorDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/bioAssayData/RawAndProcessedExpressionDataVectorDaoImpl.java @@ -7,6 +7,7 @@ import ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector; import ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector; import ubic.gemma.model.expression.designElement.CompositeSequence; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -35,11 +36,11 @@ public Collection load( Collection ids ) { } @Override - public DesignElementDataVector find( DesignElementDataVector entity ) { - if ( entity instanceof RawExpressionDataVector ) { - return rawExpressionDataVectorDao.find( ( RawExpressionDataVector ) entity ); - } else if ( entity instanceof ProcessedExpressionDataVector ) { - return processedExpressionDataVectorDao.find( ( ProcessedExpressionDataVector ) entity ); + public DesignElementDataVector find( Specification spec ) { + if ( spec.getEntity() instanceof RawExpressionDataVector ) { + return rawExpressionDataVectorDao.find( ( Specification ) spec ); + } else if ( spec.getEntity() instanceof ProcessedExpressionDataVector ) { + return processedExpressionDataVectorDao.find( ( Specification ) spec ); } else { throw new UnsupportedOperationException( "Only raw and processed vectors can be used with this service." ); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialDaoImpl.java index d058b8889f..866548a826 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialDaoImpl.java @@ -18,7 +18,10 @@ */ package ubic.gemma.persistence.service.expression.biomaterial; -import org.hibernate.*; +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.ObjectNotFoundException; +import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import ubic.gemma.model.expression.biomaterial.BioMaterial; @@ -29,10 +32,11 @@ import ubic.gemma.persistence.service.AbstractVoEnabledDao; import ubic.gemma.persistence.util.BusinessKey; import ubic.gemma.persistence.util.EntityUtils; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; + +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; /** * @author pavlidis @@ -50,10 +54,10 @@ public BioMaterialDaoImpl( SessionFactory sessionFactory ) { } @Override - public BioMaterial find( BioMaterial bioMaterial ) { + public BioMaterial find( Specification spec ) { Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( BioMaterial.class ); - BusinessKey.addRestrictions( queryObject, bioMaterial ); + BusinessKey.addRestrictions( queryObject, spec ); // This part is involved in a weird race condition that I could not get to a bottom of, so this is a hack-fix for now - tesarst, 2018-May-2 BioMaterial result = null; @@ -82,7 +86,7 @@ public BioMaterial copy( final BioMaterial bioMaterial ) { newMaterial.setFactorValues( bioMaterial.getFactorValues() ); newMaterial.setName( "Modeled after " + bioMaterial.getName() ); - newMaterial = this.findOrCreate( newMaterial ); + newMaterial = this.findOrCreate( byIdentifiable( newMaterial ) ); return newMaterial; } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialService.java index c3f2584cc4..dfc2690870 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/BioMaterialService.java @@ -26,6 +26,7 @@ import ubic.gemma.persistence.service.BaseImmutableService; import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.BaseVoEnabledService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.CheckReturnValue; import java.util.Collection; @@ -54,7 +55,7 @@ public interface BioMaterialService extends BaseService, BaseVoEnab @Override @Secured({ "GROUP_USER", "AFTER_ACL_READ" }) - BioMaterial findOrCreate( BioMaterial bioMaterial ); + BioMaterial findOrCreate( Specification bioMaterial ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundDaoImpl.java index 73baf26109..5b31eca685 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundDaoImpl.java @@ -1,8 +1,8 @@ /* * The Gemma project. - * + * * Copyright (c) 2006-2007 University of British Columbia - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,7 @@ import org.springframework.stereotype.Repository; import ubic.gemma.model.expression.biomaterial.Compound; import ubic.gemma.persistence.service.AbstractDao; +import ubic.gemma.persistence.util.Specification; import java.util.Comparator; @@ -43,8 +44,8 @@ public CompoundDaoImpl( SessionFactory sessionFactory ) { } @Override - public Compound find( Compound compound ) { - return this.findByProperty( "name", compound.getName() ) + public Compound find( Specification compound ) { + return this.findByProperty( "name", compound.getEntity().getName() ) .stream() .max( Comparator.comparing( Compound::getId ) ) .orElse( null ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundService.java index bf968a7767..aa354c17b2 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/biomaterial/CompoundService.java @@ -21,7 +21,9 @@ import org.springframework.security.access.annotation.Secured; import ubic.gemma.model.expression.biomaterial.Compound; import ubic.gemma.persistence.service.BaseImmutableService; -import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; + +import java.util.Collection; /** * @author kelsey @@ -30,7 +32,7 @@ public interface CompoundService extends BaseImmutableService { @Override @Secured({ "GROUP_USER" }) - Compound findOrCreate( Compound compound ); + Compound findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceDaoImpl.java index 4c7ab9e135..4df017d67a 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceDaoImpl.java @@ -571,7 +571,8 @@ public void thaw( final CompositeSequence cs ) { // } @Override - public CompositeSequence find( CompositeSequence compositeSequence ) { + public CompositeSequence find( Specification spec ) { + CompositeSequence compositeSequence = spec.getEntity(); if ( compositeSequence.getName() == null ) return null; diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceService.java index 579c578c5e..c3f69e313a 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/designElement/CompositeSequenceService.java @@ -30,6 +30,7 @@ import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.FilteringVoEnabledService; import ubic.gemma.persistence.util.Slice; +import ubic.gemma.persistence.util.Specification; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; @@ -45,11 +46,11 @@ public interface CompositeSequenceService @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_ARRAYDESIGN_COLLECTION_READ" }) - CompositeSequence find( CompositeSequence compositeSequence ); + CompositeSequence find( Specification spec ); @Override @Secured({ "GROUP_USER" }) - CompositeSequence findOrCreate( CompositeSequence compositeSequence ); + CompositeSequence findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignDaoImpl.java index e33b16fb8b..9ea64a93ca 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignDaoImpl.java @@ -18,7 +18,6 @@ */ package ubic.gemma.persistence.service.expression.experiment; -import org.hibernate.Criteria; import org.hibernate.SessionFactory; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; @@ -26,8 +25,7 @@ import ubic.gemma.model.expression.experiment.ExperimentalDesign; import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.AbstractDao; - -import java.util.List; +import ubic.gemma.persistence.util.Specification; /** * @see ubic.gemma.model.expression.experiment.ExperimentalDesign @@ -41,9 +39,9 @@ public ExperimentalDesignDaoImpl( SessionFactory sessionFactory ) { } @Override - public ExperimentalDesign find( ExperimentalDesign experimentalDesign ) { + public ExperimentalDesign find( Specification spec ) { return ( ExperimentalDesign ) this.getSessionFactory().getCurrentSession().createCriteria( ExperimentalDesign.class ) - .add( Restrictions.eq( "name", experimentalDesign.getName() ) ) + .add( Restrictions.eq( "name", spec.getEntity().getName() ) ) .uniqueResult(); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignService.java index 5259e0a65d..5842180d7c 100755 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignService.java @@ -22,8 +22,8 @@ import ubic.gemma.model.expression.experiment.ExperimentalDesign; import ubic.gemma.model.expression.experiment.ExpressionExperiment; import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; -import javax.annotation.Nullable; import java.util.Collection; /** @@ -33,7 +33,7 @@ public interface ExperimentalDesignService extends BaseService spec ); @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalFactorDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalFactorDao.java index 695dd9ecc8..34c72f3b37 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalFactorDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalFactorDao.java @@ -27,11 +27,5 @@ */ public interface ExperimentalFactorDao extends BaseVoEnabledDao { - @Override - ExperimentalFactor find( ExperimentalFactor experimentalFactor ); - - @Override - ExperimentalFactor findOrCreate( ExperimentalFactor experimentalFactor ); - ExperimentalFactor thaw( ExperimentalFactor ef ); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentDaoImpl.java index 9f25a12afb..af4d403695 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentDaoImpl.java @@ -141,7 +141,7 @@ public Collection findByName( String name ) { } @Override - public ExpressionExperiment find( ExpressionExperiment entity ) { + public ExpressionExperiment find( Specification entity ) { Criteria criteria = this.getSessionFactory().getCurrentSession().createCriteria( ExpressionExperiment.class ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetDao.java index bd61d87cce..57044df235 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetDao.java @@ -31,17 +31,7 @@ */ public interface ExpressionExperimentSubSetDao extends BaseDao { - @Override - ExpressionExperimentSubSet find( ExpressionExperimentSubSet entity ); - - /** - * @return matching or new entity. Matching would mean the same bioassays. - */ - @Override - ExpressionExperimentSubSet findOrCreate( ExpressionExperimentSubSet entity ); - Collection getFactorValuesUsed( ExpressionExperimentSubSet entity, ExperimentalFactor factor ); Collection getFactorValuesUsed( Long subSetId, Long experimentalFactor ); - } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetService.java index e7810bf285..7d982f507f 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExpressionExperimentSubSetService.java @@ -24,6 +24,7 @@ import ubic.gemma.model.expression.experiment.FactorValue; import ubic.gemma.model.expression.experiment.FactorValueValueObject; import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nullable; import java.util.Collection; @@ -35,11 +36,11 @@ public interface ExpressionExperimentSubSetService extends BaseService spec ); @Override @Secured({ "GROUP_USER" }) - ExpressionExperimentSubSet findOrCreate( ExpressionExperimentSubSet entity ); + ExpressionExperimentSubSet findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/FactorValueService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/FactorValueService.java index c7595aee63..c0c672f600 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/FactorValueService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/FactorValueService.java @@ -21,9 +21,9 @@ import org.springframework.security.access.annotation.Secured; import ubic.gemma.model.expression.experiment.FactorValue; import ubic.gemma.model.expression.experiment.FactorValueValueObject; -import ubic.gemma.persistence.service.BaseImmutableService; import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.FilteringVoEnabledService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -38,7 +38,7 @@ public interface FactorValueService extends BaseService, FilteringV @Override @Secured({ "GROUP_USER", "AFTER_ACL_READ" }) - FactorValue findOrCreate( FactorValue factorValue ); + FactorValue findOrCreate( Specification spec ); @Override @Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/ChromosomeDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/ChromosomeDaoImpl.java index b6086f398e..7a4de45873 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/ChromosomeDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/ChromosomeDaoImpl.java @@ -24,6 +24,7 @@ import ubic.gemma.model.genome.Chromosome; import ubic.gemma.model.genome.Taxon; import ubic.gemma.persistence.service.AbstractDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -52,8 +53,8 @@ public Collection find( String name, Taxon taxon ) { } @Override - public Chromosome find( Chromosome entity ) { - Collection hits = this.find( entity.getName(), entity.getSequence().getTaxon() ); + public Chromosome find( Specification spec ) { + Collection hits = this.find( spec.getEntity().getName(), spec.getEntity().getSequence().getTaxon() ); if ( hits.isEmpty() ) { return null; } else { diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/GeneDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/GeneDaoImpl.java index e27e5002d0..cf56a19a5a 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/GeneDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/GeneDaoImpl.java @@ -222,7 +222,7 @@ public Collection findByPhysicalLocation( final PhysicalLocation location } /** - * Gets a count of the CompositeSequences related to the gene identified by the given id. + * Gets a count of the CompositeSequences related to the spec identified by the given id. * * @return Collection */ @@ -257,7 +257,7 @@ public Collection getCompositeSequences( Gene gene, ArrayDesi } /** - * Gets all the CompositeSequences related to the gene identified by the given id. + * Gets all the CompositeSequences related to the spec identified by the given id. * * @return Collection */ @@ -440,13 +440,13 @@ public void remove( Gene gene ) { } @Override - public Gene find( Gene gene ) { + public Gene find( Specification spec ) { Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( Gene.class ); - BusinessKey.checkKey( gene ); + BusinessKey.checkKey( spec ); - BusinessKey.createQueryObject( queryObject, gene ); + BusinessKey.createQueryObject( queryObject, spec ); //noinspection unchecked,unchecked List results = queryObject.list(); @@ -473,7 +473,7 @@ public Gene find( Gene gene ) { // Note hack we used to allow multiple previous ids. for ( String previousId : StringUtils.split( foundGene.getPreviousNcbiId(), "," ) ) { try { - if ( gene.getNcbiGeneId().equals( Integer.parseInt( previousId ) ) ) { + if ( spec.getEntity().getNcbiGeneId().equals( Integer.parseInt( previousId ) ) ) { toDelete.add( foundGene ); } } catch ( NumberFormatException e ) { @@ -485,14 +485,14 @@ public Gene find( Gene gene ) { if ( !toDelete.isEmpty() ) { assert toDelete.size() < results.size(); // it shouldn't be everything! AbstractDao.log.warn( - "Deleting gene(s) that use a deprecated NCBI ID: " + StringUtils.join( toDelete, " | " ) ); + "Deleting spec(s) that use a deprecated NCBI ID: " + StringUtils.join( toDelete, " | " ) ); this.remove( toDelete ); // WARNING this might fail due to constraints. } results.removeAll( toDelete ); for ( Gene foundGene : results ) { - if ( foundGene.getNcbiGeneId() != null && gene.getNcbiGeneId() != null && foundGene.getNcbiGeneId() - .equals( gene.getNcbiGeneId() ) ) { + if ( foundGene.getNcbiGeneId() != null && spec.getEntity().getNcbiGeneId() != null && foundGene.getNcbiGeneId() + .equals( spec.getEntity().getNcbiGeneId() ) ) { return foundGene; } } @@ -501,11 +501,11 @@ public Gene find( Gene gene ) { * This should be quite a rare situation if the database is kept tidy. */ if ( results.size() > 1 ) { - AbstractDao.log.error( "Multiple genes found for " + gene + ":" ); + AbstractDao.log.error( "Multiple genes found for " + spec + ":" ); this.debug( results ); results.sort( Comparator.comparing( Describable::getId ) ); result = results.iterator().next(); - AbstractDao.log.error( "Returning arbitrary gene: " + result ); + AbstractDao.log.error( "Returning arbitrary spec: " + result ); } else { result = results.get( 0 ); } @@ -532,7 +532,7 @@ protected Query getFilteringQuery( @Nullable Filters filters, @Nullable Sort sor //noinspection JpaQlInspection // the constants for aliases is messing with the inspector String queryString = "select gene " - + "from Gene as gene " // gene + + "from Gene as gene " // spec + "left join fetch gene.multifunctionality " // multifunctionality, if available + "left join fetch gene.taxon as taxon "// taxon + "where gene.id is not null"; // needed to use formRestrictionCause() @@ -555,7 +555,7 @@ protected void initializeCachedFilteringResult( Gene entity ) { @Override protected Query getFilteringCountQuery( @Nullable Filters filters ) { //noinspection JpaQlInspection // the constants for aliases is messing with the inspector - String queryString = "select count(gene) from Gene as gene " // gene + String queryString = "select count(gene) from Gene as gene " // spec + "left join gene.multifunctionality " // multifunctionality, if available + "left join gene.taxon as taxon "// taxon + "where gene.id is not null"; // needed to use formRestrictionCause() diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDao.java index 9d2444ff40..fa702d76ac 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDao.java @@ -24,6 +24,8 @@ import ubic.gemma.model.genome.biosequence.BioSequence; import ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject; import ubic.gemma.persistence.service.BaseVoEnabledDao; +import ubic.gemma.persistence.util.Specification; +import ubic.gemma.persistence.util.Specifications; import java.util.Collection; import java.util.Map; @@ -33,7 +35,7 @@ */ public interface BioSequenceDao extends BaseVoEnabledDao { - BioSequence findByAccession( DatabaseEntry accession ); + BioSequence findByAccession( Specification accession ); /** *

diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDaoImpl.java index f7db7346e3..8767e4db45 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceDaoImpl.java @@ -33,6 +33,7 @@ import ubic.gemma.persistence.service.AbstractVoEnabledDao; import ubic.gemma.persistence.util.BusinessKey; import ubic.gemma.persistence.util.EntityUtils; +import ubic.gemma.persistence.util.Specification; import javax.annotation.Nullable; import java.util.*; @@ -51,7 +52,7 @@ public BioSequenceDaoImpl( SessionFactory sessionFactory ) { } @Override - public BioSequence findByAccession( DatabaseEntry databaseEntry ) { + public BioSequence findByAccession( Specification databaseEntry ) { BusinessKey.checkValidKey( databaseEntry ); String queryString; @@ -60,30 +61,29 @@ public BioSequence findByAccession( DatabaseEntry databaseEntry ) { queryString = "select b from BioSequence b inner join fetch b.sequenceDatabaseEntry d inner join fetch d.externalDatabase e where d=:dbe"; //noinspection unchecked results = this.getSessionFactory().getCurrentSession().createQuery( queryString ) - .setParameter( "dbe", databaseEntry ).list(); + .setParameter( "dbe", databaseEntry.getEntity() ).list(); } else { queryString = "select b from BioSequence b inner join fetch b.sequenceDatabaseEntry d " + "inner join fetch d.externalDatabase e where d.accession = :acc and e.name = :dbName"; //noinspection unchecked results = this.getSessionFactory().getCurrentSession().createQuery( queryString ) - .setParameter( "acc", databaseEntry.getAccession() ) - .setParameter( "dbName", databaseEntry.getExternalDatabase().getName() ).list(); + .setParameter( "acc", databaseEntry.getEntity().getAccession() ) + .setParameter( "dbName", databaseEntry.getEntity().getExternalDatabase().getName() ).list(); } if ( results.size() > 1 ) { this.debug( null, results ); AbstractDao.log.warn( "More than one instance of '" + BioSequence.class.getName() - + "' was found when executing query for accession=" + databaseEntry.getAccession() ); + + "' was found when executing query for accession=" + databaseEntry.getEntity().getAccession() ); // favor the one with name matching the accession. - for ( Object object : results ) { - BioSequence bs = ( BioSequence ) object; - if ( bs.getName().equals( databaseEntry.getAccession() ) ) { + for ( BioSequence bs : results ) { + if ( bs.getName().equals( databaseEntry.getEntity().getAccession() ) ) { return bs; } } - AbstractDao.log.error( "No biosequence really matches " + databaseEntry.getAccession() ); + AbstractDao.log.error( "No biosequence really matches " + databaseEntry.getEntity().getAccession() ); return null; } else if ( results.size() == 1 ) { @@ -203,7 +203,7 @@ protected BioSequenceValueObject doLoadValueObject( BioSequence entity ) { @SuppressWarnings("unchecked") @Override - public BioSequence find( BioSequence bioSequence ) { + public BioSequence find( Specification bioSequence ) { BusinessKey.checkValidKey( bioSequence ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceService.java index d375023a2a..a062c772d9 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceService.java @@ -26,6 +26,7 @@ import ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject; import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.BaseVoEnabledService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.Map; @@ -35,7 +36,7 @@ */ public interface BioSequenceService extends BaseService, BaseVoEnabledService { - BioSequence findByAccession( DatabaseEntry accession ); + BioSequence findByAccession( Specification accession ); /** * @param genes genes @@ -56,7 +57,7 @@ public interface BioSequenceService extends BaseService, BaseVoEnab @Override @Secured({ "GROUP_USER" }) - BioSequence findOrCreate( BioSequence bioSequence ); + BioSequence findOrCreate( Specification bioSequence ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceServiceImpl.java index 342221434b..babfade9a5 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/biosequence/BioSequenceServiceImpl.java @@ -27,11 +27,14 @@ import ubic.gemma.model.genome.biosequence.BioSequence; import ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject; import ubic.gemma.persistence.service.AbstractVoEnabledService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.HashSet; import java.util.Map; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * Spring Service base class for BioSequenceService, provides access to * all services and entities referenced by this service. @@ -54,7 +57,7 @@ public BioSequenceServiceImpl( BioSequenceDao bioSequenceDao ) { @Override @Transactional(readOnly = true) - public BioSequence findByAccession( DatabaseEntry accession ) { + public BioSequence findByAccession( Specification accession ) { return this.bioSequenceDao.findByAccession( accession ); } @@ -75,7 +78,7 @@ public Collection findByName( String name ) { public Collection findOrCreate( Collection bioSequences ) { Collection result = new HashSet<>(); for ( BioSequence bioSequence : bioSequences ) { - result.add( this.bioSequenceDao.findOrCreate( bioSequence ) ); + result.add( this.bioSequenceDao.findOrCreate( byIdentifiable( bioSequence ) ) ); } return result; } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDao.java index f1ba0fcc70..1a91d92805 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDao.java @@ -13,17 +13,18 @@ import ubic.gemma.model.genome.gene.GeneProduct; import ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation; import ubic.gemma.persistence.service.BaseDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; /** * @author paul */ -public interface AnnotationAssociationDao extends BaseDao{ +public interface AnnotationAssociationDao extends BaseDao { - Collection find( BioSequence bioSequence ); + Collection findByBioSequence( Specification bioSequence ); - Collection find( Gene gene ); + Collection findByGene( Specification gene ); void thaw( final AnnotationAssociation annotationAssociation ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDaoImpl.java index 1a38872791..a39e00c5d4 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationDaoImpl.java @@ -27,11 +27,14 @@ import ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation; import ubic.gemma.persistence.service.AbstractDao; import ubic.gemma.persistence.util.BusinessKey; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** * @author paul */ @@ -45,7 +48,7 @@ public AnnotationAssociationDaoImpl( SessionFactory sessionFactory ) { } @Override - public Collection find( BioSequence bioSequence ) { + public Collection findByBioSequence( Specification bioSequence ) { BusinessKey.checkValidKey( bioSequence ); Criteria queryObject = this.getSessionFactory().getCurrentSession() .createCriteria( AnnotationAssociation.class ); @@ -56,16 +59,16 @@ public Collection find( BioSequence bioSequence ) { } @Override - public Collection find( Gene gene ) { - if ( gene.getProducts().size() == 0 ) { + public Collection findByGene( Specification gene ) { + if ( gene.getEntity().getProducts().size() == 0 ) { throw new IllegalArgumentException( "Gene has no products" ); } Collection result = new HashSet<>(); - for ( GeneProduct geneProduct : gene.getProducts() ) { + for ( GeneProduct geneProduct : gene.getEntity().getProducts() ) { - BusinessKey.checkValidKey( geneProduct ); + BusinessKey.checkValidKey( byIdentifiable( geneProduct ) ); Criteria queryObject = this.getSessionFactory().getCurrentSession() .createCriteria( AnnotationAssociation.class ); Criteria innerQuery = queryObject.createCriteria( "geneProduct" ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationService.java index 1cd106bdc4..f3cafd06ca 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationService.java @@ -14,7 +14,7 @@ import ubic.gemma.model.genome.biosequence.BioSequence; import ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation; import ubic.gemma.persistence.service.BaseImmutableService; -import ubic.gemma.persistence.service.BaseService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -36,9 +36,9 @@ public interface AnnotationAssociationService extends BaseImmutableService find( BioSequence bioSequence ); + Collection findByBioSequence( Specification bioSequence ); - Collection find( Gene gene ); + Collection findByGene( Specification gene ); Collection removeRootTerms( Collection associations ); } diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationServiceImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationServiceImpl.java index ca0320bc5d..3cfca797e9 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationServiceImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/AnnotationAssociationServiceImpl.java @@ -8,6 +8,7 @@ import ubic.gemma.model.genome.biosequence.BioSequence; import ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation; import ubic.gemma.persistence.service.AbstractService; +import ubic.gemma.persistence.util.Specification; import java.util.ArrayList; import java.util.Collection; @@ -26,14 +27,14 @@ public AnnotationAssociationServiceImpl( AnnotationAssociationDao annotationAsso @Override @Transactional(readOnly = true) - public Collection find( BioSequence bioSequence ) { - return this.annotationAssociationDao.find( bioSequence ); + public Collection findByBioSequence( Specification bioSequence ) { + return this.annotationAssociationDao.findByBioSequence( bioSequence ); } @Override @Transactional(readOnly = true) - public Collection find( Gene gene ) { - return this.annotationAssociationDao.find( gene ); + public Collection findByGene( Specification gene ) { + return this.annotationAssociationDao.findByGene( gene ); } /** diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDao.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDao.java index 0552c48017..7abfb01d6b 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDao.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDao.java @@ -18,9 +18,12 @@ */ package ubic.gemma.persistence.service.genome.sequenceAnalysis; +import ubic.gemma.model.genome.Gene; +import ubic.gemma.model.genome.biosequence.BioSequence; import ubic.gemma.model.genome.gene.GeneProduct; import ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation; import ubic.gemma.persistence.service.BaseDao; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -29,9 +32,9 @@ */ public interface BlatAssociationDao extends BaseDao { - java.util.Collection find( ubic.gemma.model.genome.biosequence.BioSequence bioSequence ); + Collection findByBioSequence( Specification bioSequence ); - java.util.Collection find( ubic.gemma.model.genome.Gene gene ); + Collection findByGene( Specification gene ); void thaw( Collection blatAssociations ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDaoImpl.java index 2adf92a1dd..d6137f0696 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/sequenceAnalysis/BlatAssociationDaoImpl.java @@ -19,7 +19,9 @@ package ubic.gemma.persistence.service.genome.sequenceAnalysis; import org.apache.commons.lang3.StringUtils; -import org.hibernate.*; +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.SessionFactory; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -29,11 +31,14 @@ import ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation; import ubic.gemma.persistence.service.AbstractDao; import ubic.gemma.persistence.util.BusinessKey; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; + /** *

* Base Spring DAO Class: is able to create, update, remove, load, and find objects of type @@ -51,7 +56,7 @@ public BlatAssociationDaoImpl( SessionFactory sessionFactory ) { } @Override - public Collection find( BioSequence bioSequence ) { + public Collection findByBioSequence( Specification bioSequence ) { BusinessKey.checkValidKey( bioSequence ); Criteria queryObject = super.getSessionFactory().getCurrentSession().createCriteria( BlatAssociation.class ); BusinessKey.attachCriteria( queryObject, bioSequence, "bioSequence" ); @@ -60,17 +65,17 @@ public Collection find( BioSequence bioSequence ) { } @Override - public Collection find( Gene gene ) { + public Collection findByGene( Specification gene ) { - if ( gene.getProducts().size() == 0 ) { + if ( gene.getEntity().getProducts().size() == 0 ) { throw new IllegalArgumentException( "Gene has no products" ); } Collection result = new HashSet<>(); - for ( GeneProduct geneProduct : gene.getProducts() ) { + for ( GeneProduct geneProduct : gene.getEntity().getProducts() ) { - BusinessKey.checkValidKey( geneProduct ); + BusinessKey.checkValidKey( byIdentifiable( geneProduct ) ); Criteria queryObject = super.getSessionFactory().getCurrentSession() .createCriteria( BlatAssociation.class ); diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonDaoImpl.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonDaoImpl.java index f8832251e7..7c27018aa7 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonDaoImpl.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonDaoImpl.java @@ -25,10 +25,7 @@ import ubic.gemma.model.genome.TaxonValueObject; import ubic.gemma.persistence.service.AbstractFilteringVoEnabledDao; import ubic.gemma.persistence.service.AbstractQueryFilteringVoEnabledDao; -import ubic.gemma.persistence.util.BusinessKey; -import ubic.gemma.persistence.util.FilterQueryUtils; -import ubic.gemma.persistence.util.Filters; -import ubic.gemma.persistence.util.Sort; +import ubic.gemma.persistence.util.*; import javax.annotation.Nullable; import java.text.MessageFormat; @@ -49,21 +46,21 @@ public TaxonDaoImpl( SessionFactory sessionFactory ) { @Override public Taxon create( Taxon taxon ) { if ( StringUtils.isBlank( taxon.getCommonName() ) && StringUtils.isBlank( taxon.getScientificName() ) ) { - throw new IllegalArgumentException( "Cannot create a taxon without names: " + taxon ); + throw new IllegalArgumentException( "Cannot create a spec without names: " + taxon ); } return super.create( taxon ); } @Override - public Taxon find( Taxon taxon ) { + public Taxon find( Specification spec ) { - BusinessKey.checkValidKey( taxon ); + BusinessKey.checkValidKey( spec ); Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria( Taxon.class ) .setReadOnly( true ); queryObject.setReadOnly( true ); queryObject.setFlushMode( FlushMode.MANUAL ); - BusinessKey.addRestrictions( queryObject, taxon ); + BusinessKey.addRestrictions( queryObject, spec ); return ( Taxon ) queryObject.uniqueResult(); } @@ -111,7 +108,7 @@ protected Query getFilteringQuery( @Nullable Filters filters, @Nullable Sort sor //noinspection JpaQlInspection // the constants for aliases is messing with the inspector //language=HQL String queryString = MessageFormat.format( "select {0} " - + "from Taxon as {0} " // taxon + + "from Taxon as {0} " // spec + "left join {0}.externalDatabase as ED " // external db + "where {0}.id is not null ", OBJECT_ALIAS ); // needed to use formRestrictionCause() @@ -135,7 +132,7 @@ protected Query getFilteringCountQuery( @Nullable Filters filters ) { //noinspection JpaQlInspection // the constants for aliases is messing with the inspector //language=HQL String queryString = MessageFormat.format( "select count({0}) " - + "from Taxon as {0} " // taxon + + "from Taxon as {0} " // spec + "left join {0}.externalDatabase as ED " // external db + "where {0}.id is not null ", OBJECT_ALIAS ); // needed to use formRestrictionCause() diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonService.java b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonService.java index f326098da3..ba4d38a9e9 100755 --- a/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonService.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/service/genome/taxon/TaxonService.java @@ -23,6 +23,7 @@ import ubic.gemma.model.genome.TaxonValueObject; import ubic.gemma.persistence.service.BaseService; import ubic.gemma.persistence.service.FilteringVoEnabledService; +import ubic.gemma.persistence.util.Specification; import java.util.Collection; @@ -39,7 +40,7 @@ public interface TaxonService extends BaseService, FilteringVoEnabledServ @Override @Secured({ "GROUP_USER" }) - Taxon findOrCreate( Taxon taxon ); + Taxon findOrCreate( Specification spec ); @Override @Secured({ "GROUP_USER" }) diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/util/BusinessKey.java b/gemma-core/src/main/java/ubic/gemma/persistence/util/BusinessKey.java index 1b53180e57..e8d7f43493 100644 --- a/gemma-core/src/main/java/ubic/gemma/persistence/util/BusinessKey.java +++ b/gemma-core/src/main/java/ubic/gemma/persistence/util/BusinessKey.java @@ -61,7 +61,7 @@ public class BusinessKey { private static final Log log = LogFactory.getLog( BusinessKey.class.getName() ); - public static void addRestrictions( Criteria queryObject, ArrayDesign arrayDesign ) { + public static void addRestrictions( Criteria queryObject, Specification arrayDesign ) { /* * Test whether ANY of the associated external references match any of the given external references. @@ -103,7 +103,7 @@ public static void addRestrictions( Criteria queryObject, ArrayDesign arrayDesig } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void addRestrictions( Criteria queryObject, BioAssay bioAssay ) { + public static void addRestrictions( Criteria queryObject, Specification bioAssay ) { if ( bioAssay.getId() != null ) { queryObject.add( Restrictions.eq( "id", bioAssay.getId() ) ); } else if ( bioAssay.getAccession() != null ) { @@ -112,7 +112,7 @@ public static void addRestrictions( Criteria queryObject, BioAssay bioAssay ) { queryObject.add( Restrictions.eq( "name", bioAssay.getName() ) ); } - public static void addRestrictions( Criteria queryObject, BioMaterial bioMaterial ) { + public static void addRestrictions( Criteria queryObject, Specification bioMaterial ) { if ( bioMaterial.getName() != null ) { queryObject.add( Restrictions.eq( "name", bioMaterial.getName() ) ); @@ -147,23 +147,23 @@ public static void addRestrictions( Criteria queryObject, BioMaterial bioMateria * @param queryObject query object */ @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void addRestrictions( Criteria queryObject, BioSequence bioSequence ) { + public static void addRestrictions( Criteria queryObject, Specification bioSequence ) { if ( bioSequence.getId() != null ) { queryObject.add( Restrictions.eq( "id", bioSequence.getId() ) ); return; } - if ( StringUtils.isNotBlank( bioSequence.getName() ) ) { - BusinessKey.addNameRestriction( queryObject, bioSequence ); + if ( StringUtils.isNotBlank( bioSequence.getEntity().getName() ) ) { + BusinessKey.addNameRestriction( queryObject, bioSequence.getEntity() ); } - BusinessKey.attachCriteria( queryObject, bioSequence.getTaxon(), "taxon" ); + BusinessKey.attachCriteria( queryObject, bioSequence.getEntity().getTaxon(), "taxon" ); } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void addRestrictions( Criteria queryObject, Characteristic characteristic ) { + public static void addRestrictions( Criteria queryObject, Specification characteristic ) { if ( characteristic.getCategoryUri() != null ) { queryObject.add( Restrictions.eq( "categoryUri", characteristic.getCategoryUri() ) ); @@ -181,7 +181,7 @@ public static void addRestrictions( Criteria queryObject, Characteristic charact } @SuppressWarnings({ "WeakerAccess", "unused" }) // Possible external use - public static void addRestrictions( Criteria queryObject, Chromosome chromosome ) { + public static void addRestrictions( Criteria queryObject, Specification chromosome ) { queryObject.add( Restrictions.eq( "name", chromosome.getName() ) ); BusinessKey.attachCriteria( queryObject, chromosome.getTaxon(), "taxon" ); if ( chromosome.getAssemblyDatabase() != null ) { @@ -192,7 +192,7 @@ public static void addRestrictions( Criteria queryObject, Chromosome chromosome } } - public static void addRestrictions( Criteria queryObject, Contact contact ) { + public static void addRestrictions( Criteria queryObject, Specification contact ) { if ( contact instanceof User ) { queryObject.add( Restrictions.eq( "userName", ( ( User ) contact ).getUserName() ) ); @@ -209,7 +209,7 @@ public static void addRestrictions( Criteria queryObject, Contact contact ) { } - public static void addRestrictions( Criteria queryObject, ExperimentalFactor experimentalFactor ) { + public static void addRestrictions( Criteria queryObject, Specification experimentalFactor ) { if ( experimentalFactor.getId() != null ) { queryObject.add( Restrictions.eq( "id", experimentalFactor.getId() ) ); @@ -226,7 +226,7 @@ public static void addRestrictions( Criteria queryObject, ExperimentalFactor exp } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void addRestrictions( Criteria queryObject, Gene gene, boolean stricter ) { + public static void addRestrictions( Criteria queryObject, Specification gene, boolean stricter ) { if ( gene.getId() != null ) { queryObject.add( Restrictions.eq( "id", gene.getId() ) ); } else if ( gene.getNcbiGeneId() != null ) { @@ -279,12 +279,12 @@ public static void addRestrictions( Criteria queryObject, Gene gene, boolean str } } - public static void addRestrictions( Criteria queryObject, Gene2GOAssociation gene2GOAssociation ) { + public static void addRestrictions( Criteria queryObject, Specification gene2GOAssociation ) { BusinessKey.attachCriteria( queryObject, gene2GOAssociation.getGene(), "gene" ); BusinessKey.attachCriteria( queryObject, gene2GOAssociation.getOntologyEntry() ); } - public static void addRestrictions( Criteria queryObject, QuantitationType quantitationType ) { + public static void addRestrictions( Criteria queryObject, Specification quantitationType ) { queryObject.add( Restrictions.eq( "name", quantitationType.getName() ) ); queryObject.add( Restrictions.eq( "description", quantitationType.getDescription() ) ); @@ -309,13 +309,13 @@ public static void addRestrictions( Criteria queryObject, QuantitationType quant } - public static void addRestrictions( Criteria queryObject, Taxon taxon ) { + public static void addRestrictions( Criteria queryObject, Specification taxon ) { BusinessKey.checkValidKey( taxon ); BusinessKey.attachCriteria( queryObject, taxon ); } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void addRestrictions( DetachedCriteria queryObject, DatabaseEntry databaseEntry ) { + public static void addRestrictions( DetachedCriteria queryObject, Specification databaseEntry ) { queryObject.add( Restrictions.eq( "accession", databaseEntry.getAccession() ) ) .createCriteria( "externalDatabase" ) .add( Restrictions.eq( "name", databaseEntry.getExternalDatabase().getName() ) ); @@ -328,7 +328,7 @@ public static void addRestrictions( DetachedCriteria queryObject, DatabaseEntry * @param propertyName Often this will be 'bioSequence' * @param queryObject query object */ - public static void attachCriteria( Criteria queryObject, BioSequence bioSequence, String propertyName ) { + public static void attachCriteria( Criteria queryObject, Specification bioSequence, String propertyName ) { Criteria innerQuery = queryObject.createCriteria( propertyName ); BusinessKey.addRestrictions( innerQuery, bioSequence ); } @@ -341,7 +341,7 @@ public static void attachCriteria( Criteria queryObject, BioSequence bioSequence * @param queryObject query object */ @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void attachCriteria( Criteria queryObject, Characteristic ontologyEntry, String propertyName ) { + public static void attachCriteria( Criteria queryObject, Specification ontologyEntry, String propertyName ) { Criteria innerQuery = queryObject.createCriteria( propertyName ); BusinessKey.addRestrictions( innerQuery, ontologyEntry ); } @@ -353,7 +353,7 @@ public static void attachCriteria( Criteria queryObject, Characteristic ontology * @param propertyName often "accession" * @param queryObject query object */ - public static void attachCriteria( Criteria queryObject, DatabaseEntry databaseEntry, String propertyName ) { + public static void attachCriteria( Criteria queryObject, Specification databaseEntry, String propertyName ) { Criteria innerQuery = queryObject.createCriteria( propertyName ); BusinessKey.attachCriteria( innerQuery, databaseEntry ); } @@ -366,13 +366,13 @@ public static void attachCriteria( Criteria queryObject, DatabaseEntry databaseE * @param propertyName property name */ @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void attachCriteria( Criteria queryObject, Gene gene, String propertyName ) { + public static void attachCriteria( Criteria queryObject, Specification gene, String propertyName ) { Criteria innerQuery = queryObject.createCriteria( propertyName ); BusinessKey.addRestrictions( innerQuery, gene, true ); } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void attachCriteria( Criteria queryObject, PhysicalLocation physicalLocation, String attributeName ) { + public static void attachCriteria( Criteria queryObject, Specification physicalLocation, String attributeName ) { Criteria nestedCriteria = queryObject.createCriteria( attributeName ); if ( physicalLocation.getChromosome() == null ) { @@ -404,19 +404,19 @@ public static void attachCriteria( Criteria queryObject, PhysicalLocation physic * @param taxon taxon */ @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void attachCriteria( Criteria queryObject, Taxon taxon, String propertyName ) { + public static void attachCriteria( Criteria queryObject, Specification taxon, String propertyName ) { Criteria innerQuery = queryObject.createCriteria( propertyName ); BusinessKey.attachCriteria( innerQuery, taxon ); } @SuppressWarnings({ "WeakerAccess", "unused" }) // Possible external use - public static void attachCriteria( DetachedCriteria queryObject, DatabaseEntry databaseEntry, + public static void attachCriteria( DetachedCriteria queryObject, Specification databaseEntry, String attributeName ) { DetachedCriteria externalRef = queryObject.createCriteria( attributeName ); BusinessKey.addRestrictions( externalRef, databaseEntry ); } - public static void checkKey( BibliographicReference bibliographicReference ) { + public static void checkKey( Specification bibliographicReference ) { if ( bibliographicReference == null || bibliographicReference.getPubAccession() == null || bibliographicReference.getPubAccession().getAccession() == null ) { throw new IllegalArgumentException( @@ -425,19 +425,19 @@ public static void checkKey( BibliographicReference bibliographicReference ) { } @SuppressWarnings("WeakerAccess") // Consistency - public static void checkKey( Characteristic ontologyEntry ) { + public static void checkKey( Specification ontologyEntry ) { if ( ontologyEntry.getValue() == null ) throw new IllegalArgumentException(); } - public static void checkKey( Contact contact ) { + public static void checkKey( Specification contact ) { if ( contact == null || ( StringUtils.isBlank( contact.getName() ) && StringUtils .isBlank( contact.getEmail() ) ) ) { throw new IllegalArgumentException( "Contact must have at least some information filled in!" ); } } - public static void checkKey( DatabaseEntry accession ) { + public static void checkKey( Specification accession ) { if ( accession.getId() != null ) return; if ( StringUtils.isBlank( accession.getAccession() ) ) { @@ -446,7 +446,7 @@ public static void checkKey( DatabaseEntry accession ) { BusinessKey.checkKey( accession.getExternalDatabase() ); } - public static void checkKey( DesignElementDataVector designElementDataVector ) { + public static void checkKey( Specification designElementDataVector ) { if ( designElementDataVector == null || designElementDataVector.getDesignElement() == null || designElementDataVector.getExpressionExperiment() == null ) { throw new IllegalArgumentException( @@ -455,7 +455,7 @@ public static void checkKey( DesignElementDataVector designElementDataVector ) { } @SuppressWarnings("WeakerAccess") // Consistency - public static void checkKey( ExternalDatabase externalDatabase ) { + public static void checkKey( Specification externalDatabase ) { if ( externalDatabase.getId() != null ) return; if ( StringUtils.isBlank( externalDatabase.getName() ) ) { @@ -463,7 +463,7 @@ public static void checkKey( ExternalDatabase externalDatabase ) { } } - public static void checkKey( FactorValue factorValue ) { + public static void checkKey( Specification factorValue ) { if ( factorValue.getValue() == null && factorValue.getMeasurement() == null && factorValue.getCharacteristics().size() == 0 ) { throw new IllegalArgumentException( @@ -471,7 +471,7 @@ public static void checkKey( FactorValue factorValue ) { } } - public static void checkKey( Gene gene ) { + public static void checkKey( Specification gene ) { if ( gene == null ) throw new IllegalArgumentException( "Gene cannot be null" ); if ( ( ( gene.getOfficialSymbol() == null || gene.getTaxon() == null ) && gene.getPhysicalLocation() == null @@ -481,36 +481,36 @@ public static void checkKey( Gene gene ) { } } - public static void checkKey( User user ) { + public static void checkKey( Specification user ) { if ( user == null || StringUtils.isBlank( user.getUserName() ) ) { throw new IllegalArgumentException( "User was null or had no userName defined" ); } } - public static void checkValidKey( ArrayDesign arrayDesign ) { - if ( arrayDesign == null || ( StringUtils.isBlank( arrayDesign.getName() ) && StringUtils - .isBlank( arrayDesign.getShortName() ) && arrayDesign.getExternalReferences().size() == 0 ) ) { + public static void checkValidKey( Specification arrayDesign ) { + if ( arrayDesign.getEntity() == null || ( StringUtils.isBlank( arrayDesign.getEntity().getName() ) && StringUtils + .isBlank( arrayDesign.getEntity().getShortName() ) && arrayDesign.getEntity().getExternalReferences().size() == 0 ) ) { throw new IllegalArgumentException( arrayDesign + " did not have a valid key" ); } } - public static void checkValidKey( BioSequence bioSequence ) { - if ( bioSequence == null || bioSequence.getTaxon() == null || StringUtils.isBlank( bioSequence.getName() ) ) { + public static void checkValidKey( Specification bioSequence ) { + if ( bioSequence.getEntity() == null || bioSequence.getEntity().getTaxon() == null || StringUtils.isBlank( bioSequence.getEntity().getName() ) ) { throw new IllegalArgumentException( bioSequence + " did not have a valid key" ); } } @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use - public static void checkValidKey( Chromosome chromosome ) { - if ( StringUtils.isBlank( chromosome.getName() ) ) { + public static void checkValidKey( Specification chromosome ) { + if ( StringUtils.isBlank( chromosome.getEntity().getName() ) ) { throw new IllegalArgumentException( "Chromosome did not have a valid key" ); } - BusinessKey.checkValidKey( chromosome.getTaxon() ); + BusinessKey.checkValidKey( chromosome.getEntity().getTaxon() ); } - public static void checkValidKey( DatabaseEntry databaseEntry ) { - if ( databaseEntry == null || databaseEntry.getAccession() == null - || databaseEntry.getExternalDatabase() == null ) { + public static void checkValidKey( Specification databaseEntry ) { + if ( databaseEntry.getEntity() == null || databaseEntry.getEntity().getAccession() == null + || databaseEntry.getEntity().getExternalDatabase() == null ) { throw new IllegalArgumentException( "DatabaseEntry does not have valid key" ); } } @@ -522,7 +522,7 @@ public static void checkValidKey( ExperimentalFactor experimentalFactor ) { } @SuppressWarnings("WeakerAccess") // Consistency - public static void checkValidKey( Gene gene ) { + public static void checkValidKey( Specification gene ) { if ( gene == null || ( gene.getNcbiGeneId() == null && ( StringUtils.isBlank( gene.getOfficialSymbol() ) || gene.getTaxon() == null || StringUtils.isBlank( gene.getOfficialName() ) ) ) ) { throw new IllegalArgumentException( @@ -530,11 +530,11 @@ public static void checkValidKey( Gene gene ) { } } - public static void checkValidKey( Gene2GOAssociation gene2GOAssociation ) { + public static void checkValidKey( Specification gene2GOAssociation ) { BusinessKey.checkValidKey( gene2GOAssociation.getGene() ); } - public static void checkValidKey( GeneProduct geneProduct ) { + public static void checkValidKey( Specification geneProduct ) { if ( geneProduct.getId() != null ) return; @@ -553,30 +553,30 @@ public static void checkValidKey( GeneProduct geneProduct ) { } - public static void checkValidKey( Taxon taxon ) { + public static void checkValidKey( Specification taxon ) { if ( taxon == null || ( taxon.getNcbiId() == null && StringUtils.isBlank( taxon.getCommonName() ) && StringUtils .isBlank( taxon.getScientificName() ) ) ) { throw new IllegalArgumentException( "Taxon " + taxon + " did not have a valid key" ); } } - public static void checkValidKey( ubic.gemma.model.common.description.LocalFile localFile ) { - if ( localFile == null || ( localFile.getLocalURL() == null && localFile.getRemoteURL() == null ) ) { - if ( localFile != null ) + public static void checkValidKey( Specification localFile ) { + if ( localFile.getEntity() == null || ( localFile.getEntity().getLocalURL() == null && localFile.getEntity().getRemoteURL() == null ) ) { + if ( localFile.getEntity() != null ) BusinessKey.log - .error( "Localfile without valid key: localURL=" + localFile.getLocalURL() + " remoteUrL=" - + localFile.getRemoteURL() + " size=" + localFile.getSize() ); + .error( "Localfile without valid key: localURL=" + localFile.getEntity().getLocalURL() + " remoteUrL=" + + localFile.getEntity().getRemoteURL() + " size=" + localFile.getEntity().getSize() ); throw new IllegalArgumentException( "localFile was null or had no valid business keys" ); } } - public static void checkValidKey( Unit unit ) { - if ( unit == null || StringUtils.isBlank( unit.getUnitNameCV() ) ) { + public static void checkValidKey( Specification unit ) { + if ( unit.getEntity() == null || StringUtils.isBlank( unit.getEntity().getUnitNameCV() ) ) { throw new IllegalArgumentException( unit + " did not have a valid key" ); } } - public static void createQueryObject( Criteria queryObject, FactorValue factorValue ) { + public static void createQueryObject( Criteria queryObject, Specification factorValue ) { ExperimentalFactor ef = factorValue.getExperimentalFactor(); @@ -638,7 +638,7 @@ public static void createQueryObject( Criteria queryObject, FactorValue factorVa queryObject.setResultTransformer( CriteriaSpecification.DISTINCT_ROOT_ENTITY ); } - public static void createQueryObject( Criteria queryObject, Gene gene ) { + public static void createQueryObject( Criteria queryObject, Specification gene ) { if ( gene.getId() != null ) { queryObject.add( Restrictions.eq( "id", gene.getId() ) ); } else { @@ -647,7 +647,7 @@ public static void createQueryObject( Criteria queryObject, Gene gene ) { } - public static void createQueryObject( Criteria queryObject, GeneProduct geneProduct ) { + public static void createQueryObject( Criteria queryObject, Specification geneProduct ) { if ( geneProduct.getId() != null ) { queryObject.add( Restrictions.eq( "id", geneProduct.getId() ) ); } else if ( StringUtils.isNotBlank( geneProduct.getNcbiGi() ) ) { @@ -665,40 +665,40 @@ public static void createQueryObject( Criteria queryObject, GeneProduct geneProd } @SuppressWarnings("unused") // Possible external use - public static Criteria createQueryObject( Session session, ArrayDesign arrayDesign ) { + public static Criteria createQueryObject( Session session, Specification arrayDesign ) { Criteria queryObject = session.createCriteria( ArrayDesign.class ); BusinessKey.addRestrictions( queryObject, arrayDesign ); return queryObject; } - public static Criteria createQueryObject( Session session, BioAssay bioAssay ) { + public static Criteria createQueryObject( Session session, Specification bioAssay ) { Criteria queryObject = session.createCriteria( BioAssay.class ); BusinessKey.checkKey( bioAssay ); BusinessKey.addRestrictions( queryObject, bioAssay ); return queryObject; } - public static Criteria createQueryObject( Session session, BioSequence bioSequence ) { + public static Criteria createQueryObject( Session session, Specification bioSequence ) { Criteria queryObject = session.createCriteria( BioSequence.class ); BusinessKey.addRestrictions( queryObject, bioSequence ); return queryObject; } @SuppressWarnings("unused") // Possible external use - public static Criteria createQueryObject( Session session, Characteristic ontologyEntry ) { + public static Criteria createQueryObject( Session session, Specification ontologyEntry ) { Criteria queryObject = session.createCriteria( Characteristic.class ); BusinessKey.checkKey( ontologyEntry ); BusinessKey.addRestrictions( queryObject, ontologyEntry ); return queryObject; } - public static Criteria createQueryObject( Session session, Unit unit ) { + public static Criteria createQueryObject( Session session, Specification unit ) { Criteria queryObject = session.createCriteria( Unit.class ); if ( unit.getId() != null ) { queryObject.add( Restrictions.eq( "id", unit.getId() ) ); - } else if ( unit.getUnitNameCV() != null ) { - queryObject.add( Restrictions.eq( "unitNameCV", unit.getUnitNameCV() ) ); + } else if ( unit.getEntity().getUnitNameCV() != null ) { + queryObject.add( Restrictions.eq( "unitNameCV", unit.getEntity().getUnitNameCV() ) ); } return queryObject; @@ -755,19 +755,19 @@ private static void attachCriteria( Criteria queryObject, Taxon taxon ) { } } - private static void attachCriteria( Criteria queryObject, Characteristic ontologyEntry ) { + private static void attachCriteria( Criteria queryObject, Specification ontologyEntry ) { Criteria innerQuery = queryObject.createCriteria( "ontologyEntry" ); BusinessKey.addRestrictions( innerQuery, ontologyEntry ); } - private static void checkKey( BioAssay bioAssay ) { - if ( bioAssay.getId() == null && bioAssay.getAccession() == null ) { + private static void checkKey( Specification bioAssay ) { + if ( bioAssay.getId() == null && bioAssay.getEntity().getAccession() == null ) { throw new IllegalArgumentException( "Bioassay must have id or accession" ); } } - public static void checkKey( ExpressionExperimentSubSet entity ) { + public static void checkKey( Specification entity ) { if ( entity.getBioAssays().isEmpty() ) { throw new IllegalArgumentException( "Subset must have bioassays" ); } @@ -783,7 +783,7 @@ public static void checkKey( ExpressionExperimentSubSet entity ) { } } - public static void createQueryObject( Criteria queryObject, ExpressionExperimentSubSet entity ) { + public static void createQueryObject( Criteria queryObject, Specification entity ) { /* * Note that we don't match on name. */ diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/util/Specification.java b/gemma-core/src/main/java/ubic/gemma/persistence/util/Specification.java new file mode 100644 index 0000000000..2813701f0c --- /dev/null +++ b/gemma-core/src/main/java/ubic/gemma/persistence/util/Specification.java @@ -0,0 +1,11 @@ +package ubic.gemma.persistence.util; + +import javax.annotation.Nullable; + +public interface Specification { + + @Nullable + Long getId(); + + T getEntity(); +} diff --git a/gemma-core/src/main/java/ubic/gemma/persistence/util/Specifications.java b/gemma-core/src/main/java/ubic/gemma/persistence/util/Specifications.java new file mode 100644 index 0000000000..1250aaf7be --- /dev/null +++ b/gemma-core/src/main/java/ubic/gemma/persistence/util/Specifications.java @@ -0,0 +1,26 @@ +package ubic.gemma.persistence.util; + +import ubic.gemma.model.common.Identifiable; + +import javax.annotation.Nullable; + +public final class Specifications { + + /** + * Create a specification for an {@link Identifiable} entity. + */ + public static Specification byIdentifiable( T entity ) { + return new Specification() { + @Nullable + @Override + public Long getId() { + return entity.getId(); + } + + @Override + public T getEntity() { + return entity; + } + }; + } +} diff --git a/gemma-core/src/test/java/ubic/gemma/model/genome/TaxonServiceImplTest.java b/gemma-core/src/test/java/ubic/gemma/model/genome/TaxonServiceImplTest.java index e7534fbab9..9e00df7ada 100644 --- a/gemma-core/src/test/java/ubic/gemma/model/genome/TaxonServiceImplTest.java +++ b/gemma-core/src/test/java/ubic/gemma/model/genome/TaxonServiceImplTest.java @@ -22,9 +22,12 @@ import org.junit.Test; import ubic.gemma.core.util.test.BaseSpringContextTest; +import ubic.gemma.persistence.util.Specification; +import ubic.gemma.persistence.util.Specifications; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static ubic.gemma.persistence.util.Specifications.byIdentifiable; /** * @author paul @@ -32,7 +35,7 @@ public class TaxonServiceImplTest extends BaseSpringContextTest { /** - * Test method for {@link ubic.gemma.persistence.service.genome.taxon.TaxonService#findOrCreate(Taxon)} )}. + * Test method for {@link ubic.gemma.persistence.service.genome.taxon.TaxonService#findOrCreate(Specification)} )}. * Situation where the secondary id is treated as the primary, we must not make a new taxon! */ @Test @@ -43,7 +46,7 @@ public void testFindOrCreate() { Taxon yeast = taxonService.findByCommonName( "yeast" ); assertNotNull( yeast ); // this should be loaded automatically. - Taxon found = taxonService.findOrCreate( t ); + Taxon found = taxonService.findOrCreate( byIdentifiable(t) ); assertEquals( new Integer( 4932 ), found.getNcbiId() ); }