@SuppressWarnings("unchecked") @Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { final String cellContent = rs.getString(names[0]); if (cellContent == null) throw new RuntimeException("cell Content is null"); final ObjectMapper mapper = SpringContext.getBean(ObjectMapper.class); try { return mapper.readValue(cellContent, returnedClass()); } catch (final IOException ex) { throw new RuntimeException("Failed to convert String to Invoice: " + ex.getMessage(), ex); } }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.VARCHAR); return; } try { final ObjectMapper mapper = new ObjectMapper(); final StringWriter w = new StringWriter(); mapper.writeValue(w, value); w.flush(); st.setObject(index, w.toString(), Types.VARCHAR); } catch (final Exception ex) { throw new RuntimeException("Failed to convert Invoice to String: " + ex.getMessage(), ex); } }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { Array array = rs.getArray(names[0]); if (array == null) { return null; } Long[] javaArray = (Long[]) array.getArray(); ArrayList<Long> result = new ArrayList<>(); Collections.addAll(result, javaArray); //do not use Arrays.asList(), that method returns a fake ArrayList return result; }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { Connection connection = st.getConnection(); if (value == null) { st.setNull(index, sqlTypes()[0]); } else { @SuppressWarnings("unchecked") ArrayList<Long> castObject = (ArrayList) value; Long[] longs = castObject.toArray(new Long[castObject.size()]); Array array = connection.createArrayOf("bigint", longs); st.setArray(index, array); } }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String detailRaw = rs.getString(names[0]); if (detailRaw == null) { return null; } // according to credential.hbm.xml property sequence String typeRaw = rs.getString(2); CredentialType type = CredentialType.valueOf(typeRaw); return GSON.fromJson(detailRaw, type.getClazz()); }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { // set to null if (value == null) { st.setBytes(index, null); return; } // value already in string type if (value instanceof byte[]) { st.setBytes(index, (byte[]) value); return; } byte[] bytes = stringToByte((String) value); st.setBytes(index, bytes); }
/** * @param st * @param value * @param index * @param session * @throws HibernateException * @throws SQLException */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { // set to null if (value == null) { st.setString(index, null); return; } // value already in string type if (value instanceof String) { st.setString(index, (String) value); return; } String str = objectToJson(value); st.setString(index, str); }
private void cleanUpRows(SharedSessionContractImplementor session, Queryable persister) { final String sql = "delete from " + fullyQualifiedTableName + " where " + discriminatorColumn + "=?"; PreparedStatement ps = null; try { ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql, false); ps.setString(1, generateDiscriminatorValue(persister)); StringType.INSTANCE.set(ps, generateDiscriminatorValue(persister), 1, session); session.getJdbcCoordinator().getResultSetReturn().executeUpdate(ps); } catch (SQLException e) { throw session.getJdbcServices().getSqlExceptionHelper().convert(e, "Unable to clean up id table [" + fullyQualifiedTableName + "]", sql); } finally { if (ps != null) { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(ps); } } }
@Override public void nullSafeSet( PreparedStatement ps, Object value, int idx, SharedSessionContractImplementor session ) throws HibernateException, SQLException { if ( value == null ) { ps.setObject( idx, null ); return; } PGobject pg = new PGobject(); pg.setType( "jsonb" ); pg.setValue( convertObjectToJson( value ) ); ps.setObject( idx, pg ); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { Reader reader = rs.getCharacterStream( names[0] ); if ( reader == null ) return null; StringBuilder result = new StringBuilder( 4096 ); try { char[] charbuf = new char[4096]; for ( int i = reader.read( charbuf ); i > 0 ; i = reader.read( charbuf ) ) { result.append( charbuf, 0, i ); } } catch (IOException e) { throw new SQLException( e.getMessage() ); } return result.toString(); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String name = rs.getString(names[0]); if (rs.wasNull()) { return null; } for (PersistentEnum value : returnedClass().getEnumConstants()) { if (name.equals(value.getId())) { return value; } } throw new IllegalStateException( "Unknown " + returnedClass().getSimpleName() + " value [" + name + "]"); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { byte[] bytes = rs.getBytes(names[0]); if (rs.wasNull()) { return null; } else { BitSet bits = new BitSet(bytes.length); int index = 0; for (byte b : bytes) { // 1 and 0 are encoded as ascii values of '1' and '0' bits.set(index++, b - '0' != 0); } return bits; } }
/** * Returns <code>null</code> if the item is not readable. Locked items are not readable, nor are items created * afterQuery the start of this transaction. */ public final Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { readLockIfNeeded(key); try { final Lockable item = (Lockable) region().get(key); final boolean readable = item != null && item.isReadable(txTimestamp); if (readable) { return item.getValue(); } else { return null; } } finally { readUnlockIfNeeded(key); } }
/** * Returns <code>false</code> and fails to put the value if there is an existing un-writeable item mapped to this * key. */ @Override public final boolean putFromLoad( SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { region.getCache().lock(key); try { final Lockable item = (Lockable) region().get(key); final boolean writeable = item == null || item.isWriteable(txTimestamp, version, versionComparator); if (writeable) { region().put(key, new Item(value, version, region.nextTimestamp())); return true; } else { return false; } } finally { region.getCache().unlock(key); } }
/** * {@inheritDoc} */ public boolean putFromLoad( SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if (minimalPutOverride && cache.get(key) != null) { return false; } //OptimisticCache? versioning? cache.put(key, value); return true; }
/** * {@inheritDoc} * <p> * Inserts will only succeed if there is no existing value mapped to this key. */ @Override public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { region.getCache().lock(key); try { final Lockable item = (Lockable) region().get(key); if (item == null) { region().put(key, new Item(value, version, region.nextTimestamp())); return true; } else { return false; } } finally { region.getCache().unlock(key); } }
/** * {@inheritDoc} * <p> * Updates will only succeed if this entry was locked by this transaction and exclusively this transaction for the * duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during * the course of this transaction. */ @Override public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { //what should we do with previousVersion here? region.getCache().lock(key); try { final Lockable item = (Lockable) region().get(key); if (item != null && item.isUnlockable(lock)) { final Lock lockItem = (Lock) item; if (lockItem.wasLockedConcurrently()) { decrementLock(key, lockItem); return false; } else { region().put(key, new Item(value, currentVersion, region.nextTimestamp())); return true; } } else { handleLockExpiry(key, item); return false; } } finally { region.getCache().unlock(key); } }
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final SharedSessionContractImplementor session, final Object owner) throws HibernateException, SQLException { if (rs.wasNull()) { return null; } final String[] array = (String[])rs.getArray(names[0]).getArray(); return array; }
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, SQL_TYPES[0]); } else { final Array array = session.connection().createArrayOf("text", (String[])value); st.setArray(index, array); } }
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final SharedSessionContractImplementor session, final Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (value == null) { return null; } else { try { return MAPPER.readValue(value, this.javaType); } catch (IOException e) { throw new HibernateException("Unable to read object from result set", e); } } }
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.OTHER); } else { try { st.setObject(index, MAPPER.writeValueAsString(value), Types.OTHER); } catch (JsonProcessingException e) { throw new HibernateException("Unable to set object to result set", e); } } }
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final SharedSessionContractImplementor session, final Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (value == null) { return null; } else { return construct(value); } }
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.VARCHAR); } else { st.setString(index, value.toString()); } }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String str = rs.getString(names[0]); if (str == null) { return null; } SettingContent settingContent = GSON.fromJson(str, SettingContent.class); return GSON.fromJson(str, settingContent.getType().getClazz()); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { byte[] bytes = rs.getBytes(names[0]); if (bytes == null) { return null; } return byteToString(bytes); }
/** * @param rs * @param names * @param session * @param owner * @return * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String str = rs.getString(names[0]); if (str == null) { return null; } return jsonToObject(str); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { final String value = rs.getString(names[0]); if (value == null) { return null; } return new SCID(Long.valueOf(value)); }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.BIGINT); return; } st.setLong(index, ((SCID)value).getValue()); }
@Override public Serializable generate(SharedSessionContractImplementor session, Object obj) { if (obj instanceof Identifiable) { Identifiable identifiable = (Identifiable)obj; Serializable id = identifiable.getId(); if (id != null) { return id; } } return super.generate(session, obj); }
public void nullSafeSet( PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.OTHER); } else { st.setObject(index, value.toString(), Types.OTHER); } }
@Override public void set(PreparedStatement st, Character value, int index, SharedSessionContractImplementor session) throws SQLException { if (value == null) { st.setNull(index, Types.CHAR); } else { st.setString(index, String.valueOf(value)); } }
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (rs.wasNull()) return null; try { return ServiceDate.parseString(value); } catch (ParseException ex) { throw new SQLException("error parsing service date value: " + value, ex); } }
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { if (value == null) { st.setNull(index, SQL_TYPES[0]); } else { ServiceDate serviceDate = (ServiceDate) value; st.setString(index, serviceDate.getAsString()); } }
@Override public Object get(final SharedSessionContractImplementor session, final Object key) throws CacheException { try { return getCache().get(key, nextTimestamp()); } catch (OperationTimeoutException e) { return null; } }
@Override public void put(final SharedSessionContractImplementor session, final Object key, final Object value) throws CacheException { try { getCache().put(key, value, nextTimestamp(), null); } catch (OperationTimeoutException e) { Logger.getLogger(AbstractGeneralRegion.class).finest(e); } }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { Object id = type.nullSafeGet(rs, names[0], session); if ((!rs.wasNull()) && id != null) { return bidiMap.getEnumValue(id); } return null; }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { st.setNull(index, sqlTypes[0]); } else { type.nullSafeSet(st, bidiMap.getKey(value), index, session); } }
@Override public Object nullSafeGet( ResultSet resultSet, String[] names, SharedSessionContractImplementor impl, Object owner ) throws HibernateException, SQLException { String name = resultSet.getString( names[0] ); E result = null; if ( !resultSet.wasNull() ) { result = Enum.valueOf( clazz, name ); } return result; }
@Override public void nullSafeSet( PreparedStatement preparedStatement, Object value, int index, SharedSessionContractImplementor impl ) throws HibernateException, SQLException { if ( null == value ) { preparedStatement.setNull( index, Types.VARCHAR ); } else { preparedStatement.setString( index, ((Enum<?>) value).name() ); } }
@Override public Object nullSafeGet( ResultSet resultSet, String[] names, SharedSessionContractImplementor impl, Object owner ) throws HibernateException, SQLException { String name = resultSet.getString( names[0] ); TranslationProperty result = null; if ( !resultSet.wasNull() ) { result = TranslationProperty.fromValue( name ); } return result; }