List of usage examples for org.hibernate Hibernate initialize
public static void initialize(Object proxy) throws HibernateException
From source file:com.piccritic.compute.post.PostService.java
public Album getDefaultAlbum(String handle) { uc = new JPAUserConnector(); Critic user = uc.selectCritic(handle); Set<Album> albums = user.getAlbums(); Hibernate.initialize(albums); Album defaultAlbum = null;/*from w w w . ja v a 2 s . c o m*/ for (Album a : albums) { if (a.getName().equals("default")) { defaultAlbum = a; } } return defaultAlbum; }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns the library which locationId matches with the given id number. * Initializes image, map, areas and collections objects related to the * library, so that the library can be edited. * * @param libraryId locationId that is used for searching * @param owner the owner of the object//from w w w .j a v a 2 s . c om * @return library with the desired locationId or null if matching library * doesn't exist */ @Override public Library getLibrary(int libraryId, Owner owner) { List<Library> list = (List<Library>) getHibernateTemplate().findByNamedParam( "from Library library " + "left join fetch library.image " + "left join fetch library.map " + "left join fetch library.areas " + "join fetch library.owner as owner " + "where owner.code like :owner " + "and library.locationId = :libraryId", new String[] { "owner", "libraryId" }, new Object[] { owner.getCode(), libraryId }); if (list.isEmpty()) { return null; } Hibernate.initialize(list.get(0).getCollections()); Hibernate.initialize(list.get(0).getDescriptions()); Hibernate.initialize(list.get(0).getNotes()); return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns the library which locationId matches with the given id number. * Initializes areas, collections and shelves related to the given library * object, so that the library and the objects related to it can be deleted. * * @param libraryId locationId that is used for searching * @param owner the owner of the object//from w w w .ja v a 2s .c o m * @return library with the desired locationId or null if matching library * doesn't exist */ @Override public Library getLibraryToBeDeleted(int libraryId, Owner owner) { DetachedCriteria criteria = DetachedCriteria.forClass(Library.class) .add(Restrictions.eq("locationId", libraryId)).add(Restrictions.eq("owner", owner)) .setFetchMode("areas", FetchMode.JOIN); List<Library> list = (List<Library>) getHibernateTemplate().findByCriteria(criteria); if (list.isEmpty()) { return null; } Hibernate.initialize(list.get(0).getDescriptions()); Hibernate.initialize(list.get(0).getNotes()); Hibernate.initialize(list.get(0).getImage()); Hibernate.initialize(list.get(0).getMap()); List<LibraryCollection> collections = list.get(0).getCollections(); for (LibraryCollection collection : collections) { Hibernate.initialize(collection.getShelves()); } return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns the collection which locationId matches with the given id number * and that belongs to the given library. Initializes image, map, areas, * subject matters and shelves objects related to the collection, so that * the collection can be edited.//from ww w. jav a 2s . c o m * * @param collectionId locationId that is used for searching * @param libraryId locationId of the library * @param owner the owner of the object * @return the collection with the desired locationId or null if matching * collection doesn't exist */ @Override public LibraryCollection getCollection(int collectionId, int libraryId, Owner owner) { String libCondition = ""; if (libraryId != 0) { libCondition = " and library.locationId = " + libraryId; } List<LibraryCollection> list = (List<LibraryCollection>) getHibernateTemplate().findByNamedParam( "from LibraryCollection collection " + "left join fetch collection.image " + "left join fetch collection.map " + "left join fetch collection.areas " + "join fetch collection.owner as owner " + "join fetch collection.library as library " + "where owner.code like :owner " + "and collection.locationId = :collectionId" + libCondition, new String[] { "owner", "collectionId" }, new Object[] { owner.getCode(), collectionId }); if (list.isEmpty()) { return null; } Hibernate.initialize(list.get(0).getShelves()); Hibernate.initialize(list.get(0).getSubjectMatters()); Hibernate.initialize(list.get(0).getDescriptions()); Hibernate.initialize(list.get(0).getNotes()); return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns the collection which locationId matches with the given id number * and that belongs to the given library. Initializes areas, subject matters * and shelves related to the given collection object, so that the * collection and the objects related to it can be deleted. * * @param collectionId locationId that is used for searching * @param libraryId locationId of the library * @param owner the owner of the object// www . j a v a2 s .c o m * @return collection with the given locationId or null if matching * collection doesn't exist */ @Override public LibraryCollection getCollectionToBeDeleted(int collectionId, int libraryId, Owner owner) { String libCondition = ""; if (libraryId != 0) { libCondition = " and library.locationId = " + libraryId; } List<LibraryCollection> list = (List<LibraryCollection>) getHibernateTemplate().findByNamedParam( "from LibraryCollection collection " + "left join fetch collection.image " + "left join fetch collection.map " + "left join fetch collection.areas " + "join fetch collection.owner as owner " + "join fetch collection.library as library " + "where owner.code like :owner " + "and collection.locationId = :collectionId" + libCondition, new String[] { "owner", "collectionId" }, new Object[] { owner.getCode(), collectionId }); if (list.isEmpty()) { return null; } Hibernate.initialize(list.get(0).getShelves()); Hibernate.initialize(list.get(0).getSubjectMatters()); Hibernate.initialize(list.get(0).getDescriptions()); Hibernate.initialize(list.get(0).getNotes()); return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns the shelf which locationId matches with the given id number. * Initializes image, map, areas and subject matters objects related to the * shelf, so that the shelf can be edited. * * @param shelfId locationId that is used for searching * @param collectionId locationId of the collection * @param libraryId locationId of the library * @param owner the owner of the object/* w ww . j a v a 2 s . c o m*/ * @return shelf with the desired locationId or null if matching shelf is * not found */ @Override public Shelf getShelf(int shelfId, int collectionId, int libraryId, Owner owner) { String libCondition = ""; if (libraryId != 0) { libCondition = " and collection.library.locationId = " + libraryId; } String colCondition = ""; if (collectionId != 0) { colCondition = " and collection.locationId = " + collectionId; } List<Shelf> list = (List<Shelf>) getHibernateTemplate().findByNamedParam( "from Shelf shelf " + "left join fetch shelf.image " + "left join fetch shelf.map " + "left join fetch shelf.areas " + "join fetch shelf.collection as collection " + "join fetch shelf.collection.library as library " + "join fetch shelf.owner as owner " + "where owner.code like :owner " + "and shelf.locationId = :shelfId" + colCondition + libCondition, new String[] { "owner", "shelfId" }, new Object[] { owner.getCode(), shelfId }); if (list.isEmpty()) { return null; } Hibernate.initialize(list.get(0).getSubjectMatters()); Hibernate.initialize(list.get(0).getDescriptions()); Hibernate.initialize(list.get(0).getNotes()); return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java
License:Open Source License
/** * Returns a list of collections that belong to the library with the given * location id. Search indexes and shelves with their search indexes are * loaded too.// w w w .j a va 2 s.co m * * @param locationId id of the library * @return list of collections */ @Override public List<LibraryCollection> getCollectionsForIndexUpdate(int locationId) { List<LibraryCollection> list = (List<LibraryCollection>) getHibernateTemplate().findByNamedParam( "from LibraryCollection as collection " + "left join fetch collection.searchIndexes si " + "join fetch collection.library as library " + "where library.locationId = :locationId", "locationId", locationId); for (LibraryCollection col : list) { for (Shelf shelf : col.getShelves()) { Hibernate.initialize(shelf.getSearchIndexes()); } } return list; }
From source file:com.pkrete.locationservice.admin.dao.owners.OwnersDaoImpl.java
License:Open Source License
/** * Returns the owner with the given id with all the collections related to * the owner loaded. If the owner cannot be found, null is returned. * * @param id the id that is used for searching * @return the owner with the given id or null *///from w w w . j av a 2 s .c om @Override public Owner getFullOwner(int id) { List<Owner> list = (List<Owner>) getHibernateTemplate().findByNamedParam( "from Owner owner left join fetch owner.languages " + "where owner.id=:id", "id", id); if (list.isEmpty()) { return null; } Owner owner = list.get(0); Hibernate.initialize(owner.getNotFoundRedirects()); Hibernate.initialize(owner.getPreprocessingRedirects()); return list.get(0); }
From source file:com.pkrete.locationservice.admin.dao.owners.OwnersDaoImpl.java
License:Open Source License
/** * Deletes the given owner object from the database. * * @param owner the owner to be deleted//from w ww.j a v a 2s . c o m * @return true if and only if the object was successfully deleted; * otherwise false */ @Override public boolean delete(Owner owner) { try { Owner temp = this.getOwner(owner.getId()); Hibernate.initialize(temp.getLanguages()); getHibernateTemplate().delete(temp); } catch (Exception e) { localLogger.error(e.getMessage()); return false; } return true; }
From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java
License:Open Source License
/** * Returns the library which location id matches the given id. All the lazy * relationships are loaded.//from w ww. j ava 2s. com * * @param id location id to be searched * @return library matching the given location id */ @Override public Library getLibrary(int id) { List<Library> list = (List<Library>) getHibernateTemplate() .findByNamedParam("from Library as lib " + "left join fetch lib.image " + "left join fetch lib.map " + "left join fetch lib.areas " + "where lib.locationId = :id", "id", id); if (list.isEmpty()) { return null; } Library lib = list.get(0); Hibernate.initialize(lib.getNotes()); Hibernate.initialize(lib.getDescriptions()); return lib; }