/** * Prints the most counts in the database. * @param ps The printStream to use * * @since 1.9.0 */ public static void printDatabaseCounts(PrintStream ps) { final DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); ps.println("Publications: "+ daoFactory.getPublicationDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(PublicationXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(PublicationAlias.class).countAll()); ps.println("Experiments: "+ daoFactory.getExperimentDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(ExperimentXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(ExperimentAlias.class).countAll()); ps.println("Interactors: "+ daoFactory.getInteractorDao().countAll()); ps.println("\tInteractions: "+ daoFactory.getInteractionDao().countAll()); ps.println("\tPolymers: " + daoFactory.getPolymerDao().countAll()); ps.println("\t\tProteins: "+ daoFactory.getProteinDao().countAll()); ps.println("\t\tNucleic Acids: "+ daoFactory.getInteractorDao(NucleicAcidImpl.class).countAll()); ps.println("\tSmall molecules: " + daoFactory.getInteractorDao(SmallMoleculeImpl.class).countAll()); ps.println("\tInteractor Xrefs: "+ daoFactory.getXrefDao(InteractorXref.class).countAll()); ps.println("\tInteractor Aliases: "+ daoFactory.getAliasDao(InteractorAlias.class).countAll()); ps.println("Components: "+ daoFactory.getComponentDao().countAll()); ps.println("Features: "+ daoFactory.getFeatureDao().countAll()); ps.println("\tRanges: "+ daoFactory.getRangeDao().countAll()); ps.println("CvObjects: "+ daoFactory.getCvObjectDao().countAll()); ps.println("BioSources: "+ daoFactory.getBioSourceDao().countAll()); ps.println("Annotations: "+ daoFactory.getAnnotationDao().countAll()); ps.println("Institutions: "+ daoFactory.getInstitutionDao().countAll()); }
protected EntityManager getEntityManager() { EntityManager em = getDaoFactory().getEntityManager(); //em.setFlushMode(FlushModeType.COMMIT); return em; }
public <T extends AnnotatedObject> AnnotatedObjectDao<T> getAnnotatedObjectDao( Class<T> entityType ) { if (entityType.isAssignableFrom(Institution.class)) { return (AnnotatedObjectDao<T>)getInstitutionDao(); } else if (Publication.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getPublicationDao(); } else if (CvObject.class.isAssignableFrom(entityType)) { return getCvObjectDao((Class)entityType); } else if (Experiment.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getExperimentDao(); } else if (Interaction.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getInteractionDao(); } else if (Interactor.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getInteractorDao(); } else if (BioSource.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getBioSourceDao(); } else if (Component.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getComponentDao(); } else if (Feature.class.isAssignableFrom(entityType)) { return (AnnotatedObjectDao<T>)getFeatureDao(); } else { throw new IllegalArgumentException( "No Dao for entity type: "+entityType.getClass().getName()); } }
@Transactional(propagation = Propagation.REQUIRES_NEW) /** * Delete hidden annotations for each cv given in the collection */ public void removeHiddenFrom(Collection<CvObject> cvs){ DaoFactory factory = IntactContext.getCurrentInstance().getDaoFactory(); AnnotationDao annDao = factory.getAnnotationDao(); for (CvObject cv : cvs){ cv = factory.getEntityManager().merge(cv); Collection<Annotation> annotations = new ArrayList<Annotation>(cv.getAnnotations()); for (Annotation annotation : annotations){ if (annotation.getCvTopic() != null && CvTopic.HIDDEN.equalsIgnoreCase(annotation.getCvTopic().getShortLabel())){ cv.removeAnnotation(annotation); annDao.delete(annotation); } } } }
protected <T extends CvObject> T getCvObjectByLabel( Class<T> cvObjectClass, String label ) { if ( label == null ) { throw new NullPointerException( "label is null" ); } if ( log.isTraceEnabled() ) log.trace( "Processed values size: " + processed.size() ); for ( CvObject cvObject : processed.values() ) { if ( cvObjectClass.isAssignableFrom( cvObject.getClass() ) && label.equals( cvObject.getShortLabel() ) ) { return ( T ) cvObject; } } return IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getCvObjectDao( cvObjectClass ).getByShortLabel( cvObjectClass, label ); }
XrefDao<CvObjectXref> xrefDao = factory.getXrefDao(CvObjectXref.class); AliasDao<CvObjectAlias> aliasDao = factory.getAliasDao(CvObjectAlias.class); AnnotationDao annotationDao = factory.getAnnotationDao(); CvObjectDao<CvDagObject> cvDao = factory.getCvObjectDao(CvDagObject.class); factory.getCvObjectDao(CvDagObject.class).update(updateContext.getCvTerm());
CvObjectDao<CvTopic> cvTopicDao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getCvObjectDao(CvTopic.class); if ( ! experiment.getAnnotations().contains( annotation ) ) { IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getAnnotationDao().persist( annotation ); experiment.addAnnotation( annotation ); IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getExperimentDao().update( experiment );
private CvTopic createCvTopicObsolete() { final DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); if ( obsoleteTopic != null ) { if (daoFactory.getBaseDao().isTransient(obsoleteTopic) && obsoleteTopic.getAc() != null) { obsoleteTopic = daoFactory.getCvObjectDao( CvTopic.class ).getByAc( obsoleteTopic.getAc() ); } } else { obsoleteTopic = daoFactory.getCvObjectDao( CvTopic.class ).getByPsiMiRef( CvTopic.OBSOLETE_MI_REF ); } if ( obsoleteTopic == null ) { // create the obsolete term (which is obsolete too!) obsoleteTopic = CvObjectUtils.createCvObject( IntactContext.getCurrentInstance().getInstitution(), CvTopic.class, CvTopic.OBSOLETE_MI_REF, CvTopic.OBSOLETE ); obsoleteTopic.setFullName( "obsolete term" ); addObsoleteAnnotation( obsoleteTopic, "Deprecated CV term that should not be used to annotate entries" ); } return obsoleteTopic; }
/** * Retrieves the annotations from an AnnotatedObject, initializing them if necessary. * * @param ao The annotated object instance with possibly non-initialized annotations * @return The returned annotations are ensured to be initialized * @since 2.4.0 */ public static Collection<Annotation> ensureInitializedAnnotations(AnnotatedObject ao) { Collection<Annotation> annotations; if (IntactCore.isInitialized(ao.getAnnotations())) { annotations = ao.getAnnotations(); } else { annotations = IntactContext.getCurrentInstance().getDaoFactory().getAnnotationDao().getByParentAc(ao.getClass(), ao.getAc()); } return annotations; }
public static <X extends Xref> Collection<X> getIdentityXrefs(AnnotatedObject<X, ?> annotatedObject) { Collection<X> xrefs = new ArrayList<X>(); Collection<X> allXrefs = annotatedObject.getXrefs(); if (!IntactCore.isInitialized(annotatedObject.getXrefs()) && IntactContext.currentInstanceExists()) { EntityManager entityManager = IntactContext.getCurrentInstance().getDaoFactory().getEntityManager(); // set the flush mode to manual to avoid hibernate trying to flush the session when querying the xrefs FlushModeType originalFlushMode = entityManager.getFlushMode(); entityManager.setFlushMode(FlushModeType.COMMIT); Class xrefClass = AnnotatedObjectUtils.getXrefClassType(annotatedObject.getClass()); allXrefs = IntactContext.getCurrentInstance().getDaoFactory().getXrefDao(xrefClass).getByParentAc(annotatedObject.getAc()); entityManager.setFlushMode(originalFlushMode); } for (X xref : allXrefs) { CvXrefQualifier qualifier = xref.getCvXrefQualifier(); String qualifierMi = null; if (qualifier != null && ((qualifierMi = qualifier.getIdentifier()) != null && qualifierMi.equals(CvXrefQualifier.IDENTITY_MI_REF))) { xrefs.add(xref); } } return xrefs; }
daoFactory.getBaseDao().persist( ao ); } catch (Exception e) { throw new PersisterException("Problem persisting: "+ao, e); throw new IllegalStateException( "Object to persist should have an AC: " + DebugUtil.annotatedObjectToString(ao, true)); } else { daoFactory.getBaseDao().merge( ao ); if (statisticsEnabled) statistics.addMerged(ao); daoFactory.getEntityManager().flush(); } catch (IllegalStateException ise) { if (ise.getCause() instanceof TransientObjectException) { final SessionImpl session = (SessionImpl) ((HibernateEntityManager) daoFactory.getEntityManager()).getSession(); final Map.Entry<Object, EntityEntry>[] entityEntries = session.getPersistenceContext().reentrantSafeEntityEntries();
public GeneratedEntry addInteractorWithUniprotId(String uniprotId) { List<ProteinImpl> interactors = intactContext.getDataContext().getDaoFactory() .getProteinDao().getByUniprotId(uniprotId); if (interactors.isEmpty()) { throw new IntactException("No interactors found with uniprot ID: " + uniprotId); } for (Interactor interactor : interactors) { addInteractor(interactor); } return this; }
@Transactional(propagation = Propagation.SUPPORTS) public boolean updateReferencesToObsoleteTerm(CvUpdateContext updateContext, DaoFactory factory, IntactOntologyTermI ontologyTerm, CvDagObject term, boolean couldRemap, CvUpdateManager manager, CvDagObject termFromDb, int resultUpdate) { if (term instanceof CvAliasType && termFromDb instanceof CvAliasType){ Query query = factory.getEntityManager().createQuery("update Alias a set a.cvAliasType = :type" + " where a.cvAliasType = :duplicate"); query.setParameter("type", termFromDb); Query query = factory.getEntityManager().createQuery("update Component c set c.cvBiologicalRole = :role" + " where c.cvBiologicalRole = :duplicate"); query.setParameter("role", termFromDb); Query query = factory.getEntityManager().createQuery("update BioSource b set b.cvCellType = :type" + " where b.cvCellType = :duplicate"); query.setParameter("type", termFromDb); Query query = factory.getEntityManager().createQuery("update BioSource b set b.cvCellCycle = :cycle" + " where b.cvCellCycle = :duplicate"); query.setParameter("cycle", termFromDb); Query query = factory.getEntityManager().createQuery("update BioSource b set b.cvTissue = :tissue" + " where b.cvTissue = :duplicate"); query.setParameter("tissue", termFromDb); Query query = factory.getEntityManager().createQuery("update Component c set c.cvComponentRole = :role" + " where c.cvComponentRole = :duplicate"); query.setParameter("role", termFromDb); Query query = factory.getEntityManager().createQuery("update BioSource b set b.cvCompartment = :compartment" + " where b.cvCompartment = :duplicate"); query.setParameter("compartment", termFromDb);
int countOfParticipants = intactContext.getDaoFactory().getInteractorDao().countComponentsForInteractorWithAc(child.getAc()); if (countOfParticipants > 0){ throw new IntactObjectDeleteException("The interactor " + child.getAc() + " cannot be deleted because it is still used in " + countOfParticipants + " participants."); int countOfInteractors = intactContext.getDaoFactory().getInteractorDao().getByBioSourceAc(child.getAc()).size(); if ( countOfInteractors > 0){ throw new IntactObjectDeleteException("The bioSource " + child.getAc() + " cannot be deleted because it is still used in " + countOfInteractors + " interactors."); int countOfExpressedIn = intactContext.getDaoFactory().getComponentDao().getByExpressedIn(child.getAc()).size(); if (countOfExpressedIn > 0){ throw new IntactObjectDeleteException("The bioSource " + child.getAc() + " cannot be deleted because it is still used in " + countOfExpressedIn + " participants as expressed in organism."); int countExperiments = intactContext.getDaoFactory().getExperimentDao().getByHostOrganism(child.getAc()).size(); if (countExperiments > 0){ throw new IntactObjectDeleteException("The bioSource " + child.getAc() + " cannot be deleted because it is still used in " + countExperiments + " experiments.");
log.info("annotation no_uniprot_update removed from the annotations of " + accession); prot.removeAnnotation(a); daoFactory.getAnnotationDao().delete(a); log.info("caution removed from the annotations of " + accession); prot.removeAnnotation(a2); daoFactory.getAnnotationDao().delete(a2); daoFactory.getProteinDao().update( prot ); accessionsToUpdate.add(accession);
/** * Retrieves the experimental preparations from a participant, initializing them if necessary. * Do not set the initialized collection of experimental preparations because cannot be orphan * @param component the component * @return The returned experimental preparations are ensured to be initialized * @since 2.4.0 */ public static Collection<CvExperimentalPreparation> ensureInitializedExperimentalPreparations(Component component) { Collection<CvExperimentalPreparation> expPrep; if (IntactCore.isInitialized(component.getExperimentalPreparations())) { expPrep = component.getExperimentalPreparations(); } else { expPrep = IntactContext.getCurrentInstance().getDaoFactory().getComponentDao().getExperimentalPreparationsForComponentAc(component.getAc()); } return expPrep; }
IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getAnnotationDao().persist( annotation ); IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getExperimentDao().update( experiment ); IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getAnnotationDao().update( annotation ); IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getExperimentDao().update( experiment ); IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getAnnotationDao().delete( annotation );
public XrefDao<Xref> getXrefDao() { return getXrefDao(Xref.class); }
System.out.println("Database instance: " + IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao().getDbName()); System.out.println("User: " + IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao().getDbUserName());
final AnnotatedObjectDao<T> dao = daoFactory.getAnnotatedObjectDao( ( Class<T> ) ao.getClass() ); final T managedObject = dao.getByAc( ac ); final BaseDao baseDao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao(); final AnnotatedObjectDao<T> dao = daoFactory.getAnnotatedObjectDao( ( Class<T> ) ao.getClass() );