Package net.sf.hibernate

Examples of net.sf.hibernate.Session


        }
    }

    public String getAttribute(int targetId, String name) throws RepositoryException {
        try {
            final Session session = ThreadSession.get();
            final Attribute id = new Attribute(targetId, name, null);
            Attribute attribute = (Attribute)session.load(Attribute.class, id);
            return attribute.getValue();
        } catch (net.sf.hibernate.ObjectNotFoundException e) {
            return null;
        } catch (RuntimeException e) {
            throw e;
View Full Code Here


    }

    public Map getAttributes(int targetId, String prefix) throws RepositoryException {
        HashMap attributes = new HashMap();
        try {
            final Session session = ThreadSession.get();
            String pattern = (prefix != null ? prefix : "")+"%";
            List attributeObjects = session.find("from a in "+Attribute.class+
                    " where targetId = ? and name like ?",
                    new Object[]{ new Integer(targetId), pattern },
                    new Type[]{ Hibernate.INTEGER, Hibernate.STRING });
            for (int i = 0; i < attributeObjects.size(); i++) {
                Attribute attribute = (Attribute)attributeObjects.get(i);
View Full Code Here

public class DataSamplingJob implements Job {
    private Logger log = Logger.getLogger(getClass());

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            Session session = null;
            try {
                session = GlobalSessionFactory.get().openSession();
                List iterations = session.find("from i in " + Iteration.class +
                        " where i.endDate >= ?", new Date(), Hibernate.DATE);
                Date now = new Date();
                for (int i = 0; i < iterations.size(); i++) {
                    Iteration iteration = (Iteration)iterations.get(i);
                    DataSample estimatedHoursSample = new DataSample(now, iteration.getId(),
                            "estimatedHours", iteration.getEstimatedHours());
                    session.save(estimatedHoursSample);
                    DataSample actualHoursSample = new DataSample(now, iteration.getId(),
                            "actualHours", iteration.getActualHours());
                    session.save(actualHoursSample);
                    DataSample remainingHoursSample = new DataSample(now, iteration.getId(),
                            "remainingHours", iteration.getRemainingHours());
                    session.save(remainingHoursSample);
                }
                log.info("committing data sample changes");
                session.flush();
                session.connection().commit();
            } catch (Throwable ex) {
                log.error("rolling back data sample changes", ex);
                session.connection().rollback();
            } finally {
                session.close();
            }
        } catch (SQLException e) {
            throw new JobExecutionException(
                    "SQL error while saving data samples, retrying...", e, true);
        } catch (Exception e) {
View Full Code Here

            ActionForm actionForm,
            HttpServletRequest request,
            HttpServletResponse reply) throws Exception {
        PersonTimesheetForm form = (PersonTimesheetForm)actionForm;
        try {
            Session session = getSession(request);
            try {
                PersonTimesheetQuery query = new PersonTimesheetQuery(getSession(request));
                query.setPersonId(form.getPersonId());
                query.setStartDate(form.getStartDate());
                query.setEndDate(form.getEndDate());
                form.setTimesheet(query.getTimesheet());
                if (form.getDateFormat() == null) {
                    String format = getResources(request).getMessage("format.date");
                    form.setDateFormat(new SimpleDateFormat(format));
                }

                return actionMapping.findForward("view/timesheet");
            } catch (Exception ex) {
                session.connection().rollback();
                log.error("error", ex);
                throw new ServletException(ex);
            }
        } catch (ServletException ex) {
            throw ex;
View Full Code Here

    private FileSystem fileSystem;

    protected ActionForward doExecute(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Session hibernateSession = getSession(request);
        FileManagerForm fform = (FileManagerForm)form;
        try {
            if (fform.getAction() == null) {
                fform.setAction("list");
                fform.setDirectoryId(Integer.toString(
                        fileSystem.getRootDirectory().getId()));
            }
            if (fform.getAction().equals("upload")) {
                FormFile formFile = fform.getFormFile();
                fileSystem.createFile(hibernateSession, Integer.parseInt(fform.getDirectoryId()), formFile.getFileName(),
                        formFile.getContentType(), formFile.getFileSize(), formFile.getInputStream());
            } else if (fform.getAction().equals("download")) {
                File file = fileSystem.getFile(hibernateSession, Integer.parseInt(fform.getFileId()));
                writeFileToResponse(response, file);
            } else if (fform.getAction().equals("delete")) {
                fileSystem.deleteFile(hibernateSession, Integer.parseInt(fform.getFileId()));
            } else if (fform.getAction().equals("mkdir")) {
                int parentDirectoryId = Integer.parseInt(fform.getDirectoryId());
                fileSystem.createDirectory(hibernateSession, parentDirectoryId, fform.getName());
            } else if (fform.getAction().equals("rmdir")) {
                Directory directory = fileSystem.getDirectory(hibernateSession, Integer.parseInt(fform.getDirectoryId()));
                Directory parent = directory.getParent();
                if (parent == null) {
                    parent = fileSystem.getRootDirectory();
                }
                fform.setDirectoryId(Integer.toString(parent.getId()));
                fileSystem.deleteDirectory(hibernateSession, directory.getId());
            }
            hibernateSession.flush();
            hibernateSession.connection().commit();
            if (fform.getDirectoryId() != null) {
                Directory directory = fileSystem.getDirectory(hibernateSession, Integer.parseInt(fform.getDirectoryId()));
                request.setAttribute("directory", directory);
            }
            request.setAttribute("root", fileSystem.getRootDirectory());
            return mapping.findForward("display");
        } catch (ObjectNotFoundException ex) {
            request.setAttribute("exception", ex);
            return mapping.findForward("error/objectNotFound");
        } catch (Exception e) {
            hibernateSession.connection().rollback();
            throw e;
        }
    }
View Full Code Here

    public Object getTargetObject() {
        return targetObject;
    }

    public void populate(Object object) throws Exception {
        Session session = ThreadSession.get();
        targetObject = object;
        if (object instanceof Project) {
            populate((Project)object);
        } else if (object instanceof Iteration) {
            populate(session, (Iteration)object);
View Full Code Here

    private void populate(Note note) throws Exception {
        populate(getNoteTarget(note.getAttachedToId()));
    }

    public static Object getNoteTarget(int attachedToId) throws Exception {
        Session session = ThreadSession.get();
        Object target = null;
        Integer id = new Integer(attachedToId);
        List types = Arrays.asList(new Class[]{ Project.class, Iteration.class, UserStory.class, Task.class });
        for (int i = 0; i < types.size(); i++) {
            Class attacheeClass = (Class)types.get(i);
            Object object = null;
            try {
                object = session.load(attacheeClass, id);
            } catch (ObjectNotFoundException e) {
                // ignored
            }
            if (object != null) {
                target = object;
View Full Code Here

    protected ActionForward doExecute(ActionMapping actionMapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse reply)
            throws Exception {
        TimeEditorForm form = (TimeEditorForm)actionForm;
        try {
            Session session = getSession(request);
            try {
                ActionForward forward = null;
                if (form.isSubmitted() == false) {
                    populateForm(session, form, request);
                    forward = new ActionForward(actionMapping.getInput());
                } else {
                    forward = doAction(session, form, request, actionMapping);
                }
                return forward;
            } catch (Exception ex) {
                session.connection().rollback();
                log.error("error", ex);
                throw new ServletException(ex);
            }
        } catch (ServletException ex) {
            throw ex;
View Full Code Here

                String oid = pageContext.getRequest().getParameter(DEFAULT_OID_PARAMETER);
                if (oid != null) {
                    objectId = new Integer(oid);
                }
            }
            Session session = getSession();
            try {
                Class clazz = Class.forName(type);
                Object object = session.load(clazz, objectId);
                pageContext.setAttribute(id, object, getScope());
                if (log.isDebugEnabled()) {
                    log.debug("bean loaded: " + id + " " + object);
                }
            } catch (Exception ex) {
View Full Code Here

            if (allowedUser != 0 &&
                    allowedUser == SecurityHelper.getRemoteUserId(
                            (HttpServletRequest)pageContext.getRequest())) {
                skipBody = false;
            } else {
                Session session;
                int projectId = getProjectId();
                int principalId = getPrincipalId();
                session = getSession();
                skipBody = checkPermission(session, projectId, principalId);
                if (skipBody == true && projectId == 0) {
                    // Has permission for any...
                    Collection projects = session.find("from project in "+Project.class);
                    for (Iterator iterator = projects.iterator(); iterator.hasNext();) {
                        Project project = (Project)iterator.next();
                        skipBody = checkPermission(session, project.getId(), principalId);
                        if (!skipBody) {
                            break;
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.