Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
19   97   16   1.58
12   61   0.84   12
12     1.33  
1    
 
 
  IntBooleanType       Line # 22 19 16 0% 0.0
 
No Tests
 
1    package org.itracker.persistence.dao;
2   
3    import java.io.Serializable;
4    import java.sql.PreparedStatement;
5    import java.sql.ResultSet;
6    import java.sql.SQLException;
7    import java.sql.Types;
8   
9    import org.hibernate.HibernateException;
10    import org.hibernate.usertype.UserType;
11   
12    /**
13    * A Hibernate <code>UserType</code> to map a Java boolean or java.lang.Boolean
14    * property to an SQL column of type INT with the values 0 (= false) or 1 (= true).
15    *
16    * <p>This is necessary because of the legacy ITracker 2.x database schema
17    * which uses INT instead of BOOLEAN or BIT, which aren't supported by all
18    * databases (e.g. DB2). </p>
19    *
20    * @author johnny
21    */
 
22    public final class IntBooleanType implements UserType {
23   
24    private static final int[] SQL_TYPES = { Types.INTEGER };
25   
26    /**
27    * Default constructor, required by Hibernate.
28    */
 
29  0 toggle public IntBooleanType() {
30    }
31   
 
32  0 toggle public void nullSafeSet(PreparedStatement statement, Object value, int index)
33    throws HibernateException, SQLException {
34  0 if (value == null) {
35  0 statement.setNull(index, Types.INTEGER);
36    } else {
37  0 final int intValue = ((Boolean) value).booleanValue() ? 1 : 0;
38  0 statement.setInt(index, intValue);
39    }
40    }
41   
 
42  0 toggle public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
43    throws HibernateException, SQLException {
44  0 final int value = resultSet.getInt(names[0]);
45  0 return resultSet.wasNull() ? null : (value == 1);
46    }
47   
 
48  0 toggle public int hashCode(Object x) throws HibernateException {
49    /* Apparently, there's no need to check for nulls here. */
50  0 assert (x != null);
51   
52  0 return x.hashCode();
53    }
54   
 
55  0 toggle public Serializable disassemble(Object value) throws HibernateException {
56  0 return (Serializable) value;
57    }
58   
 
59  0 toggle public Object deepCopy(Object value) throws HibernateException {
60  0 return value;
61    }
62   
 
63  0 toggle public int[] sqlTypes() {
64  0 return SQL_TYPES;
65    }
66   
 
67  0 toggle public Class<Boolean> returnedClass() {
68  0 return Boolean.class;
69    }
70   
 
71  0 toggle public Object replace(Object original, Object target, Object owner) throws HibernateException {
72  0 return original;
73    }
74   
 
75  0 toggle public boolean isMutable() {
76  0 return false;
77    }
78   
79    /**
80    * Implements persistence equality.
81    */
 
82  0 toggle public boolean equals(Object x, Object y) throws HibernateException {
83  0 if (x == y) {
84  0 return true;
85    }
86   
87  0 if (x == null || y == null) {
88  0 return false; // test (x == y) has been done before and was false.
89    }
90  0 return x.equals(y);
91    }
92   
 
93  0 toggle public Object assemble(Serializable cached, Object owner) throws HibernateException {
94  0 return cached;
95    }
96   
97    }