Search in sources :

Example 1 with LongType

use of org.hibernate.type.LongType in project BroadleafCommerce by BroadleafCommerce.

the class TranslationDaoImpl method getEntityId.

@Override
public String getEntityId(TranslatedEntity entityType, Object entity) {
    Map<String, Object> idMetadata = getIdPropertyMetadata(entityType);
    String idProperty = (String) idMetadata.get("name");
    Type idType = (Type) idMetadata.get("type");
    if (!(idType instanceof LongType || idType instanceof StringType)) {
        throw new UnsupportedOperationException("Only ID types of String and Long are currently supported");
    }
    Object idValue;
    try {
        idValue = PropertyUtils.getProperty(entity, idProperty);
    } catch (Exception e) {
        throw new RuntimeException("Error reading id property", e);
    }
    if (idType instanceof StringType) {
        return (String) idValue;
    } else if (idType instanceof LongType) {
        return getUpdatedEntityId(entityType, (Long) idValue);
    }
    throw new IllegalArgumentException(String.format("Could not retrieve value for id property. Object: [%s], " + "ID Property: [%s], ID Type: [%s]", entity, idProperty, idType));
}
Also used : StringType(org.hibernate.type.StringType) LongType(org.hibernate.type.LongType) ResultType(org.broadleafcommerce.common.extension.ResultType) Type(org.hibernate.type.Type) LongType(org.hibernate.type.LongType) StringType(org.hibernate.type.StringType)

Example 2 with LongType

use of org.hibernate.type.LongType in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method findByGene.

@Override
public Collection<ExpressionExperiment> findByGene(Gene gene) {
    /*
         * uses GENE2CS table.
         */
    // language=MySQL
    final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, ARRAY_DESIGN ad, BIO_ASSAY ba, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND ad.ID = cs.ARRAY_DESIGN_FK AND ba.ARRAY_DESIGN_USED_FK = ad.ID AND" + " ba.EXPRESSION_EXPERIMENT_FK = ee.ID AND g2s.GENE = :geneID";
    Collection<Long> eeIds;
    Session session = this.getSessionFactory().getCurrentSession();
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
    queryObject.setLong("geneID", gene.getId());
    queryObject.addScalar("eeID", new LongType());
    ScrollableResults results = queryObject.scroll();
    eeIds = new HashSet<>();
    while (results.next()) {
        eeIds.add(results.getLong(0));
    }
    return this.load(eeIds);
}
Also used : LongType(org.hibernate.type.LongType) org.hibernate(org.hibernate)

Example 3 with LongType

use of org.hibernate.type.LongType in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method findByExpressedGene.

