List of usage examples for org.apache.ibatis.session SqlSession getMapper
<T> T getMapper(Class<T> type);
From source file:com.bibisco.manager.ImageManager.java
License:GNU General Public License
public static String load(Integer pIntIdImage) { String lStrFileName = null;/*from w ww. ja va 2s . c o m*/ mLog.debug("Start load(ImageDTO)"); // validate preconditions Validate.notNull(pIntIdImage, "argument idImage cannot be null"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class); Images lImages = lImagesMapper.selectByPrimaryKey(pIntIdImage.longValue()); if (lImages != null) { lStrFileName = lImages.getFileName(); } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End load(ImageDTO)"); return lStrFileName; }
From source file:com.bibisco.manager.ImageManager.java
License:GNU General Public License
public static List<ImageDTO> loadImagesByElement(Integer pIntIdElement, ElementType pElementType) { List<ImageDTO> lListImageDTO = new ArrayList<ImageDTO>(); mLog.debug("Start loadImagesByElement(Integer, ElementType"); // validate preconditions Validate.notNull(pIntIdElement, "argument idElement cannot be null"); Validate.notNull(pElementType, "argument ElementType cannot be null"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w w w. j a v a2s.c o m*/ ImagesExample lImagesExample = new ImagesExample(); lImagesExample.createCriteria().andIdElementEqualTo(pIntIdElement) .andElementTypeEqualTo(pElementType.getValue()); lImagesExample.setOrderByClause("id_image"); ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class); List<Images> lListImages = lImagesMapper.selectByExample(lImagesExample); for (Images lImages : lListImages) { ImageDTO lImageDTO = new ImageDTO(); lImageDTO.setIdImage(lImages.getIdImage().intValue()); lImageDTO.setDescription(lImages.getDescription()); lImageDTO.setElementType(pElementType); lImageDTO.setIdElement(pIntIdElement); lListImageDTO.add(lImageDTO); } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadImagesByElement(ImageDTO"); return lListImageDTO; }
From source file:com.bibisco.manager.ImageManager.java
License:GNU General Public License
public static void delete(Integer pIntIdImage) { mLog.debug("Start delete(Integer)"); // validate preconditions Validate.notNull(pIntIdImage, "argument idImage cannot be null"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w w w . j a va 2s . c o m*/ ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class); // load image to delete Images lImages = lImagesMapper.selectByPrimaryKey(pIntIdImage.longValue()); if (lImages != null) { // delete image file on disk deleteFile(lImages.getFileName()); // delete image on db lImagesMapper.deleteByPrimaryKey(pIntIdImage.longValue()); lSqlSession.commit(); } } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End delete(Integer)"); }
From source file:com.bibisco.manager.ImageManager.java
License:GNU General Public License
public static void deleteImagesByElement(SqlSession pSqlSession, Integer pIntIdElement, ElementType pElementType) { mLog.debug("Start deleteImagesByElement(SqlSession, Integer, ElementType)"); // validate preconditions Validate.notNull(pSqlSession, "argument SqlSession cannot be null"); Validate.notNull(pIntIdElement, "argument idElement cannot be null"); Validate.notNull(pElementType, "argument ElementType cannot be null"); try {/* w w w.ja v a 2s . co m*/ ImagesExample lImagesExample = new ImagesExample(); lImagesExample.createCriteria().andIdElementEqualTo(pIntIdElement) .andElementTypeEqualTo(pElementType.getValue()); ImagesMapper lImagesMapper = pSqlSession.getMapper(ImagesMapper.class); // load images to delete List<Images> lListImages = lImagesMapper.selectByExample(lImagesExample); // delete image files on disk for (Images lImages : lListImages) { deleteFile(lImages.getFileName()); } // delete images on db lImagesMapper.deleteByExample(lImagesExample); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } mLog.debug("End deleteImagesByElement(SqlSession, Integer, ElementType)"); }
From source file:com.bibisco.manager.LocaleManager.java
License:GNU General Public License
private Locale initLocale() { Locale lLocale = null;/*ww w .j a va 2 s. c o m*/ mLog.debug("Start initLocale()"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = lPropertiesMapper.selectByPrimaryKey("locale"); if (lProperties != null) { String[] lStrLocaleSplit = lProperties.getValue().split("_"); lLocale = new Locale(lStrLocaleSplit[0], lStrLocaleSplit[1]); } else { lLocale = Locale.getDefault(); // save locale lProperties = new Properties(); lProperties.setProperty("locale"); lProperties.setValue(lLocale.toString()); lPropertiesMapper.insert(lProperties); lSqlSession.commit(); } } catch (Throwable t) { lSqlSession.rollback(); mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End initLocale()"); return lLocale; }
From source file:com.bibisco.manager.LocaleManager.java
License:GNU General Public License
public void saveLocale(String pStrLocale) { mLog.debug("Start saveLocale(String)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w w w . java 2 s . c om*/ PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("locale"); lProperties.setValue(pStrLocale); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); String[] lStrLocaleSplit = pStrLocale.split("_"); mLocale = new Locale(lStrLocaleSplit[0], lStrLocaleSplit[1]); } catch (Throwable t) { lSqlSession.rollback(); mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End saveLocale(String)"); }
From source file:com.bibisco.manager.LocationManager.java
License:GNU General Public License
public static List<LocationDTO> loadAll() { List<LocationDTO> lListLocationDTO = null; mLog.debug("Start loadAll()"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {// ww w. j a va 2 s. c o m LocationsMapper lLocationsMapper = lSqlSession.getMapper(LocationsMapper.class); LocationsExample lLocationsExample = new LocationsExample(); lLocationsExample.setOrderByClause("position"); List<Locations> lListLocations = lLocationsMapper.selectByExample(lLocationsExample); if (lListLocations != null && lListLocations.size() > 0) { lListLocationDTO = new ArrayList<LocationDTO>(); for (Locations lLocations : lListLocations) { LocationDTO lLocationDTO = new LocationDTO(); lLocationDTO.setIdLocation(lLocations.getIdLocation().intValue()); lLocationDTO.setName(lLocations.getName()); lLocationDTO.setPosition(lLocations.getPosition()); lLocationDTO.setNation(lLocations.getNation()); lLocationDTO.setState(lLocations.getState()); lLocationDTO.setCity(lLocations.getCity()); lLocationDTO.setTaskStatus(TaskStatus.getTaskStatusFromValue(lLocations.getTaskStatus())); lListLocationDTO.add(lLocationDTO); } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadAll()"); return lListLocationDTO; }
From source file:com.bibisco.manager.LocationManager.java
License:GNU General Public License
public static LocationDTO insert(LocationDTO pLocationDTO) { mLog.debug("Start insert(LocationDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w ww .j a v a 2s. com*/ Locations lLocations = new Locations(); lLocations.setName(pLocationDTO.getName()); lLocations.setPosition(pLocationDTO.getPosition()); lLocations.setNation(pLocationDTO.getNation()); lLocations.setState(pLocationDTO.getState()); lLocations.setCity(pLocationDTO.getCity()); LocationsMapper lLocationsMapper = lSqlSession.getMapper(LocationsMapper.class); lLocationsMapper.insertSelective(lLocations); pLocationDTO.setIdLocation(lLocations.getIdLocation().intValue()); pLocationDTO.setTaskStatus(TaskStatus.TODO); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End insert(LocationDTO)"); return pLocationDTO; }
From source file:com.bibisco.manager.LocationManager.java
License:GNU General Public License
public static boolean deleteByPosition(Integer pIntIdPosition) { boolean lBlnResult; mLog.debug("Start deleteByPosition(Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {//w w w . java2 s.co m LocationsExample lLocationsExample = new LocationsExample(); lLocationsExample.createCriteria().andPositionEqualTo(pIntIdPosition); LocationsMapper lLocationsMapper = lSqlSession.getMapper(LocationsMapper.class); // get location to delete by position Locations lLocations = lLocationsMapper.selectByExample(lLocationsExample).get(0); // check if location is referenced boolean lBlnIsReferenced = checkIfReferenced(lLocations.getIdLocation().intValue(), lSqlSession); // location is not referenced, go on if (!lBlnIsReferenced) { // delete location lLocationsMapper.deleteByPrimaryKey(lLocations.getIdLocation()); // delete all images ImageManager.deleteImagesByElement(lSqlSession, lLocations.getIdLocation().intValue(), ElementType.LOCATIONS); // shift down other locations lLocationsMapper.shiftDown(pIntIdPosition, Integer.MAX_VALUE); lBlnResult = true; } // location is referenced, stop else { lBlnResult = false; } lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } return lBlnResult; }
From source file:com.bibisco.manager.LocationManager.java
License:GNU General Public License
public static void move(Integer pIntSourcePosition, Integer pIntDestPosition) { mLog.debug("Start move(Integer, Integer)"); if (!pIntSourcePosition.equals(pIntDestPosition)) { SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance() .getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {//from w w w.j ava2s . c o m LocationsExample lLocationsExample = new LocationsExample(); lLocationsExample.createCriteria().andPositionEqualTo(pIntSourcePosition); LocationsMapper lLocationsMapper = lSqlSession.getMapper(LocationsMapper.class); // get location to update Locations lLocations = lLocationsMapper.selectByExample(lLocationsExample).get(0); // update location position with fake position to preserve unique index before shift lLocations.setPosition(-1); lLocationsMapper.updateByPrimaryKey(lLocations); // update other locations' position Integer lIntStartPosition; Integer lIntEndPosition; if (pIntSourcePosition > pIntDestPosition) { lIntStartPosition = pIntDestPosition; lIntEndPosition = pIntSourcePosition; lLocationsMapper.shiftUp(lIntStartPosition, lIntEndPosition); } else { lIntStartPosition = pIntSourcePosition; lIntEndPosition = pIntDestPosition; lLocationsMapper.shiftDown(lIntStartPosition, lIntEndPosition); } // update location position lLocations.setPosition(pIntDestPosition); lLocationsMapper.updateByPrimaryKey(lLocations); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } } mLog.debug("End move(Integer, Integer)"); }