Package net.sf.hibernate

Examples of net.sf.hibernate.Session


        return EVAL_BODY_INCLUDE;
    }

    public int doEndTag() throws JspException {
        try {
            Session session = getSession();
            try {
                List objects = null;
                if (qname == null) {
                    String hql = null;
                    if (getBodyContent() == null) {
                        hql = "from object in class " + type;
                        if (where != null) {
                            hql += " where " + where;
                        }
                        if (order != null) {
                            hql += " order by " + order;
                        }
                    } else {
                        hql = getBodyContent().getString();
                    }
                    Query query = session.createQuery(hql);
                    objects = bindParametersAndExecute(query);
                } else {
                    objects = new ArrayList();
                    String[] queryNames = qname.split(",");
                    for (int i = 0; i < queryNames.length; i++) {
                        objects.addAll(bindParametersAndExecute(session.getNamedQuery(queryNames[i])));
                    }
                }
                pageContext.setAttribute(id, objects);
                if (log.isDebugEnabled()) {
                    log.debug("loaded beans: " + id + " " + objects);
View Full Code Here


    }

    public void run(String[] args) {
        try {
            HibernateHelper.initializeHibernate();
            Session session = GlobalSessionFactory.get().openSession();
            List projects = session.find("from project in "+Project.class+" where project.hidden = false");
            try {
                if (isOldRoleTableExisting()) {
                    upgradeRoles(session, projects);
                    dropTable(session, "personrole");
                }
            } finally {
                session.flush();
                session.connection().commit();
                session.close();
            }
        } catch (Exception e) {
            log.error("error", e);
        }
View Full Code Here

    public boolean isOldRoleTableExisting() throws SQLException, HibernateException {
        boolean oldRoleTableExists = false;
        // Some databases (e.g. PostgreSQL) invalidate the transaction when
        // an exception is thrown. Creating a separate session isolates the
        // main test set up code from this behavior.
        Session session = GlobalSessionFactory.get().openSession();
        Statement statement = session.connection().createStatement();
        try {
            statement.execute("select * from personrole");
            oldRoleTableExists = true;
        } catch (SQLException e) {
            if (e.getMessage().indexOf("doesn't exist") == -1 &&
                    e.getMessage().indexOf("does not exist") == -1) {
                log.error(tableCheckError, e);
            }
        } finally {
            statement.close();
            session.close();
        }
        return oldRoleTableExists;
    }
View Full Code Here

    private static final String PARAM_USE_PROXY = "HIBERNATE_FILTER_USE_PROXY";
    private boolean useProxy = true;

    public void doFilter(ServletRequest request, ServletResponse aResponse, FilterChain aChain)
            throws IOException, ServletException {
        Session session = null;
        boolean sessionWasCreated = false;

        try {
            // We will try to get  the Hiberate Session from the request.  If
            // it doesn't exist, then we will create it, otherwise
            // we will use the one that already exists.
            session = (Session)request.getAttribute(SESSION_ATTRIBUTE_KEY);

            if (session == null) {
                SessionFactory sessionFactory = GlobalSessionFactory.get();
                if (useProxy) {
                    session = SessionProxy.createProxy(this, sessionFactory);
                } else {
                    session = sessionFactory.openSession();
                    if (log.isDebugEnabled()) {
                        log.debug("Session opened: "+session);
                    }
                }
                request.setAttribute(SESSION_ATTRIBUTE_KEY, session);
                ThreadSession.set(session);
                sessionWasCreated = true;
                log.debug("Session created: "+session);
            } else {
                log.debug("Reusing session from request: "+session);
            }
        } catch (Exception exc) {
            log.error("Error opening Hibernate session.", exc);
        }

        try {
            aChain.doFilter(request, aResponse);
        } finally {
            try {
                if (sessionWasCreated) {
                    if (session != null) {
                        // Only try to close the connection if it is open,
                        // since it might have been closed somewhere else
                        // by mistake.
                        if (session.isOpen()) {
                            session.close();
                            if (log.isDebugEnabled()) {
                                log.debug("Session closed: "+session);
                            }
                        } else {
                            log.debug("Session already closed: "+session);
View Full Code Here


        try {
            List users = parseTomcatUsersFile(filename);
            HibernateHelper.initializeHibernate();
            Session session = GlobalSessionFactory.get().openSession();
            XPlannerLoginModule encryptor = new XPlannerLoginModule(new HashMap());
            Iterator userItr = users.iterator();
            while (userItr.hasNext()) {
                User user = (User)userItr.next();
                try {
                    Person person = getPerson(session, user);
                    if (person != null) {
                        initializePassword(person, log, user, encryptor);
                        initializeRoles(session, user, person);
                    } else {
                        log.warn("no xplanner user: " + user.getName());
                    }
                    session.flush();
                    session.connection().commit();
                } catch (Throwable e) {
                    log.error("error", e);
                    session.connection().rollback();
                }
            }
            session.close();
        } catch (Exception e) {
            log.error("error", e);
        }
    }
View Full Code Here

    }

    public void run(String[] args) {
        try {
            HibernateHelper.initializeHibernate();
            Session session = GlobalSessionFactory.get().openSession();
            HashSet missingPreviousColumns = new HashSet();
            missingPreviousColumns.add("filename");
            missingPreviousColumns.add("content_type");
            missingPreviousColumns.add("file");
            missingPreviousColumns.add("file_size");
            DatabaseMetaData metaData = session.connection().getMetaData();
            ResultSet columns = metaData.getColumns(null, "%", "note", "%");
            while (columns.next()) {
                missingPreviousColumns.remove(columns.getString("COLUMN_NAME"));
            }
            if (missingPreviousColumns.size() == 4) {
View Full Code Here

        tester.submit();
        tester.assertKeyPresent("projects.title");
    }

    private void commit() throws HibernateException, SQLException {
        Session session = tester.getSession();
        session.flush();
        session.connection().commit();
    }
View Full Code Here

    private String type;
    private MetaRepository metaRepository;

    public final ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        Session session = ThreadSession.get();
        Transaction transaction = session.beginTransaction();
        try {
            ActionForward forward = doExecute(mapping, form, request, response);
            Object object = request.getAttribute(TARGET_OBJECT);
            if (object != null) {
                beforeObjectCommit(object, session, mapping, form, request, response);
View Full Code Here

        }
    }

    private Collection getCurrentTasks() throws HibernateException {
        if (cachedCurrentTasks == null) {
            Session session = ThreadSession.get();
            cachedCurrentTasks = queryTasks(session, "tasks.current.accepted");
            cachedCurrentTasks.addAll(queryTasks(session, "tasks.current.worked"));
        }
        return cachedCurrentTasks;
    }
View Full Code Here

    protected DomainObject createObject(Class objectClass,
                                        HttpServletRequest request,
                                        AbstractEditorForm form,
                                        ObjectRepository objectRepository) throws Exception
    {
        Session session = ThreadSession.get();
        DomainObject person = super.createObject(objectClass, request, form, objectRepository);
        session.save(new Permission("system.person",person.getId(),person.getId(),"edit%"));
        session.save(new Permission("system.person",0,person.getId(),"read%"));

        return person;
    }
View Full Code Here

TOP

Related Classes of net.sf.hibernate.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.