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));
}
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);
}
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);
}
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;
}
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]);
}
Aggregations