Java Examples for org.hibernate.type.WrapperBinaryType

The following java examples will help you to understand the usage of org.hibernate.type.WrapperBinaryType. These source code samples are taken from different open source projects.

Example 1
Project: resthub-master  File: DataFactory.java View source code
public CcLob getLob(final Session session, final LobHandler handler) throws Exception {
    final Query q = handler.getQuery();
    final SQLQuery query = getPagedSQLQuery(session, handler);
    final MdColumn c = handler.getMdColumn();
    switch(c.getType()) {
        case BLOB:
            query.addScalar(c.getName(), new WrapperBinaryType());
            break;
        case CLOB:
            query.addScalar(c.getName(), new TextType());
            break;
        default:
            throw new ClientErrorException(Status.CLIENT_ERROR_BAD_REQUEST, "Column %d (%s) expected to be LOB found %s", handler.getColumn(), c.getName(), c.getType().name());
    }
    if (log.isDebugEnabled()) {
        log.debug(query.getQueryString());
    }
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<CcLob> fetchData = executor.submit(new Callable<CcLob>() {

        @Override
        @SuppressWarnings("unchecked")
        public CcLob call() throws Exception {
            CcLob cc = new CcLob();
            Object o = query.uniqueResult();
            if (o != null) {
                switch(c.getType()) {
                    case CLOB:
                        cc.setValue((String) o);
                        break;
                    case BLOB:
                        cc.setValue((Byte[]) o);
                        break;
                }
            }
            return cc;
        }

        ;
    });
    try {
        return fetchData.get(q.getTimeOut(), TimeUnit.SECONDS);
    } catch (ExecutionExceptionInterruptedException |  ex) {
        throw ex;
    } catch (TimeoutException ex) {
        throw new ServerErrorException(Status.SERVER_ERROR_GATEWAY_TIMEOUT, ex);
    }
}