Example usage for org.hibernate.type AbstractStandardBasicType fromStringValue

List of usage examples for org.hibernate.type AbstractStandardBasicType fromStringValue

Introduction

In this page you can find the example usage for org.hibernate.type AbstractStandardBasicType fromStringValue.

Prototype

@Override
    public T fromStringValue(String xml) throws HibernateException 

Source Link

Usage

From source file:org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContainerUserType.java

License:Open Source License

/** Creates the serializable id object from a string */
private Serializable extractID(Type type, String idString) {
    // first handle the most common case
    if (type instanceof AbstractStandardBasicType) {
        final AbstractStandardBasicType<?> ntype = (AbstractStandardBasicType<?>) type;
        return (Serializable) ntype.fromStringValue(idString);
    }//from   w ww  .j a v  a 2  s.  c o m

    // for all other cases the classname is encoded into the field
    final String className = idString.substring(0, idString.indexOf(ENCODING_SEPARATOR));
    final String strValue = idString.substring(1 + idString.indexOf(ENCODING_SEPARATOR));

    Constructor<?> constructor = constructorCache.get(className);
    if (constructor == null) {
        try {
            final Class<?> clazz = ClassLoaderResolver.classForName(className);
            constructor = clazz.getConstructor(new Class[] { String.class });
        } catch (StoreClassLoadException e) {
            throw new HbMapperException("Class " + className + " not found");
        } catch (NoSuchMethodException e) {
            throw new HbMapperException(
                    "Class " + className + " does not have a constructor with a String parameter!");
        }
    }
    if (constructor == null) {
        throw new HbMapperException(
                "Class " + className + " does not have a constructor with a String parameter!");
    }

    try {
        return (Serializable) constructor.newInstance(new Object[] { strValue });
    } catch (InvocationTargetException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    } catch (InstantiationException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    } catch (IllegalAccessException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierUtil.java

License:Open Source License

/** Creates the serializable id object from a string */
private static Serializable extractID(Type type, String idString) {
    // first handle the most common case
    if (type instanceof AbstractStandardBasicType) {
        final AbstractStandardBasicType<?> ntype = (AbstractStandardBasicType<?>) type;
        return (Serializable) ntype.fromStringValue(idString);
    }/*from  w  w  w .  j  a  v a2  s  .  c o m*/

    // for all other cases the classname of the type is encoded into the
    // field
    final String className = idString.substring(0, idString.indexOf(ENCODING_SEPARATOR));
    final String strValue = idString.substring(1 + idString.indexOf(ENCODING_SEPARATOR));

    Constructor<?> constructor = constructorCache.get(className);
    if (constructor == null) {
        try {
            final Class<?> clazz = ClassLoaderResolver.classForName(className);
            constructor = clazz.getConstructor(new Class[] { String.class });
        } catch (StoreClassLoadException e) {
            throw new HbMapperException("Class " + className + " not found");
        } catch (NoSuchMethodException e) {
            throw new HbMapperException(
                    "Class " + className + " does not have a constructor with a String parameter!");
        }
    }
    if (constructor == null) {
        throw new HbMapperException(
                "Class " + className + " does not have a constructor with a String parameter!");
    }

    try {
        return (Serializable) constructor.newInstance(new Object[] { strValue });
    } catch (InvocationTargetException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    } catch (InstantiationException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    } catch (IllegalAccessException e) {
        throw new HbMapperException("Can not instantiate: " + className + " using value " + strValue);
    }
}