List of usage examples for org.hibernate.type TextType TextType
public TextType()
From source file:lt.emasina.resthub.server.factory.DataFactory.java
License:Open Source License
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://from ww w .ja v a2 s. c om 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 (ExecutionException | InterruptedException ex) { throw ex; } catch (TimeoutException ex) { throw new ServerErrorException(Status.SERVER_ERROR_GATEWAY_TIMEOUT, ex); } }
From source file:org.openmrs.module.metadatasharing.api.db.hibernate.XMLSerializableType.java
License:Open Source License
/** * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], * java.lang.Object)/*from w w w . j a v a 2 s. c o m*/ */ @Override public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { String xmlString = (String) new TextType().nullSafeGet(rs, names[0]); return xstream.fromXML(xmlString); }
From source file:org.openmrs.module.metadatasharing.api.db.hibernate.XMLSerializableType.java
License:Open Source License
/** * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, * java.lang.Object, int)//from w w w. ja v a 2 s.co m */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { String xmlString = xstream.toXML(value); new TextType().nullSafeSet(st, xmlString, index); }