Search in sources :

Example 1 with HibernateObservationBuilder

use of org.n52.sos.ds.hibernate.util.HibernateObservationBuilder in project SOS by 52North.

the class CacheQueryTest method fillObservations.

@BeforeClass
public static void fillObservations() throws OwsExceptionReport {
    Session session = getSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
        I18NDAORepository i18NDAORepository = new I18NDAORepository();
        DaoFactory daoFactory = new DaoFactory();
        daoFactory.setI18NDAORepository(i18NDAORepository);
        HibernateObservationBuilder b = new HibernateObservationBuilder(session, daoFactory);
        DateTime begin = new DateTime();
        int numObs = 10000;
        for (int i = 0; i < numObs; ++i) {
            if (i % 50 == 0) {
                LOGGER.debug(LOG_TEMPLATE, i, numObs);
                session.flush();
                session.clear();
            }
            b.createObservation(String.valueOf(i), begin.plusHours(i));
        }
        LOGGER.debug(LOG_TEMPLATE, numObs, numObs);
        session.flush();
        transaction.commit();
    } catch (HibernateException | CodedException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw he;
    } finally {
        returnSession(session);
    }
}
Also used : Transaction(org.hibernate.Transaction) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) HibernateException(org.hibernate.HibernateException) I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) HibernateObservationBuilder(org.n52.sos.ds.hibernate.util.HibernateObservationBuilder) DateTime(org.joda.time.DateTime) Session(org.hibernate.Session) BeforeClass(org.junit.BeforeClass)

Example 2 with HibernateObservationBuilder

use of org.n52.sos.ds.hibernate.util.HibernateObservationBuilder in project SOS by 52North.

the class TemporalRestrictionTest method getBuilder.

protected HibernateObservationBuilder getBuilder(Session session) throws OwsExceptionReport {
    I18NDAORepository i18NDAORepository = new I18NDAORepository();
    DaoFactory daoFactory = new DaoFactory();
    daoFactory.setI18NDAORepository(i18NDAORepository);
    return new HibernateObservationBuilder(session, daoFactory);
}
Also used : I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory)

Example 3 with HibernateObservationBuilder

use of org.n52.sos.ds.hibernate.util.HibernateObservationBuilder in project SOS by 52North.

the class TemporalRestrictionPeriodInstantTest method createScenario.

@Override
public TimeInstant createScenario(Session session) throws OwsExceptionReport {
    Transaction transaction = null;
    try {
        DateTime ref = new DateTime(DateTimeZone.UTC).minusDays(1);
        transaction = session.beginTransaction();
        HibernateObservationBuilder b = getBuilder(session);
        b.createObservation(TemporalRestrictionTest.Identifier.PI_BEGUN_BY_ID, ref, ref.plus(1));
        b.createObservation(TemporalRestrictionTest.Identifier.PI_ENDED_BY_ID, ref.minus(1), ref);
        b.createObservation(TemporalRestrictionTest.Identifier.PI_AFTER_ID, ref.plus(1), ref.plus(2));
        b.createObservation(TemporalRestrictionTest.Identifier.PI_BEFORE_ID, ref.minus(2), ref.minus(1));
        b.createObservation(TemporalRestrictionTest.Identifier.PI_CONTAINS_ID, ref.minus(1), ref.plus(1));
        session.flush();
        transaction.commit();
        return new TimeInstant(ref);
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw he;
    }
}
Also used : Transaction(org.hibernate.Transaction) HibernateException(org.hibernate.HibernateException) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 4 with HibernateObservationBuilder

use of org.n52.sos.ds.hibernate.util.HibernateObservationBuilder in project SOS by 52North.

the class ObservationDAOTest method fillObservations.

@Before
public void fillObservations() throws OwsExceptionReport {
    Session session = getSession();
    HibernateMetadataCache.init(session);
    Transaction transaction = null;
    try {
        I18NDAORepository i18NDAORepository = new I18NDAORepository();
        DaoFactory daoFactory = new DaoFactory();
        daoFactory.setI18NDAORepository(i18NDAORepository);
        observationDAO = daoFactory.getObservationDAO();
        offeringDAO = daoFactory.getOfferingDAO();
        transaction = session.beginTransaction();
        HibernateObservationBuilder b;
        b = new HibernateObservationBuilder(session, daoFactory);
        DateTime begin = DateTimeHelper.parseIsoString2DateTime("2019-10-01T12:00:00.000Z");
        for (int i = 0; i < 50; ++i) {
            b.createObservation(String.valueOf(i), begin.plusHours(i));
        }
        session.flush();
        transaction.commit();
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw he;
    } finally {
        returnSession(session);
    }
}
Also used : Transaction(org.hibernate.Transaction) HibernateException(org.hibernate.HibernateException) I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) DateTime(org.joda.time.DateTime) Session(org.hibernate.Session) Before(org.junit.Before)

Example 5 with HibernateObservationBuilder

use of org.n52.sos.ds.hibernate.util.HibernateObservationBuilder in project SOS by 52North.

the class TemporalRestrictionInstantPeriodTest method createScenario.

@Override
protected TimePeriod createScenario(Session session) throws OwsExceptionReport {
    Transaction transaction = null;
    try {
        DateTime ref = new DateTime(DateTimeZone.UTC).minusDays(1);
        transaction = session.beginTransaction();
        HibernateObservationBuilder b = getBuilder(session);
        b.createObservation(TemporalRestrictionTest.Identifier.IP_BEFORE_ID, ref.minus(2));
        b.createObservation(TemporalRestrictionTest.Identifier.IP_BEGINS_ID, ref.minus(1));
        b.createObservation(TemporalRestrictionTest.Identifier.IP_DURING_ID, ref);
        b.createObservation(TemporalRestrictionTest.Identifier.IP_ENDS_ID, ref.plus(1));
        b.createObservation(TemporalRestrictionTest.Identifier.IP_AFTER_ID, ref.plus(2));
        session.flush();
        transaction.commit();
        return new TimePeriod(ref.minus(1), ref.plus(1));
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw he;
    }
}
Also used : Transaction(org.hibernate.Transaction) HibernateException(org.hibernate.HibernateException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DateTime(org.joda.time.DateTime)

Aggregations

HibernateException (org.hibernate.HibernateException)6 Transaction (org.hibernate.Transaction)6 DateTime (org.joda.time.DateTime)6 I18NDAORepository (org.n52.iceland.i18n.I18NDAORepository)3 Session (org.hibernate.Session)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)2 DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)2 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1 HibernateObservationBuilder (org.n52.sos.ds.hibernate.util.HibernateObservationBuilder)1