Java 类org.hibernate.engine.spi.SharedSessionContractImplementor 实例源码

项目:MMORPG_Prototype    文件:JsonUserType.java   
@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);
    }

}
项目:MMORPG_Prototype    文件:JsonUserType.java   
@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);
    }

}
项目:SqlSauce    文件:ArrayListLongUserType.java   
@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;
}
项目:SqlSauce    文件:ArrayListLongUserType.java   
@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);
    }
}
项目:flow-platform    文件:CredentialDetailAdaptor.java   
@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());
}
项目:flow-platform    文件:ByteAdaptor.java   
@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);

}
项目:flow-platform    文件:BaseAdaptor.java   
/**
 * @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);
}
项目:hibernate-single-table-bulk-id-strategy    文件:SingleGlobalTemporaryTableBulkIdStrategy.java   
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);
        }
    }
}
项目:dhis2-core    文件:JsonListBinaryType.java   
@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 );
}
项目:owsi-core-parent    文件:StringClobType.java   
@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();
}
项目:webanno    文件:PersistentEnumUserType.java   
@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 + "]");
}
项目:pedal-dialect    文件:PostgresqlBitStringUserType.java   
@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;
    }
}
项目:hibernate-l2-memcached    文件:AbstractReadWriteMemcachedAccessStrategy.java   
/**
 * 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);
    }
}
项目:hibernate-l2-memcached    文件:AbstractReadWriteMemcachedAccessStrategy.java   
/**
 * 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);
    }
}
项目:hibernate-l2-memcached    文件:TransactionalMemcachedEntityRegionAccessStrategy.java   
/**
 * {@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;
}
项目:hibernate-l2-memcached    文件:ReadWriteMemcachedEntityRegionAccessStrategy.java   
/**
 * {@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);
    }
}
项目:hibernate-l2-memcached    文件:ReadWriteMemcachedEntityRegionAccessStrategy.java   
/**
 * {@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);
    }
}
项目:postguice    文件:TextArrayUserType.java   
@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;
}
项目:postguice    文件:TextArrayUserType.java   
@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);
    }
}
项目:postguice    文件:JSONUserType.java   
@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);
        }
    }
}
项目:postguice    文件:JSONUserType.java   
@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);
        }
    }
}
项目:postguice    文件:SimpleStringUserType.java   
@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);
    }
}
项目:postguice    文件:SimpleStringUserType.java   
@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());
    }
}
项目:flow-platform    文件:SettingContentAdaptor.java   
@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());
}
项目:flow-platform    文件:ByteAdaptor.java   
@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);
}
项目:flow-platform    文件:BaseAdaptor.java   
/**
 * @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);
}
项目:cr-private-server    文件:SCID.java   
@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));
}
项目:cr-private-server    文件:SCID.java   
@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());
}
项目:cr-private-server    文件:AssignedIdentityGenerator.java   
@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);
}
项目:hibernate-types    文件:PostgreSQLEnumType.java   
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);
    }
}
项目:hibernate-types    文件:NullableCharacterType.java   
@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));
    }
}
项目:infotranspub-backend    文件:ServiceDateUserType.java   
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);
    }
}
项目:infotranspub-backend    文件:ServiceDateUserType.java   
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());
    }
}
项目:hazelcast-hibernate5    文件:AbstractGeneralRegion.java   
@Override
public Object get(final SharedSessionContractImplementor session, final Object key) throws CacheException {
    try {
        return getCache().get(key, nextTimestamp());
    } catch (OperationTimeoutException e) {
        return null;
    }
}
项目:hazelcast-hibernate5    文件:AbstractGeneralRegion.java   
@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);
    }
}
项目:gorm-hibernate5    文件:IdentityEnumType.java   
@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;
}
项目:gorm-hibernate5    文件:IdentityEnumType.java   
@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);
    }
}
项目:dhis2-core    文件:EnumUserType.java   
@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;
}
项目:dhis2-core    文件:EnumUserType.java   
@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() );
    }
}
项目:dhis2-core    文件:TranslationPropertyUserType.java   
@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;
}