001/*002 * Copyright 2002-2012 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.orm.hibernate3.support;018019import java.io.UnsupportedEncodingException;020import java.sql.PreparedStatement;021import java.sql.ResultSet;022import java.sql.SQLException;023import java.sql.Types;024import javax.transaction.TransactionManager;025026import org.springframework.jdbc.support.lob.LobCreator;027import org.springframework.jdbc.support.lob.LobHandler;028029/**030 * Hibernate UserType implementation for Strings that get mapped to BLOBs.031 * Retrieves the LobHandler to use from LocalSessionFactoryBean at config time.032 *033 * <p>This is intended for the (arguably unnatural, but still common) case034 * where character data is stored in a binary LOB. This requires encoding035 * and decoding the characters within this UserType; see the javadoc of the036 * {@code getCharacterEncoding()} method.037 *038 * <p>Can also be defined in generic Hibernate mappings, as DefaultLobCreator will039 * work with most JDBC-compliant database drivers. In this case, the field type040 * does not have to be BLOB: For databases like MySQL and MS SQL Server, any041 * large enough binary type will work.042 *043 * @author Juergen Hoeller044 * @since 1.2.7045 * @see #getCharacterEncoding()046 * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#setLobHandler047 * @deprecated as of Spring 4.3, in favor of Hibernate 4.x/5.x048 */049@Deprecated050public class BlobStringType extends AbstractLobType {051052 /**053 * Constructor used by Hibernate: fetches config-time LobHandler and054 * config-time JTA TransactionManager from LocalSessionFactoryBean.055 * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeLobHandler056 * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeTransactionManager057 */058 public BlobStringType() {059 super();060 }061062 /**063 * Constructor used for testing: takes an explicit LobHandler064 * and an explicit JTA TransactionManager (can be {@code null}).065 */066 protected BlobStringType(LobHandler lobHandler, TransactionManager jtaTransactionManager) {067 super(lobHandler, jtaTransactionManager);068 }069070 @Override071 public int[] sqlTypes() {072 return new int[] {Types.BLOB};073 }074075