Example usage for org.hibernate Hibernate getLobCreator

List of usage examples for org.hibernate Hibernate getLobCreator

Introduction

In this page you can find the example usage for org.hibernate Hibernate getLobCreator.

Prototype

public static LobCreator getLobCreator(SessionImplementor session) 

Source Link

Document

Obtain a lob creator for the given session.

Usage

From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java

License:Open Source License

private Object applyDatabaseType(FieldCondition field, Object value) {
    if (field.fieldMetadata != null
            && TypeMapping.SQL_TYPE_CLOB.equals(field.fieldMetadata.getType().getData(TypeMapping.SQL_TYPE))) {
        return Hibernate.getLobCreator(session).createClob(String.valueOf(value));
    }/*w  w w.  j  ava2  s .  c o  m*/
    return value;
}

From source file:com.amalto.core.storage.hibernate.TypeMapping.java

License:Open Source License

private static Object _serializeValue(Object value, FieldMetadata sourceField, FieldMetadata targetField,
        Session session) {//  ww w  .  ja  va2s  .  co m
    if (targetField == null) {
        return value;
    }
    if (!targetField.isMany()) {
        Boolean targetZipped = targetField.<Boolean>getData(MetadataRepository.DATA_ZIPPED);
        Boolean sourceZipped = sourceField.<Boolean>getData(MetadataRepository.DATA_ZIPPED);
        if (sourceZipped == null && Boolean.TRUE.equals(targetZipped)) {
            try {
                ByteArrayOutputStream characters = new ByteArrayOutputStream();
                OutputStream bos = new Base64OutputStream(characters);
                ZipOutputStream zos = new ZipOutputStream(bos);
                ZipEntry zipEntry = new ZipEntry("content"); //$NON-NLS-1$
                zos.putNextEntry(zipEntry);
                zos.write(String.valueOf(value).getBytes("UTF-8")); //$NON-NLS-1$
                zos.closeEntry();
                zos.flush();
                zos.close();
                return new String(characters.toByteArray());
            } catch (IOException e) {
                throw new RuntimeException("Unexpected compression exception", e); //$NON-NLS-1$
            }
        }
        String targetSQLType = targetField.getType().getData(TypeMapping.SQL_TYPE);
        if (targetSQLType != null && SQL_TYPE_CLOB.equals(targetSQLType)) {
            if (value != null) {
                return Hibernate.getLobCreator(session).createClob(String.valueOf(value));
            } else {
                return null;
            }
        }
    }
    return value;
}

From source file:com.amalto.core.storage.hibernate.UpdateReportTypeMapping.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*w ww .j  a  v a  2s  .c  o  m*/
public void setValues(Session session, DataRecord from, Wrapper to) {
    to.set("x_user_name", from.get("UserName")); //$NON-NLS-1$ //$NON-NLS-2$
    Object source = from.get("Source"); //$NON-NLS-1$
    if (source == null) {
        // TMDM-4856: In case source is null, put "none" as the source.
        source = NO_SOURCE;
    }
    to.set("x_source", source); //$NON-NLS-1$ 
    to.set("x_time_in_millis", Long.parseLong(String.valueOf(from.get("TimeInMillis")))); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_operation_type", from.get("OperationType")); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_revision_id", from.get("RevisionID")); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_data_cluster", from.get("DataCluster")); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_data_model", from.get("DataModel")); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_concept", from.get("Concept")); //$NON-NLS-1$ //$NON-NLS-2$
    to.set("x_key", from.get("Key")); //$NON-NLS-1$ //$NON-NLS-2$
    try {
        List<DataRecord> dataRecord = (List<DataRecord>) from.get("Item"); //$NON-NLS-1$
        if (dataRecord != null) { // this might be null if there is no 'Item' element in update report.
            DataRecordXmlWriter writer = new DataRecordXmlWriter("Item"); //$NON-NLS-1$
            StringWriter stringWriter = new StringWriter();
            for (DataRecord record : dataRecord) {
                writer.write(record, new BufferedWriter(stringWriter));
            }
            to.set("x_items_xml", //$NON-NLS-1$
                    isUsingClob(to) ? Hibernate.getLobCreator(session).createClob(stringWriter.toString())
                            : stringWriter.toString());
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not set Items XML value", e); //$NON-NLS-1$
    }
}

From source file:com.formkiq.core.dao.AbstractDaoImpl.java

License:Apache License

@SuppressWarnings("resource")
@Override/* w  w  w .j a v  a2 s.  co m*/
public Blob convertToBlob(final byte[] data) {
    Session session = getEntityManager().unwrap(Session.class);
    Blob blob = Hibernate.getLobCreator(session).createBlob(data);
    return blob;
}

From source file:com.jredrain.dao.UploadDao.java

License:Apache License

