Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java
new file mode 100644
index 0000000000..979f17b4cb
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java
@@ -0,0 +1,115 @@
+/***************************************************************************
+ * Copyright (c) 2008 - 2008 Martin Taal and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal - initial api
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.internal.protocol.model.CDOTypeImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOType;
+
+import org.hibernate.Hibernate;
+import org.hibernate.usertype.UserType;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * @author Martin Taal
+ */
+public class CDOTypeUserType implements UserType
+{
+
+ private static final int[] SQL_TYPES = { Types.INTEGER };
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+ public Class<?> returnedClass()
+ {
+ return CDOType.class;
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ public CDOTypeUserType()
+ {
+ }
+
+ public Object deepCopy(Object value)
+ {
+ return value;
+ }
+
+ public boolean equals(Object x, Object y)
+ {
+ if (x == y)
+ {
+ return true;
+ }
+ if (x == null || y == null)
+ {
+ return false;
+ }
+ return x.equals(y);
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException
+ {
+ final Integer value = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]);
+ if (rs.wasNull())
+ {
+ return null;
+ }
+ if (value == null)
+ {
+ return null;
+ }
+ return CDOTypeImpl.index.get(value);
+ }
+
+ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException
+ {
+ if (value != null)
+ {
+ statement.setInt(index, ((CDOType)value).getTypeID());
+ }
+ else
+ {
+ statement.setNull(index, Types.INTEGER);
+ }
+ }
+
+ public Serializable disassemble(Object value)
+ {
+ return (Serializable)value;
+ }
+
+ public Object assemble(Serializable cachedValue, Object owner)
+ {
+ return cachedValue;
+ }
+
+ public Object replace(Object original, Object target, Object owner)
+ {
+ return original;
+ }
+
+ public int hashCode(Object x)
+ {
+ return x.hashCode();
+ }
+}

Back to the top