Example usage for org.hibernate FlushMode ALWAYS

List of usage examples for org.hibernate FlushMode ALWAYS

Introduction

In this page you can find the example usage for org.hibernate FlushMode ALWAYS.

Prototype

FlushMode ALWAYS

To view the source code for org.hibernate FlushMode ALWAYS.

Click Source Link

Document

The Session is flushed before every query.

Usage

From source file:com.miranteinfo.seam.hibernate.HibernateAutoFlushEventListener.java

License:Open Source License

private boolean flushIsReallyNeeded(AutoFlushEvent event, final EventSource source) {
    return source.getActionQueue().areTablesToBeUpdated(event.getQuerySpaces())
            || source.getFlushMode() == FlushMode.ALWAYS;
}

From source file:com.sos.hibernate.classes.SosHibernateSession.java

License:Apache License

public static Session getInstance(final File configurationFile) {
    if (session == null) {
        ClassLoader classLoader = ClassLoader.getSystemClassLoader();
        try {/*  w ww.j  a v a 2s. c om*/
            Configuration configuration = new Configuration();
            try {
                Class dailyScheduleDBItem = classLoader
                        .loadClass("com.sos.dailyschedule.db.DailyScheduleDBItem");
                configuration.addAnnotatedClass(dailyScheduleDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class schedulerTaskHistoryDBItem = classLoader
                        .loadClass("com.sos.scheduler.history.db.SchedulerTaskHistoryDBItem");
                configuration.addAnnotatedClass(schedulerTaskHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class schedulerOrderStepHistoryDBItem = classLoader
                        .loadClass("com.sos.scheduler.history.db.SchedulerOrderStepHistoryDBItem");
                configuration.addAnnotatedClass(schedulerOrderStepHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class schedulerOrderHistoryDBItem = classLoader
                        .loadClass("com.sos.scheduler.history.db.SchedulerOrderHistoryDBItem");
                configuration.addAnnotatedClass(schedulerOrderHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class schedulerInstancesDBItem = classLoader
                        .loadClass("com.sos.scheduler.db.SchedulerInstancesDBItem");
                configuration.addAnnotatedClass(schedulerInstancesDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class jadeFilesDBItem = classLoader.loadClass("sos.ftphistory.db.JadeFilesDBItem");
                configuration.addAnnotatedClass(jadeFilesDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class JadeFilesHistoryDBItem = classLoader
                        .loadClass("sos.ftphistory.db.JadeFilesHistoryDBItem");
                configuration.addAnnotatedClass(JadeFilesHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class SchedulerEventDBItem = classLoader.loadClass("com.sos.eventing.db.SchedulerEventDBItem");
                configuration.addAnnotatedClass(SchedulerEventDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class jobNetPlanDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetPlanDBItem");
                configuration.addAnnotatedClass(jobNetPlanDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class jobNetNodeDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetNodeDBItem");
                configuration.addAnnotatedClass(jobNetNodeDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class jobNetEdgesDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetEdgesDBItem");
                configuration.addAnnotatedClass(jobNetEdgesDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class eventsDBItem = classLoader.loadClass("com.sos.jobnet.db.EventsDBItem");
                configuration.addAnnotatedClass(eventsDBItem);
            } catch (ClassNotFoundException e) {
            }
            try {
                Class jobNetHistoryDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetHistoryDBItem");
                configuration.addAnnotatedClass(jobNetHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class jobNetCmdHistoryDBItem = classLoader
                        .loadClass("com.sos.jobnet.db.JobNetCmdHistoryDBItem");
                configuration.addAnnotatedClass(jobNetCmdHistoryDBItem);
            } catch (ClassNotFoundException e) {
            }

            try {
                Class jobNetDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetDBItem");
                configuration.addAnnotatedClass(jobNetDBItem);
            } catch (ClassNotFoundException e) {
            }

            // Configuration configuration = new Configuration();
            // Configuration configuration = new
            // Configuration().addAnnotatedClass(dailyScheduleDBItem).addAnnotatedClass(schedulerTaskHistoryDBItem).addAnnotatedClass(schedulerOrderStepHistoryDBItem)
            // .addAnnotatedClass(schedulerOrderHistoryDBItem).addAnnotatedClass(schedulerInstancesDBItem).addAnnotatedClass(jobNetPlanDBItem).addAnnotatedClass(jobNetNodeDBItem).addAnnotatedClass(jobNetEdgesDBItem);
            configuration.configure(configurationFile);
            /*
             * serviceRegistry = new
             * ServiceRegistryBuilder().applySettings(configuration
             * .getProperties()).buildServiceRegistry(); sessionFactory =
             * configuration.buildSessionFactory(serviceRegistry);
             * 
             * configuration.setSessionFactoryObserver(new
             * SessionFactoryObserver() {
             * 
             * @Override public void sessionFactoryCreated(SessionFactory
             * factory) { }
             * 
             * @Override public void sessionFactoryClosed(SessionFactory
             * factory) { ServiceRegistryBuilder.destroy(serviceRegistry); }
             * });
             */
            sessionFactory = configuration.buildSessionFactory();
            session = sessionFactory.openSession();
            session.doWork(new Work() {
                public void execute(Connection connection) throws SQLException {
                    connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                    connection.setAutoCommit(false);
                }
            });
            session.setFlushMode(FlushMode.ALWAYS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        session.clear();
    }
    return session;
}

From source file:com.sos.hibernate.classes.SosHibernateSession.java

License:Apache License

public static Session getInstance(IHibernateOptions options) {
    if (session == null) {
        ClassLoader classLoader = ClassLoader.getSystemClassLoader();
        try {//w  ww . j  av  a  2  s  .  co m
            Class dailyScheduleDBItem = classLoader.loadClass("com.sos.dailyschedule.db.DailyScheduleDBItem");
            Class schedulerTaskHistoryDBItem = classLoader
                    .loadClass("com.sos.scheduler.history.db.SchedulerTaskHistoryDBItem");
            Class schedulerOrderStepHistoryDBItem = classLoader
                    .loadClass("com.sos.scheduler.history.db.SchedulerOrderStepHistoryDBItem");
            Class schedulerOrderHistoryDBItem = classLoader
                    .loadClass("com.sos.scheduler.history.db.SchedulerOrderHistoryDBItem");
            Class schedulerInstancesDBItem = classLoader
                    .loadClass("com.sos.scheduler.db.SchedulerInstancesDBItem");
            Class schedulerEventDBItem = classLoader.loadClass("com.sos.eventing.db.SchedulerEventDBItem");

            Class jobNetPlanDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetPlanDBItem");
            Class jobNetNodeDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetNodeDBItem");
            Class jobNetEdgesDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetEdgesDBItem");

            Class eventsDBItem = classLoader.loadClass("com.sos.Jobnet.db.EventsDBItem");

            Class jobNetHistoryDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetHistoryDBItem");
            Class jobNetCmdHistoryDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetCmdHistoryDBItem");
            Class jobNetDBItem = classLoader.loadClass("com.sos.jobnet.db.JobNetDBItem");

            // Configuration configuration = new Configuration();
            Configuration configuration = new Configuration().addAnnotatedClass(dailyScheduleDBItem)
                    .addAnnotatedClass(schedulerTaskHistoryDBItem)
                    .addAnnotatedClass(schedulerOrderStepHistoryDBItem)
                    .addAnnotatedClass(schedulerOrderHistoryDBItem).addAnnotatedClass(schedulerInstancesDBItem)
                    .addAnnotatedClass(jobNetPlanDBItem).addAnnotatedClass(jobNetNodeDBItem)
                    .addAnnotatedClass(jobNetEdgesDBItem).addAnnotatedClass(schedulerEventDBItem);
            configuration.setProperty("hibernate.connection.url",
                    options.gethibernate_connection_url().Value());
            configuration.setProperty("hibernate.connection.password",
                    options.gethibernate_connection_password().Value());
            configuration.setProperty("hibernate.connection.url",
                    options.gethibernate_connection_url().Value());
            configuration.setProperty("hibernate.connection.username",
                    options.gethibernate_connection_username().Value());
            configuration.setProperty("hibernate.dialect", options.gethibernate_dialect().Value());
            configuration.setProperty("hibernate.show_sql", options.gethibernate_show_sql().Value());
            configuration.setProperty("hibernate.connection.autocommit",
                    options.gethibernate_connection_autocommit().Value());
            configuration.setProperty("hibernate.format_sql", options.gethibernate_format_sql().Value());
            sessionFactory = configuration.buildSessionFactory();
            session = sessionFactory.openSession();
            session.setFlushMode(FlushMode.ALWAYS);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        session.clear();
    }
    return session;
}

From source file:eionet.webq.dao.KnownHostsTest.java

License:Mozilla Public License

@Before
public void before() throws Exception {
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.ALWAYS);
}

From source file:eionet.webq.dao.ProjectFileStorageImplTest.java

License:Mozilla Public License

@Before
public void setUp() throws Exception {
    defaultProjectFile = projectFileWithFileType(WEBFORM);
    defaultProjectFile.setFileName("UniqueName");
    projectFileStorage.save(defaultProjectFile, testProjectEntry(2));
    currentSession = sessionFactory.getCurrentSession();
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.ALWAYS);
}

From source file:eionet.webq.dao.ProjectFoldersAndFilesTest.java

License:Mozilla Public License

@Before
public void setUp() throws Exception {
    currentSession = sessionFactory.getCurrentSession();
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.ALWAYS);
}

From source file:eionet.webq.dao.UserFileStorageImplTest.java

License:Mozilla Public License

@Before
public void setUp() throws Exception {
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.ALWAYS);
}

From source file:entities.EVotingPersistentManager.java

private EVotingPersistentManager() throws PersistentException {
    super(_connectionSetting, _sessionType, _timeToAlive, new String[] {}, _extraProperties,
            _configurationFile);/*from  w w  w .  j  av a2 s.  co m*/
    setFlushMode(FlushMode.ALWAYS);
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer absentPersonCount(Integer roadOperationId) {
    /* Get Count of Absent Persons */
    Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(AssignedPersonDO.class, "a");

    List<Integer> teamIds = getTeamIdsForRoadOp(roadOperationId);

    if (teamIds != null && teamIds.size() > 0)
        criteriaAssignedPersons.add(Restrictions.in("a.assignedPersonKey.team.teamId", teamIds));

    criteriaAssignedPersons.add(Restrictions.eq("a.attended", "n").ignoreCase());
    criteriaAssignedPersons.setProjection(Projections.count("a.attended"));
    criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY);
    Iterator iterator = criteriaAssignedPersons.list().iterator();

    Integer AbsentMembersCount = (Integer) iterator.next();

    criteriaAssignedPersons.setFlushMode(FlushMode.ALWAYS);
    return AbsentMembersCount;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer absentPersonTeamCount(Integer teamId) {
    /* Get Count of Absent Persons */
    Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(AssignedPersonDO.class, "a");
    criteriaAssignedPersons.add(Restrictions.eq("a.assignedPersonKey.team.teamId", teamId));
    criteriaAssignedPersons.add(Restrictions.eq("a.attended", "n").ignoreCase());
    criteriaAssignedPersons.setProjection(Projections.count("a.attended"));
    criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY);
    Iterator iterator = criteriaAssignedPersons.list().iterator();

    Integer AbsentMembersCount = (Integer) iterator.next();

    criteriaAssignedPersons.setFlushMode(FlushMode.ALWAYS);
    return AbsentMembersCount;
}