public User uploadimg(File file, Long userId) throws IOException {
    Session session = getSession();// ww w . j a va2s.  c om
    User loginUser = get(User.class, userId);
    loginUser.setHeaderpic(Hibernate.getLobCreator(session).createBlob(IOUtils.readFileToArray(file)));
    //????
    loginUser.setPicExtName(file.getName().substring(file.getName().lastIndexOf(".")));
    session.save(loginUser);
    return loginUser;
}

From source file:com.multiimages.insertmultiimg.InsertMultiImg.java

License:Open Source License

@Transactional(value = "EmployeesDBTransactionManager")
public void uploadFile(Integer relativePath, MultipartFile[] files, HttpServletRequest httpServletRequest) {
    /* Note: relativePath here maps to the id of the related Object to be saved in the transaction */
    File outputFile = null;// ww w  . j a v  a 2 s.  c  o m
    Session session = sessionFactory.getObject().openSession();

    for (MultipartFile file : files) {
        try {
            Image image = new Image();
            image.setEmployee(employeeService.findById(relativePath));

            byte[] byteArray = IOUtils.toByteArray(file.getInputStream());
            Blob blob = Hibernate.getLobCreator(session).createBlob(new ByteArrayInputStream(byteArray),
                    new Long(byteArray.length));

            image.setImgdate(blob);

            imageService.create(image);
        } catch (Exception e) {
        }
    }
}

From source file:com.muslim.family.dao.impl.AnswerDAOImpl.java

public void saveOrUpdateAudioDao(MultipartFile audioFile, Answer_tbl answer) {

    try {//  www. ja  v  a2  s .com

        Session session = sessionFactory.getCurrentSession();
        Blob audioMessage = Hibernate.getLobCreator(session).createBlob(audioFile.getBytes());
        answer.setAudioMessage(audioMessage);
        session.saveOrUpdate(answer);

    } catch (IOException ex) {
        Logger.getLogger(AnswerDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mycompany.controllers.ClubController.java

@PostMapping("/create")
@ResponseBody/*from   ww  w.  ja va2  s .c om*/
public ModelAndView createClub(@Valid ClubForm clubForm, BindingResult result, Model model) throws IOException {
    if (result.hasErrors()) {
        return new ModelAndView("redirect:/club/create");
    }

    byte[] bytes;
    bytes = clubForm.getLogo().getBytes();
    bytes = LogoConvertion(bytes);

    Configuration cfg = new Configuration();
    cfg.configure("hibernate.cfg.xml");
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = factory.openSession();
    Transaction t = session.beginTransaction();

    Klub club = new Klub();
    club.setNazwa(clubForm.getName());

    LobCreator lcreator = Hibernate.getLobCreator(session);
    Blob blob = (Blob) lcreator.createBlob(bytes);
    club.setLogo(blob);

    session.persist(club);
    t.commit();
    session.close();
    factory.close();

    model.addAttribute("club", club);
    return new ModelAndView("redirect:/club/" + club.getIdKlub());

}

From source file:com.mycompany.controllers.ClubController.java

@PostMapping("/{id}/edit")
@ResponseBody/*  w ww.  ja v  a2  s.co m*/
public ModelAndView editClub(@Valid ClubForm clubForm, BindingResult result, Model model,
        @PathVariable("id") String id) throws IOException {
    if (result.hasErrors()) {
        return new ModelAndView("redirect:/club/" + id + "/edit");
    }

    byte[] bytes;
    bytes = clubForm.getLogo().getBytes();
    bytes = LogoConvertion(bytes);

    Configuration cfg = new Configuration();
    cfg.configure("hibernate.cfg.xml");
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = factory.openSession();
    Transaction t = session.beginTransaction();

    Klub club = session.find(Klub.class, Integer.parseInt(id));
    club.setNazwa(clubForm.getName());

    LobCreator lcreator = Hibernate.getLobCreator(session);
    Blob blob = (Blob) lcreator.createBlob(bytes);
    club.setLogo(blob);

    session.update(club);
    t.commit();
    session.close();
    factory.close();

    model.addAttribute("club", club);
    return new ModelAndView("redirect:/club/" + club.getIdKlub());

}

From source file:com.ronin.dao.api.FileUploadDao.java

private Belge saveFile(SessionInfo sessionInfo, UploadedFile uploadedFile, Belge belge)
        throws FileNotFoundException {
    InputStream inputStream = new FileInputStream("C:\\rmsFileUploadDocument\\" + uploadedFile.getFileName());
    belge.setContent(Hibernate.getLobCreator(getSessionFactory().getCurrentSession()).createBlob(inputStream,
            uploadedFile.getSize()));//  w w w  .  j ava  2 s.  co  m
    belge.setDataName(uploadedFile.getFileName());
    belge.setKullanici(sessionInfo.getKullanici());
    belge.setSize(uploadedFile.getSize());
    belge.setIslemTarihi(new Date());
    belge.setSirket(sessionInfo.getSirket());
    getSessionFactory().getCurrentSession().save(belge);
    return belge;
}