Example usage for org.springframework.jdbc.support.lob DefaultLobHandler DefaultLobHandler

List of usage examples for org.springframework.jdbc.support.lob DefaultLobHandler DefaultLobHandler

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.lob DefaultLobHandler DefaultLobHandler.

Prototype

DefaultLobHandler

Source Link

Usage

From source file:com.nortal.petit.orm.statement.LoadStatement.java

public InputStream getBlobAsBinaryStream(final String columnName) {
    return (InputStream) getJdbcTemplate().queryForObject(getSql(), getParams(null),
            new RowMapper<InputStream>() {
                @Override/* w  w  w .ja v a 2s. c  om*/
                public InputStream mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return new DefaultLobHandler().getBlobAsBinaryStream(rs, columnName);
                }
            });
}

From source file:alfio.manager.UploadedResourceManager.java

public int saveResource(UploadBase64FileModification file) {
    if (hasResource(file.getName())) {
        uploadedResourceRepository.delete(file.getName());
    }//w w w .  j  a va2  s.c o  m
    LobHandler lobHandler = new DefaultLobHandler();
    return jdbc.getJdbcOperations().execute(uploadedResourceRepository.uploadTemplate(file.getName()),
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
                @Override
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    setFileValues(ps, lobCreator, file, 1);
                }
            });

}

From source file:alfio.manager.UploadedResourceManager.java

public int saveResource(int organizationId, UploadBase64FileModification file) {
    if (hasResource(organizationId, file.getName())) {
        uploadedResourceRepository.delete(organizationId, file.getName());
    }//from w ww . j  a  va  2s  .c  o  m
    LobHandler lobHandler = new DefaultLobHandler();
    return jdbc.getJdbcOperations().execute(
            uploadedResourceRepository.uploadTemplate(organizationId, file.getName()),
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
                @Override
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setInt(2, organizationId);
                    setFileValues(ps, lobCreator, file, 2);
                }
            });
}

From source file:com.xchanging.support.batch.admin.service.SimpleJobServiceFactoryBean.java

public void afterPropertiesSet() throws Exception {

    Assert.notNull(dataSource, "DataSource must not be null.");
    Assert.notNull(jobRepository, "JobRepository must not be null.");
    Assert.notNull(jobLocator, "JobLocator must not be null.");
    Assert.notNull(jobLauncher, "JobLauncher must not be null.");

    jdbcTemplate = new SimpleJdbcTemplate(dataSource);

    if (incrementerFactory == null) {
        incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
    }/*from   www .  j a  v  a  2s. co  m*/

    if (databaseType == null) {
        databaseType = DatabaseType.fromMetaData(dataSource).name();
        logger.info("No database type set, using meta data indicating: " + databaseType);
    }

    if (lobHandler == null) {
        lobHandler = new DefaultLobHandler();
    }

    Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
            + "' is an unsupported database type.  The supported database types are "
            + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));

}

From source file:admin.service.SimpleJobServiceFactoryBean.java

public void afterPropertiesSet() throws Exception {

    Assert.notNull(dataSource, "DataSource must not be null.");
    Assert.notNull(jobRepository, "JobRepository must not be null.");
    Assert.notNull(jobLocator, "JobLocator must not be null.");
    Assert.notNull(jobLauncher, "JobLauncher must not be null.");

    jdbcTemplate = new JdbcTemplate(dataSource);

    if (incrementerFactory == null) {
        incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
    }//from  www . j av a 2 s .com

    if (databaseType == null) {
        databaseType = DatabaseType.fromMetaData(dataSource).name();
        logger.info("No database type set, using meta data indicating: " + databaseType);
    }

    if (lobHandler == null) {
        lobHandler = new DefaultLobHandler();
    }

    if (serializer == null) {
        XStreamExecutionContextStringSerializer defaultSerializer = new XStreamExecutionContextStringSerializer();
        defaultSerializer.afterPropertiesSet();

        serializer = defaultSerializer;
    }

    Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
            + "' is an unsupported database type.  The supported database types are "
            + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));

}

From source file:alfio.manager.UploadedResourceManager.java

