use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.
the class HibernatePredefinedInsertionHandler method convert.
private UnitEntity convert(Unit unit) {
UnitEntity entity = new UnitEntity();
entity.setSymbol(unit.getSymbol(), getDaoFactory().isStaSupportsUrls());
entity.setName(unit.getName());
entity.setLink(unit.getLink());
if (unit.hasTranslations()) {
Set<I18nEntity<? extends Describable>> trans = new LinkedHashSet<>();
unit.getTranslations().forEach(i -> {
I18nUnitEntity i18n = new I18nUnitEntity();
i18n.setLocale(i.getLocale());
i18n.setName(i.getName());
i18n.setDescription(i.getDescription());
trans.add(i18n);
});
entity.setTranslations(trans);
}
return entity;
}
use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.
the class UnitDAO method getOrInsertUnit.
/**
* Insert and get unit object
*
* @param unit
* Unit
* @param session
* Hibernate session
* @return Unit object
*/
public UnitEntity getOrInsertUnit(UoM unit, Session session) {
UnitEntity result = getUnit(unit.getUom(), session);
if (result == null) {
result = new UnitEntity();
result.setUnit(unit.getUom());
if (unit.isSetName()) {
result.setName(unit.getName());
}
if (unit.isSetLink()) {
result.setLink(unit.getLink());
}
session.save(result);
session.flush();
session.refresh(result);
}
return result;
}
use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.
the class UnitDAO method getUnit.
/**
* Get unit object for unit
*
* @param unit
* Unit
* @param session
* Hibernate session
* @return Unit object
*/
public UnitEntity getUnit(String unit, Session session) {
Criteria criteria = session.createCriteria(UnitEntity.class).add(Restrictions.eq(UnitEntity.PROPERTY_UNIT, unit));
LOGGER.trace(QUERY_UNIT_TEMPLATE, HibernateHelper.getSqlString(criteria));
return (UnitEntity) criteria.uniqueResult();
}
use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.
the class UnitDAO method getUnit.
/**
* Get unit object for unit
*
* @param unit
* Unit
* @param session
* Hibernate session
* @return Unit object
*/
public UnitEntity getUnit(UoM unit, Session session) {
Criteria criteria = session.createCriteria(UnitEntity.class).add(Restrictions.eq(UnitEntity.PROPERTY_UNIT, unit.getUom()));
LOGGER.trace(QUERY_UNIT_TEMPLATE, HibernateHelper.getSqlString(criteria));
return (UnitEntity) criteria.uniqueResult();
}
use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.
the class ParameterVisitor method addUnit.
protected void addUnit(ParameterEntity<?> vp, Value<?> v) {
if (!v.isSetUnit() && vp instanceof HasUnit && ((HasUnit) vp).isSetUnit()) {
UnitEntity unit = ((HasUnit) vp).getUnit();
UoM uom = new UoM(unit.getUnit());
if (unit.isSetName()) {
uom.setName(unit.getName());
}
if (unit.isSetLink()) {
uom.setLink(unit.getLink());
}
v.setUnit(uom);
}
}
Aggregations