1 package net.sf.flock.hibernate;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8
9 import net.sf.hibernate.Hibernate;
10 import net.sf.hibernate.HibernateException;
11 import net.sf.hibernate.UserType;
12
13 public class URLType implements UserType {
14
15 private final static int[] TYPES = new int[] { java.sql.Types.VARCHAR };
16
17 /***
18 * @see cirrus.hibernate.UserType#sqlTypes()
19 */
20 public int[] sqlTypes() {
21 return TYPES;
22 }
23
24 /***
25 * @see cirrus.hibernate.UserType#returnedClass()
26 */
27 public Class returnedClass() {
28 return java.net.URL.class;
29 }
30
31 /***
32 * @see cirrus.hibernate.UserType#equals(java.lang.Object, java.lang.Object)
33 */
34 public boolean equals(Object x, Object y) {
35 if (x==y) return true;
36 if (x==null || y==null) return false;
37 return x.equals(y);
38 }
39
40 /***
41 * @see cirrus.hibernate.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String, java.lang.Object)
42 */
43 public Object nullSafeGet(ResultSet rs, String[] names, Object o) throws HibernateException, SQLException {
44 String url = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
45 if (url==null) {
46 return null;
47 }
48 try {
49 return new URL(url);
50 } catch (MalformedURLException e) {
51 throw new HibernateException(e);
52 }
53 }
54
55 /***
56 * @see cirrus.hibernate.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
57 */
58 public void nullSafeSet(PreparedStatement ps, Object value, int index) throws HibernateException, SQLException {
59 Hibernate.STRING.nullSafeSet(ps, value==null ? null : ((URL)value).toExternalForm(), index);
60 }
61
62 /***
63 * @see cirrus.hibernate.UserType#deepCopy(java.lang.Object)
64 */
65 public Object deepCopy(Object x) {
66 return x;
67 }
68
69 /***
70 * @see cirrus.hibernate.UserType#isMutable()
71 */
72 public boolean isMutable() {
73 return false;
74 }
75
76 }
This page was automatically generated by Maven