/** * If a domain class uses more than one datasource, we need to know which one to use when calling * a method without a namespace qualifier. * * @param domainClass the domain class * @return the default datasource name */ public static String getDefaultDataSource(PersistentEntity domainClass) { List<String> names = getDatasourceNames(domainClass); if (names.size() == 1 && Mapping.ALL_DATA_SOURCES.equals(names.get(0))) { return Mapping.DEFAULT_DATA_SOURCE; } return names.get(0); }
public static void main(String[] args) { EventManager mgr = new EventManager(); if (args[0].equals("store")) { mgr.createAndStoreEvent("My Event", new Date()); } else if (args[0].equals("list")) { List events = mgr.listEvents(); for (int i = 0; i < events.size(); i++) { Event theEvent = (Event) events.get(i); System.out.println("Event: " + theEvent.getTitle() + " Time: " + theEvent.getDate()); } } else if (args[0].equals("addpersontoevent")) { Long eventId = mgr.createAndStoreEvent("My Event", new Date()); Long personId = mgr.createAndStorePerson("Foo", "Bar"); mgr.addPersonToEvent(personId, eventId); System.out.println("Added person " + personId + " to event " + eventId); } else if (args[0].equals("addemailtoperson")) { Long personId = mgr.createAndStorePerson("Foozy", "Beary"); mgr.addEmailToPerson(personId, "foo@bar"); mgr.addEmailToPerson(personId, "bar@foo"); System.out.println( "Added two email addresses (value typed objects) to person entity : " + personId); } HibernateUtil.getSessionFactory().close(); }
public EventNumberOfPassesRequest getEventPassesRequest(User user, Event event) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from EventNumberOfPassesRequest as eventNumberOfPassesRequest " + "where eventNumberOfPassesRequest.idevent=" + event.getIdevent() + " and eventNumberOfPassesRequest.iduser=" + user.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { return (EventNumberOfPassesRequest) result.get(0); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return null; }
public ActivityPartnerRequest getPartnerRequest(User user, Activity activity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from ActivityPartnerRequest as partnerrequest " + "where partnerrequest.idactivity=" + activity.getIdactivity() + " and partnerrequest.iduser=" + user.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { return (ActivityPartnerRequest) result.get(0); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return null; }
public User getUserByEmail(String email) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); List list = session.createQuery("from User as user where user.mail = '" + email + "'").list(); transaction.commit(); if (list != null && list.size() == 1) { return (User) list.get(0); } return null; }
private User getUserByEmployeeId(String employeeId) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); String queryString = "from User user where user.employeeId ='" + employeeId + "'"; List list = session.createQuery(queryString).list(); transaction.commit(); if (list != null && list.size() == 1) { return (User) list.get(0); } return null; }
public MessageBundleProperty getProperty(MessageBundleProperty mbp) { Object[] values = new Object[] { mbp.getBaseName(), mbp.getModuleName(), mbp.getPropertyName(), mbp.getLocale() }; String sql = "from MessageBundleProperty where baseName = ? and moduleName = ? and propertyName = ? and locale = ?"; List<?> results = getHibernateTemplate().find(sql, values); if (results.size() == 0) { logger.debug("can't find a default value for : " + mbp); return null; } return (MessageBundleProperty) results.get(0); }
public User getUserByName(String firstName, String lastName) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); String queryString = "from User user where user.firstname ='" + firstName + "' and user.lastname ='" + lastName + "'"; // System.out.println("queryString = " + queryString); List list = session.createQuery(queryString).list(); transaction.commit(); if (list != null && list.size() == 1) { return (User) list.get(0); } return null; }