@Override
public Collection<ExpressionExperiment> findByExpressedGene(Gene gene, Double rank) {
    // language=MySQL
    final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, PROCESSED_EXPRESSION_DATA_VECTOR dedv, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND cs.ID = dedv.DESIGN_ELEMENT_FK AND dedv.EXPRESSION_EXPERIMENT_FK = ee.ID" + " AND g2s.gene = :geneID AND dedv.RANK_BY_MEAN >= :rank";
    Collection<Long> eeIds;
    try {
        Session session = this.getSessionFactory().getCurrentSession();
        org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
        queryObject.setLong("geneID", gene.getId());
        queryObject.setDouble("rank", rank);
        queryObject.addScalar("eeID", new LongType());
        ScrollableResults results = queryObject.scroll();
        eeIds = new HashSet<>();
        // Post Processing
        while (results.next()) eeIds.add(results.getLong(0));
        session.clear();
    } catch (org.hibernate.HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
    return this.load(eeIds);
}
Also used : LongType(org.hibernate.type.LongType) org.hibernate(org.hibernate)

Example 4 with LongType

use of org.hibernate.type.LongType in project dhis2-core by dhis2.

the class HibernatePropertyIntrospector method createProperty.

private Property createProperty(Class<?> klass, org.hibernate.mapping.Property hibernateProperty, MetamodelImplementor metamodelImplementor) {
    Property property = new Property(klass);
    property.setRequired(false);
    property.setPersisted(true);
    property.setWritable(true);
    property.setOwner(true);
    Type type = hibernateProperty.getType();
    property.setName(hibernateProperty.getName());
    property.setFieldName(hibernateProperty.getName());
    property.setCascade(hibernateProperty.getCascade());
    property.setCollection(type.isCollectionType());
    property.setSetterMethod(hibernateProperty.getSetter(klass).getMethod());
    property.setGetterMethod(hibernateProperty.getGetter(klass).getMethod());
    if (property.isCollection()) {
        initCollectionProperty(metamodelImplementor, property, (CollectionType) type);
    }
    if (type instanceof SingleColumnType || type instanceof CustomType || type instanceof ManyToOneType) {
        Column column = (Column) hibernateProperty.getColumnIterator().next();
        property.setUnique(column.isUnique());
        property.setRequired(!column.isNullable());
        property.setMin(0d);
        property.setMax((double) column.getLength());
        property.setLength(column.getLength());
        if (type instanceof TextType) {
            property.setMin(0d);
            property.setMax((double) Integer.MAX_VALUE);
            property.setLength(Integer.MAX_VALUE);
        } else if (type instanceof IntegerType) {
            property.setMin((double) Integer.MIN_VALUE);
            property.setMax((double) Integer.MAX_VALUE);
            property.setLength(Integer.MAX_VALUE);
        } else if (type instanceof LongType) {
            property.setMin((double) Long.MIN_VALUE);
            property.setMax((double) Long.MAX_VALUE);
            property.setLength(Integer.MAX_VALUE);
        } else if (type instanceof DoubleType) {
            property.setMin(-Double.MAX_VALUE);
            property.setMax(Double.MAX_VALUE);
            property.setLength(Integer.MAX_VALUE);
        }
    }
    if (type instanceof ManyToOneType) {
        property.setManyToOne(true);
        property.setRequired(property.isRequired() && !property.isCollection());
        if (property.isOwner()) {
            property.setOwningRole(klass.getName() + "." + property.getName());
        } else {
            property.setInverseRole(klass.getName() + "." + property.getName());
        }
    } else if (type instanceof OneToOneType) {
        property.setOneToOne(true);
    } else if (type instanceof OneToMany) {
        property.setOneToMany(true);
    }
    return property;
}
Also used : CustomType(org.hibernate.type.CustomType) IntegerType(org.hibernate.type.IntegerType) CustomType(org.hibernate.type.CustomType) CollectionType(org.hibernate.type.CollectionType) ManyToOneType(org.hibernate.type.ManyToOneType) IntegerType(org.hibernate.type.IntegerType) TextType(org.hibernate.type.TextType) LongType(org.hibernate.type.LongType) SingleColumnType(org.hibernate.type.SingleColumnType) OneToOneType(org.hibernate.type.OneToOneType) SetType(org.hibernate.type.SetType) DoubleType(org.hibernate.type.DoubleType) Type(org.hibernate.type.Type) LongType(org.hibernate.type.LongType) SingleColumnType(org.hibernate.type.SingleColumnType) ManyToOneType(org.hibernate.type.ManyToOneType) Column(org.hibernate.mapping.Column) DoubleType(org.hibernate.type.DoubleType) OneToMany(org.hibernate.mapping.OneToMany) Property(org.hisp.dhis.schema.Property) TextType(org.hibernate.type.TextType) OneToOneType(org.hibernate.type.OneToOneType)

Example 5 with LongType

use of org.hibernate.type.LongType in project gocd by gocd.

the class MaterialRepository method getOldestAndLatestModificationId.

public PipelineRunIdInfo getOldestAndLatestModificationId(long materialId, String pattern) {
    String queryString = "SELECT MAX(modifications.id) as latestRunId, MIN(modifications.id) as oldestRunId " + "FROM modifications " + "WHERE modifications.materialid = :materialId ";
    Map<String, Object> params = new HashMap<>();
    params.put("materialId", materialId);
    if (isNotBlank(pattern)) {
        queryString = queryString + "  AND (LOWER(modifications.comment) LIKE :pattern " + "  OR LOWER(modifications.userName) LIKE :pattern " + "  OR LOWER(modifications.revision) LIKE :pattern ) ";
        params.put("pattern", "%" + pattern.toLowerCase() + "%");
    }
    String finalQueryString = queryString;
    Object[] info = (Object[]) getHibernateTemplate().execute((HibernateCallback) session -> {
        SQLQuery query = session.createSQLQuery(finalQueryString);
        query.setProperties(params);
        return query.addScalar("latestRunId", new LongType()).addScalar("oldestRunId", new LongType()).uniqueResult();
    });
    if (info == null || info[0] == null || info[1] == null) {
        return null;
    }
    return new PipelineRunIdInfo((long) info[0], (long) info[1]);
}
Also used : LongType(org.hibernate.type.LongType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback)

Aggregations

LongType (org.hibernate.type.LongType)12 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 StringType (org.hibernate.type.StringType)5 org.hibernate (org.hibernate)4 PipelineId (com.thoughtworks.go.server.ui.PipelineId)3 CollectionUtil (com.thoughtworks.go.server.util.CollectionUtil)3 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)3 ModificationForPipeline (com.thoughtworks.go.server.ui.ModificationForPipeline)2 ResultType (org.broadleafcommerce.common.extension.ResultType)2 Type (org.hibernate.type.Type)2 AbstractMaterial (com.thoughtworks.go.config.materials.AbstractMaterial)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 Materials (com.thoughtworks.go.config.materials.Materials)1 com.thoughtworks.go.domain (com.thoughtworks.go.domain)1 com.thoughtworks.go.domain.materials (com.thoughtworks.go.domain.materials)1 DependencyMaterialInstance (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialInstance)1 CacheKeyGenerator (com.thoughtworks.go.server.cache.CacheKeyGenerator)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 FeedModifier (com.thoughtworks.go.server.dao.FeedModifier)1 Database (com.thoughtworks.go.server.database.Database)1