public class StringArrayContainer { private Integer id ; private String [ ] tags ; // . }
public class StringArrayContainer { private Integer id ; private String [ ] tags ; // . }
public class StringArrayContainer { private Integer id ; private String [ ] tags ; // . }
public class StringArrayContainer { private Integer id ; private String [ ] tags ; // . }
public class StringArrayContainer { private Integer id ; private String [ ] tags ; // . }
- public class StringArrayCustomType implements UserType {
- // TODO: write the implementation.
- }
- private static final int [ ] SQL_TYPES = new int [ ] { Types . CLOB } ;
- @ Override
- public int [ ] sqlTypes ( ) {
- return SQL_TYPES ;
- }
- @ Override
- public Class returnedClass ( ) {
- return String [ ] . class ;
- }
- @ Override
- public boolean equals ( Object x, Object y ) throws HibernateException {
- return x == y ;
- }
- @ Override
- public int hashCode ( Object x ) throws HibernateException {
- return x. hashCode ( ) ;
- }
- @ Override
- public Object nullSafeGet ( ResultSet rs, String [ ] names, Object owner ) throws HibernateException, SQLException {
- String value = ( String ) Hibernate. TEXT . nullSafeGet ( rs, names [ 0 ] ) ;
- if ( value == null ) {
- return null ;
- } else {
- String [ ] array = StringUtils. split ( value, '' ) ;
- for ( int i = 0 ; i < array. length ; i ++ ) {
- array [ i ] = WhitespaceEscapeUtil. unescape ( array [ i ] ) ;
- }
- return array ;
- }
- }
- @ Override
- public void nullSafeSet ( PreparedStatement st, Object value, int index ) throws HibernateException, SQLException {
- if ( value == null ) {
- Hibernate. TEXT . nullSafeSet ( st, null , index ) ;
- } else {
- String [ ] array = ( String [ ] ) value ;
- String [ ] copy = new String [ array. length ] ;
- for ( int i = 0 ; i < array. length ; i ++ ) {
- copy [ i ] = WhitespaceEscapeUtil. escape ( array [ i ] ) ;
- }
- Hibernate. TEXT . nullSafeSet ( st, StringUtils. join ( copy, '' ) , index ) ;
- }
- }
- @ Override
- public Object deepCopy ( Object value ) throws HibernateException {
- return value ;
- }
- @ Override
- public boolean isMutable ( ) {
- return false ;
- }
- @ Override
- public Serializable disassemble ( Object value ) throws HibernateException {
- return ( Serializable ) value ;
- }
- @ Override
- public Object assemble ( Serialable cached, Object owner ) throws HibernateException {
- return cached ;
- }
- @ Override
- public Object replace ( Object original, Object target, Object owner ) throws HibernateException {
- return original ;
- }
- <class name = "StringArrayContainer" table = "containers" >
- <id name = "id" >
- <generator class = "native" />
- </ id >
- <property name = "tags" column = "tags" type = "StringArrayCustomType" />
- </ class >
Source: https://habr.com/ru/post/91328/
All Articles