Search in sources :

Example 6 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class OccurrenceDaoHibernateImpl method getFieldUnitUuidAndTitleCache.

@Override
public List<UuidAndTitleCache<FieldUnit>> getFieldUnitUuidAndTitleCache() {
    List<UuidAndTitleCache<FieldUnit>> list = new ArrayList<>();
    Session session = getSession();
    Query query = session.createQuery("select uuid, id, titleCache from " + type.getSimpleName() + " where dtype = " + FieldUnit.class.getSimpleName());
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<FieldUnit>(FieldUnit.class, (UUID) object[0], (Integer) object[1], (String) object[2]));
    }
    return list;
}
Also used : FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 7 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class OccurrenceDaoHibernateImpl method getDerivedUnitUuidAndTitleCache.

@Override
public List<UuidAndTitleCache<DerivedUnit>> getDerivedUnitUuidAndTitleCache(Integer limit, String pattern) {
    List<UuidAndTitleCache<DerivedUnit>> list = new ArrayList<>();
    Session session = getSession();
    String hql = "SELECT uuid, id, titleCache " + " FROM " + type.getSimpleName() + " WHERE NOT dtype = " + FieldUnit.class.getSimpleName();
    Query query;
    if (pattern != null) {
        pattern = pattern.replace("*", "%");
        pattern = pattern.replace("?", "_");
        pattern = pattern + "%";
        query = session.createQuery(hql + " AND titleCache like :pattern");
        query.setParameter("pattern", pattern);
    } else {
        query = session.createQuery(hql);
    }
    if (limit != null) {
        query.setMaxResults(limit);
    }
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<DerivedUnit>(DerivedUnit.class, (UUID) object[0], (Integer) object[1], (String) object[2]));
    }
    return list;
}
Also used : FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) UUID(java.util.UUID) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 8 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class TermNodeDaoImpl method getUuidAndTitleCache.

protected List<UuidAndTitleCache<TermNode>> getUuidAndTitleCache(Query query) {
    List<UuidAndTitleCache<TermNode>> list = new ArrayList<>();
    List<Object> result = query.list();
    for (Object obj : result) {
        if (obj instanceof SortableTaxonNodeQueryResult) {
            SortableTaxonNodeQueryResult stnqr = (SortableTaxonNodeQueryResult) obj;
            list.add(new UuidAndTitleCache<>(stnqr.getTaxonNodeUuid(), stnqr.getTaxonNodeId(), stnqr.getTaxonTitleCache()));
        } else {
            Object[] object = (Object[]) obj;
            list.add(new UuidAndTitleCache<>((UUID) object[0], (Integer) object[1], (String) object[2]));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)

Example 9 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetDao method getDescriptiveDataSetUuidAndTitleCache.

/**
 * {@inheritDoc}
 */
@Override
public List<UuidAndTitleCache<DescriptiveDataSet>> getDescriptiveDataSetUuidAndTitleCache(Integer limitOfInitialElements, String pattern) {
    Session session = getSession();
    String queryString = "SELECT uuid, id, label FROM DescriptiveDataSet ";
    if (pattern != null) {
        queryString += " WHERE ";
        queryString += " label LIKE :pattern";
    }
    Query query;
    query = session.createQuery(queryString);
    if (limitOfInitialElements != null) {
        query.setMaxResults(limitOfInitialElements);
    }
    if (pattern != null) {
        pattern = pattern.replace("*", "%");
        pattern = pattern.replace("?", "_");
        pattern = pattern + "%";
        query.setParameter("pattern", pattern);
    }
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    List<UuidAndTitleCache<DescriptiveDataSet>> list = new ArrayList<>();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<DescriptiveDataSet>(DescriptiveDataSet.class, (UUID) object[0], (Integer) object[1], (String) object[2]));
    }
    return list;
}
Also used : Query(org.hibernate.Query) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) UUID(java.util.UUID) Session(org.hibernate.Session)

Example 10 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class ReferenceDaoHibernateImpl method getUuidAndTitle.

@Override
public List<UuidAndTitleCache<Reference>> getUuidAndTitle() {
    List<UuidAndTitleCache<Reference>> list = new ArrayList<UuidAndTitleCache<Reference>>();
    Session session = getSession();
    Query query = session.createQuery("select uuid, id, titleCache from " + type.getSimpleName());
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<Reference>(type, (UUID) object[0], (Integer) object[1], (String) object[2]));
    }
    return list;
}
Also used : Query(org.hibernate.Query) Reference(eu.etaxonomy.cdm.model.reference.Reference) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)38 ArrayList (java.util.ArrayList)31 UUID (java.util.UUID)27 Query (org.hibernate.Query)17 Session (org.hibernate.Session)10 AuditQuery (org.hibernate.envers.query.AuditQuery)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)5 Test (org.junit.Test)5 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 SortableTaxonNodeQueryResult (eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 FullTextSession (org.hibernate.search.FullTextSession)4 DataSet (org.unitils.dbunit.annotation.DataSet)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TreeIndex (eu.etaxonomy.cdm.model.common.TreeIndex)3 Primer (eu.etaxonomy.cdm.model.molecular.Primer)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3