KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > hibernate3 > support > ClobStringType


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.hibernate3.support;
18
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21 import java.sql.SQLException JavaDoc;
22 import java.sql.Types JavaDoc;
23
24 import javax.transaction.TransactionManager JavaDoc;
25
26 import org.springframework.jdbc.support.lob.LobCreator;
27 import org.springframework.jdbc.support.lob.LobHandler;
28
29 /**
30  * Hibernate UserType implementation for Strings that get mapped to CLOBs.
31  * Retrieves the LobHandler to use from LocalSessionFactoryBean at config time.
32  *
33  * <p>Particularly useful for storing Strings with more than 4000 characters in an
34  * Oracle database (only possible via CLOBs), in combination with OracleLobHandler.
35  *
36  * <p>Can also be defined in generic Hibernate mappings, as DefaultLobCreator will
37  * work with most JDBC-compliant database drivers. In this case, the field type
38  * does not have to be CLOB: For databases like MySQL and MS SQL Server, any
39  * large enough character type will work.
40  *
41  * @author Juergen Hoeller
42  * @since 1.2
43  * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#setLobHandler
44  */

45 public class ClobStringType extends AbstractLobType {
46
47     /**
48      * Constructor used by Hibernate: fetches config-time LobHandler and
49      * config-time JTA TransactionManager from LocalSessionFactoryBean.
50      * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeLobHandler
51      * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeTransactionManager
52      */

53     public ClobStringType() {
54         super();
55     }
56
57     /**
58      * Constructor used for testing: takes an explicit LobHandler
59      * and an explicit JTA TransactionManager (can be <code>null</code>).
60      */

61     protected ClobStringType(LobHandler lobHandler, TransactionManager JavaDoc jtaTransactionManager) {
62         super(lobHandler, jtaTransactionManager);
63     }
64
65     public int[] sqlTypes() {
66         return new int[] {Types.CLOB};
67     }
68
69     public Class JavaDoc returnedClass() {
70         return String JavaDoc.class;
71     }
72
73     protected Object JavaDoc nullSafeGetInternal(
74             ResultSet JavaDoc rs, String JavaDoc[] names, Object JavaDoc owner, LobHandler lobHandler)
75             throws SQLException JavaDoc {
76
77         return lobHandler.getClobAsString(rs, names[0]);
78     }
79
80     protected void nullSafeSetInternal(
81             PreparedStatement JavaDoc ps, int index, Object JavaDoc value, LobCreator lobCreator)
82             throws SQLException JavaDoc {
83
84         lobCreator.setClobAsString(ps, index, (String JavaDoc) value);
85     }
86
87 }
88
Popular Tags