public int saveResource(int organizationId, int eventId, UploadBase64FileModification file) {
    if (hasResource(organizationId, eventId, file.getName())) {
        uploadedResourceRepository.delete(organizationId, eventId, file.getName());
    }//from   www  .j ava 2  s .  c  o m
    LobHandler lobHandler = new DefaultLobHandler();
    return jdbc.getJdbcOperations().execute(
            uploadedResourceRepository.uploadTemplate(organizationId, eventId, file.getName()),
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
                @Override
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setInt(2, organizationId);
                    ps.setInt(3, eventId);
                    setFileValues(ps, lobCreator, file, 3);
                }
            });

}

From source file:com.test.HibernateDerbyLockingTest.java

public void testSpring() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("hibernate.hbm2ddl.auto", "create");
    properties.setProperty("hibernate.dialect", "org.bpmscript.hibernate.DerbyDialect");
    properties.setProperty("hibernate.show_sql", "true");

    properties.setProperty("hibernate.connection.driver_class", EmbeddedDriver.class.getName());
    properties.setProperty("hibernate.connection.url", "jdbc:derby:lockingtest;create=true");
    properties.setProperty("hibernate.connection.username", "sa");
    properties.setProperty("hibernate.connection.password", "sa");
    properties.setProperty("hibernate.connection.pool_size", "10");

    final AnnotationSessionFactoryBean sessionFactoryBean = new AnnotationSessionFactoryBean();
    sessionFactoryBean.setLobHandler(new DefaultLobHandler());
    sessionFactoryBean.setHibernateProperties(properties);
    sessionFactoryBean.setAnnotatedClasses(new Class[] { Person.class });
    sessionFactoryBean.afterPropertiesSet();

    SessionFactory sessionFactory = (SessionFactory) sessionFactoryBean.getObject();
    try {/*from w w w .  j ava 2s.co  m*/
        runTest(sessionFactory);
    } finally {
        sessionFactory.close();
    }
}

From source file:com.opengamma.util.db.DbDialect.java

/**
 * Gets the LOB handler used for BLOBs and CLOBs.
 * Subclasses will return different handlers for different dialects.
 * //from  w w  w.  j a v  a 2  s  .co m
 * @return the LOB handler, not null
 */
public LobHandler getLobHandler() {
    return new DefaultLobHandler();
}

From source file:com.test.HibernateDerbyLockingTest.java

public void testSpringWithDataSource() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(EmbeddedDriver.class.getName());
    dataSource.setUrl("jdbc:derby:lockingtest;create=true");
    dataSource.setUsername("sa");
    dataSource.setPassword("sa");

    Properties properties = new Properties();
    properties.setProperty("hibernate.hbm2ddl.auto", "create");
    properties.setProperty("hibernate.dialect", "org.bpmscript.hibernate.DerbyDialect");
    properties.setProperty("hibernate.show_sql", "true");

    // properties.setProperty("hibernate.connection.driver_class",
    // EmbeddedDriver.class.getName());
    // properties.setProperty("hibernate.connection.url",
    // "jdbc:derby:lockingtest;create=true");
    // properties.setProperty("hibernate.connection.username", "sa");
    // properties.setProperty("hibernate.connection.password", "sa");
    // properties.setProperty("hibernate.connection.pool_size", "10");

    final AnnotationSessionFactoryBean sessionFactoryBean = new AnnotationSessionFactoryBean();
    sessionFactoryBean.setLobHandler(new DefaultLobHandler());
    sessionFactoryBean.setHibernateProperties(properties);
    sessionFactoryBean.setAnnotatedClasses(new Class[] { Person.class });
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.afterPropertiesSet();

    SessionFactory sessionFactory = (SessionFactory) sessionFactoryBean.getObject();
    try {//from  w  w  w.j a  v a2  s.c  o  m
        runTest(sessionFactory);
    } finally {
        sessionFactory.close();
    }
}

From source file:io.lavagna.service.CardDataRepository.java

@Transactional(readOnly = false)
public int addUploadContent(final String digest, final long fileSize, final InputStream content,
        final String contentType) {
    LobHandler lobHandler = new DefaultLobHandler();
    return jdbc.getJdbcOperations().execute(queries.addUploadContent(),
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

                @Override/*  ww w  . j  a va  2s .  com*/
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setString(1, digest);
                    ps.setLong(2, fileSize);
                    lobCreator.setBlobAsBinaryStream(ps, 3, content, (int) fileSize);
                    ps.setString(4, contentType);
                }
            });
}