Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-03-19 10:38:43 +0000
committerEike Stepper2012-03-19 10:38:43 +0000
commit1e85ec5f36e5a71ac4a4490a0de8c18e8c9aa2d7 (patch)
tree4ff3d44440da0383f7a200bcd822a9d33112bdf4 /plugins/org.eclipse.emf.cdo.server.hibernate
parenteac2d6262d50140bcd3ada1b70f7cf9f5c1a53b3 (diff)
downloadcdo-1e85ec5f36e5a71ac4a4490a0de8c18e8c9aa2d7.tar.gz
cdo-1e85ec5f36e5a71ac4a4490a0de8c18e8c9aa2d7.tar.xz
cdo-1e85ec5f36e5a71ac4a4490a0de8c18e8c9aa2d7.zip
[374632] NumberFormatException when converting String to CDO LOB
https://bugs.eclipse.org/bugs/show_bug.cgi?id=374632
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOLobUserType.java300
1 files changed, 150 insertions, 150 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOLobUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOLobUserType.java
index 92e77ec23f..f9d9a5638d 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOLobUserType.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOLobUserType.java
@@ -1,150 +1,150 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.lob.CDOBlob;
-import org.eclipse.emf.cdo.common.lob.CDOClob;
-import org.eclipse.emf.cdo.common.lob.CDOLob;
-
-import org.eclipse.net4j.util.HexUtil;
-
-import org.hibernate.type.StandardBasicTypes;
-import org.hibernate.usertype.ParameterizedType;
-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;
-import java.util.Properties;
-
-/**
- * Base class for persisting {@link CDOBlob} and {@link CDOClob}.
- */
-public abstract class CDOLobUserType implements UserType, ParameterizedType
-{
- private static final String SEPARATOR = " - ";
-
- private static final int[] SQL_TYPES = { Types.CLOB };
-
- public CDOLobUserType()
- {
- }
-
- public void setParameterValues(Properties arg0)
- {
- }
-
- public int[] sqlTypes()
- {
- return SQL_TYPES;
- }
-
- public boolean isMutable()
- {
- return false;
- }
-
- 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
- {
- try
- {
- final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0]);
- if (rs.wasNull())
- {
- return null;
- }
-
- return convertStringToLob(value);
- }
- catch (Exception e)
- {
- throw new IllegalStateException(e);
- }
- }
-
- public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException
- {
- try
- {
- final CDOLob<?> cdoLob = (CDOLob<?>)value;
-
- if (value == null || cdoLob.getSize() == 0)
- {
- statement.setNull(index, Types.VARCHAR);
- return;
- }
- statement.setString(index, convertLobToString(cdoLob));
- }
- catch (Exception e)
- {
- throw new IllegalStateException(e);
- }
- }
-
- public Serializable disassemble(Object value)
- {
- return (Serializable)value;
- }
-
- public Object assemble(Serializable cachedValue, Object owner)
- {
- return cachedValue;
- }
-
- private String convertLobToString(CDOLob<?> lob)
- {
- return HexUtil.bytesToHex(lob.getID()) + SEPARATOR + lob.getSize();
- }
-
- private Object convertStringToLob(String lobId)
- {
- int pos = lobId.indexOf(SEPARATOR);
-
- byte[] id = HexUtil.hexToBytes(lobId.substring(0, pos));
- long size = Long.parseLong(lobId.substring(pos + 1));
- return createLob(id, size);
- }
-
- protected abstract Object createLob(byte[] id, long size);
-
- public Object replace(Object original, Object target, Object owner)
- {
- return original;
- }
-
- public int hashCode(Object x)
- {
- return x.hashCode();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
+
+import org.eclipse.emf.cdo.common.lob.CDOBlob;
+import org.eclipse.emf.cdo.common.lob.CDOClob;
+import org.eclipse.emf.cdo.common.lob.CDOLob;
+
+import org.eclipse.net4j.util.HexUtil;
+
+import org.hibernate.type.StandardBasicTypes;
+import org.hibernate.usertype.ParameterizedType;
+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;
+import java.util.Properties;
+
+/**
+ * Base class for persisting {@link CDOBlob} and {@link CDOClob}.
+ */
+public abstract class CDOLobUserType implements UserType, ParameterizedType
+{
+ private static final String SEPARATOR = " - ";
+
+ private static final int[] SQL_TYPES = { Types.CLOB };
+
+ public CDOLobUserType()
+ {
+ }
+
+ public void setParameterValues(Properties arg0)
+ {
+ }
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ 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
+ {
+ try
+ {
+ final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0]);
+ if (rs.wasNull())
+ {
+ return null;
+ }
+
+ return convertStringToLob(value);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException
+ {
+ try
+ {
+ final CDOLob<?> cdoLob = (CDOLob<?>)value;
+
+ if (value == null || cdoLob.getSize() == 0)
+ {
+ statement.setNull(index, Types.VARCHAR);
+ return;
+ }
+ statement.setString(index, convertLobToString(cdoLob));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public Serializable disassemble(Object value)
+ {
+ return (Serializable)value;
+ }
+
+ public Object assemble(Serializable cachedValue, Object owner)
+ {
+ return cachedValue;
+ }
+
+ private String convertLobToString(CDOLob<?> lob)
+ {
+ return HexUtil.bytesToHex(lob.getID()) + SEPARATOR + lob.getSize();
+ }
+
+ private Object convertStringToLob(String lobId)
+ {
+ int pos = lobId.indexOf(SEPARATOR);
+
+ byte[] id = HexUtil.hexToBytes(lobId.substring(0, pos));
+ long size = Long.parseLong(lobId.substring(pos + SEPARATOR.length()));
+ return createLob(id, size);
+ }
+
+ protected abstract Object createLob(byte[] id, long size);
+
+ public Object replace(Object original, Object target, Object owner)
+ {
+ return original;
+ }
+
+ public int hashCode(Object x)
+ {
+ return x.hashCode();
+ }
+}

Back to the top