Package net.sf.hibernate

Examples of net.sf.hibernate.Session


public class FileTest {
    public static void main(String[] args) {
        try {
            HibernateHelper.initializeHibernate();
            Session session = GlobalSessionFactory.get().openSession();
            createTestData(session);
            session.flush();
            session.connection().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


        }
        return domainContext;
    }

    private Object getObject(int id, String type) throws Exception {
        Session session = getSession();
        return session.load(Class.forName(type), new Integer(id));
    }
View Full Code Here

    }

    public Person getPerson(String userId) throws AuthenticationException {
        try {
            Session session = ThreadSession.get();
            List people = session.find("from person in class " +
                                       Person.class.getName() + " where userid = ?",
                                       userId, Hibernate.STRING);
            Iterator peopleIterator = people.iterator();
            if (peopleIterator.hasNext()) {
                return (Person)peopleIterator.next();
View Full Code Here

    protected ActionForward doExecute(ActionMapping actionMapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse reply)
            throws Exception {
        try {
            Session session = getSession(request);
            try {
                ActionForward forward = actionMapping.findForward("display");
                int projectId = Integer.parseInt(request.getParameter("projectId"));
                if (request.getParameter("action.join") != null) {
                    forward = onJoinRequest(session, request, actionMapping, projectId);
                } else if (isLeaveRequest(request)) {
                    onLeaveRequest(session, request, projectId);
                } else if (request.getParameter("action.start") != null) {
                    forward = onStartRequest(session, actionMapping, request, projectId);
                } else if (request.getParameter("action.finish") != null) {
                    onFinishRequest(session, request, projectId);
                } else if (request.getParameter("action.cancel") != null) {
                    onCancelRequest(session, request, projectId);
                } else if (request.getParameter("personId") != null &&
                        request.getParameter("comment") != null) {
                    // default if no action, <cr> in comment field instead of pressing button
                    forward = onStartRequest(session, actionMapping, request, projectId);
                }
                session.flush();
                session.connection().commit();
                return addProjectId(request, forward);
            } catch (Exception ex) {
                session.connection().rollback();
                return actionMapping.findForward("error");
            }
        } catch (Exception ex) {
            throw new ServletException("session error", ex);
        }
View Full Code Here

        String namesQuery = "select person.name, person.id from person in " +
                "class org.nxplanner.domain.Person where person.hidden = false";

        HashMap names = new HashMap();
        Session session = ThreadSession.get();
        try {
            try {
                names.clear();
                List nameResults = session.find(namesQuery);
                Iterator iter = nameResults.iterator();
                while (iter.hasNext()) {
                    Object[] result = (Object[])iter.next();
                    names.put(result[1], result[0]);
                }

                developerMetrics.clear();
                List acceptedTasks = session.find(acceptedTaskQuery, new Integer(iterationId), Hibernate.INTEGER);
                Iterator acceptedTaskIter = acceptedTasks.iterator();
                while (acceptedTaskIter.hasNext()) {
                    Object[] result = (Object[])acceptedTaskIter.next();
                    double acceptedHours = toDouble(result[2]);
                    if (acceptedHours > 0.0) {
                        getDeveloperMetrics((String)names.get(result[1]),
                                toInt(result[1]), iterationId).setAcceptedHours(acceptedHours);
                    }
                }

                totalHours = 0.0;
                maxDeveloperHours = 0.0;
                List hoursResults = session.find(hoursQuery, new Integer(iterationId), Hibernate.INTEGER);
                Iterator hoursIterator = hoursResults.iterator();
                while (hoursIterator.hasNext()) {
                    Object[] result = (Object[])hoursIterator.next();
                    int person1Id = toInt(result[0]);
                    int person2Id = toInt(result[1]);
                    Date startTime = (Date)result[2];
                    Date endTime = (Date)result[3];
                    int acceptorId = toInt(result[4]);
                    double duration = toDouble(result[5]);
                    if ((endTime != null && startTime != null) || duration != 0) {
                        double hours = duration == 0 ?
                                (endTime.getTime() - startTime.getTime()) / 3600000.0 :
                                duration;
                        boolean isPaired = person1Id != 0 && person2Id != 0;
                        if (person1Id != 0) {
                            updateWorkedHours(iterationId, (String)names.get(result[0]),
                                    person1Id, hours, isPaired, acceptorId);
                            totalHours += hours;
                        }
                        if (person2Id != 0) {
                            updateWorkedHours(iterationId, (String)names.get(result[1]),
                                    person2Id, hours, isPaired, acceptorId);
                            totalHours += hours;
                        }
                    }
                }
            } catch (Exception ex) {
                if (session.isConnected()) {
                    session.connection().rollback();
                }
                log.error("error", ex);
            }
        } catch (Exception ex) {
            log.error("error", ex);
View Full Code Here

    public RoleRepositoryImpl() {
        super(Role.class);
    }

    public Role findRoleByName(String rolename) throws RepositoryException {
        Session session = ThreadSession.get();
        List roles = null;
        try {
            roles = session.find("from role in class " +
                    Role.class.getName() + " where role.name = ?",
                    rolename, Hibernate.STRING);
        } catch (HibernateException e) {
            throw new RepositoryException();
        }
View Full Code Here

        log.log(loggingPriority, "initialized");
    }

    public Subject authenticate(String userId, String password) throws AuthenticationException {
        try {
            Session session = ThreadSession.get();
            try {
                log.log(loggingPriority, "attempting to authenticate: " + userId);
                Person person = getPerson(session, userId);
                if (person != null) {
                    if (isPasswordMatched(person, password)) {
View Full Code Here

    }

    public void changePassword(String userId, String password) throws AuthenticationException {
        log.log(loggingPriority, "changing password for " + userId);
        try {
            Session session = ThreadSession.get();
            try {
                Person person = getPerson(session, userId);
                if (person != null) {
                    person.setPassword(encodePassword(password, null));
                    session.flush();
                    session.connection().commit();
                } else {
                    throw new AuthenticationException("couldn't find person.");
                }
            } catch (Throwable ex) {
                session.connection().rollback();
                log.error("error during password change.", ex);
                throw new AuthenticationException("server error.");
            } finally {
                session.close();
            }
        } catch (Exception e) {
            log.error("error", e);
            throw new AuthenticationException("server error.");
        }
View Full Code Here

    public Object produceDataset(Map parameters) throws DatasetProduceException {
        List results = null;
        try {
            results = null;
            Session session = ThreadSession.get();
            results = session.find(query);
        } catch (Exception e) {
            throw new DatasetProduceException(e.getMessage());
        }
        DefaultPieDataset data = new DefaultPieDataset();
        for (int i = 0; i < results.size(); i++) {
View Full Code Here

public class ExportAction extends AbstractAction {
    private Exporter exporter;

    protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Session session = getSession(request);
        try {
            Class objectClass = getObjectType(mapping, request);
            Object object = getRepository(objectClass).load(Integer.parseInt(request.getParameter("oid")));
            byte[] data = exporter.export(session, object);
            exporter.initializeHeaders(response);
            response.getOutputStream().write(data);
        } catch (Exception ex) {
            throw new ExportException(ex);
        } finally {
            session.connection().rollback();
        }

        // Optional forward
        return mapping.findForward("display");
    }
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.