eventapp.impl.EventDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for eventapp.impl.EventDAOImpl.java

Source

/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidade do Minho
 * License Type: Academic
 */
package eventapp.impl;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;
import eventapp.*;

public class EventDAOImpl implements eventapp.dao.EventDAO {
    public Event loadEventByORMID(int ID) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return loadEventByORMID(session, ID);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event getEventByORMID(int ID) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return getEventByORMID(session, ID);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return loadEventByORMID(session, ID, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event getEventByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return getEventByORMID(session, ID, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByORMID(PersistentSession session, int ID) throws PersistentException {
        try {
            return (Event) session.load(eventapp.Event.class, new Integer(ID));
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event getEventByORMID(PersistentSession session, int ID) throws PersistentException {
        try {
            return (Event) session.get(eventapp.Event.class, new Integer(ID));
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            return (Event) session.load(eventapp.Event.class, new Integer(ID), lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event getEventByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            return (Event) session.get(eventapp.Event.class, new Integer(ID), lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public List queryEvent(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return queryEvent(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public List queryEvent(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return queryEvent(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event[] listEventByQuery(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return listEventByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event[] listEventByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return listEventByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public List queryEvent(PersistentSession session, String condition, String orderBy) throws PersistentException {
        StringBuffer sb = new StringBuffer("From eventapp.Event as Event");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            return query.list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public List queryEvent(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From eventapp.Event as Event");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            query.setLockMode("Event", lockMode);
            return query.list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event[] listEventByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        try {
            List list = queryEvent(session, condition, orderBy);
            return (Event[]) list.toArray(new Event[list.size()]);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event[] listEventByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            List list = queryEvent(session, condition, orderBy, lockMode);
            return (Event[]) list.toArray(new Event[list.size()]);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByQuery(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return loadEventByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return loadEventByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event loadEventByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        Event[] events = listEventByQuery(session, condition, orderBy);
        if (events != null && events.length > 0)
            return events[0];
        else
            return null;
    }

    public Event loadEventByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        Event[] events = listEventByQuery(session, condition, orderBy, lockMode);
        if (events != null && events.length > 0)
            return events[0];
        else
            return null;
    }

    public java.util.Iterator iterateEventByQuery(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return iterateEventByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public java.util.Iterator iterateEventByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = eventapp.ArchitecturePersistentManager.instance().getSession();
            return iterateEventByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public java.util.Iterator iterateEventByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        StringBuffer sb = new StringBuffer("From eventapp.Event as Event");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            return query.iterate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public java.util.Iterator iterateEventByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From eventapp.Event as Event");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            query.setLockMode("Event", lockMode);
            return query.iterate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public Event createEvent() {
        return new eventapp.Event();
    }

    public boolean save(eventapp.Event event) throws PersistentException {
        try {
            eventapp.ArchitecturePersistentManager.instance().saveObject(event);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean delete(eventapp.Event event) throws PersistentException {
        try {
            eventapp.ArchitecturePersistentManager.instance().deleteObject(event);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean deleteAndDissociate(eventapp.Event event) throws PersistentException {
        try {
            if (event.getOrganizationUser() != null) {
                event.getOrganizationUser().events.remove(event);
            }

            if (event.getEventCategory() != null) {
                event.getEventCategory().events.remove(event);
            }

            eventapp.RegularUser[] lRegularUserss = event.regularUsers.toArray();
            for (int i = 0; i < lRegularUserss.length; i++) {
                lRegularUserss[i].events.remove(event);
            }
            return delete(event);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean deleteAndDissociate(eventapp.Event event, org.orm.PersistentSession session)
            throws PersistentException {
        try {
            if (event.getOrganizationUser() != null) {
                event.getOrganizationUser().events.remove(event);
            }

            if (event.getEventCategory() != null) {
                event.getEventCategory().events.remove(event);
            }

            eventapp.RegularUser[] lRegularUserss = event.regularUsers.toArray();
            for (int i = 0; i < lRegularUserss.length; i++) {
                lRegularUserss[i].events.remove(event);
            }
            try {
                session.delete(event);
                return true;
            } catch (Exception e) {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean refresh(eventapp.Event event) throws PersistentException {
        try {
            eventapp.ArchitecturePersistentManager.instance().getSession().refresh(event);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean evict(eventapp.Event event) throws PersistentException {
        try {
            eventapp.ArchitecturePersistentManager.instance().getSession().evict(event);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

}