Example usage for org.hibernate.internal.util ReflectHelper classForName

List of usage examples for org.hibernate.internal.util ReflectHelper classForName

Introduction

In this page you can find the example usage for org.hibernate.internal.util ReflectHelper classForName.

Prototype

@Deprecated
public static Class classForName(String name) throws ClassNotFoundException 

Source Link

Document

Perform resolution of a class name.

Usage

From source file:com.github.pires.example.hibernate.user.types.JSONBUserType.java

License:Apache License

@Override
public void setParameterValues(Properties parameters) {
    final String clazz = (String) parameters.get(CLASS);
    try {//  w  w w. jav a2s  .c  o  m
        returnedClass = ReflectHelper.classForName(clazz);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Class: " + clazz + " is not a known class type.");
    }
}

From source file:org.babyfish.hibernate.cfg.Configuration.java

License:Open Source License

private static void replaceUserCollectionType(Property mappingProperty,
        Class<? extends org.hibernate.mapping.Collection> hibernateCollectionType,
        Class<? extends AbstractMACollectionType> babyfishCollectionType) {
    /*// w  ww  .  j  a v  a2  s.c om
     * Don't invoke property.getType() or property.getValue().getType()
     * that will cause the creating of original collection-type before the replacement.
     * that is is slow
     */
    Value value = mappingProperty.getValue();
    if (!(value instanceof org.hibernate.mapping.Collection)) {
        throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.'
                + mappingProperty.getName() + "\" must be mapped as collection.");
    }
    org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value;
    String typeName = collection.getTypeName();
    if (typeName == null) {
        if (!hibernateCollectionType.isAssignableFrom(value.getClass())) {
            throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.'
                    + mappingProperty.getName() + "\" must be mapped collection whose hibernate type is \""
                    + hibernateCollectionType.getName() + "\".");
        }
        collection.setTypeName(babyfishCollectionType.getName());
    } else {
        Class<?> userCollctionType;
        try {
            userCollctionType = ReflectHelper.classForName(typeName);
        } catch (ClassNotFoundException ex) {
            throw new MappingException(
                    '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName()
                            + "\" must be mapped as collection whose attribute \"collection-type\" is \""
                            + typeName + "\", but the there is no java type names\"" + typeName + "\".");
        }
        if (!babyfishCollectionType.isAssignableFrom(userCollctionType)) {
            throw new MappingException(
                    '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName()
                            + "\" must be mapped as collection whose attribut \"collection-type\" is \""
                            + typeName + "\", but the there class \"" + typeName + "\" is not \""
                            + babyfishCollectionType.getName() + "\" or its derived class.");
        }
    }
}

From source file:org.babyfish.hibernate.cfg.SettingsFactory.java

License:Open Source License

@Override
protected final QueryTranslatorFactory createQueryTranslatorFactory(Properties properties,
        ServiceRegistry serviceRegistry) {
    if (properties.containsKey(Environment.QUERY_TRANSLATOR)) {
        throw new HibernateException("the property \"" + Environment.QUERY_TRANSLATOR + "\" is deprecated by \""
                + OBJECT_QUERY_TRANSLATOR_FACTORY + "\"");
    }//from w  w w. ja v  a2 s  .  c om
    String className = ConfigurationHelper.getString(AvailableSettings.QUERY_TRANSLATOR, properties,
            XQueryTranslatorFactoryImpl.class.getName());
    LOGGER.info("Entity query translator: " + className);
    final XQueryTranslatorFactory translatorFactory;
    Class<?> xQueryTranslatorFactoryImplClass;
    try {
        xQueryTranslatorFactoryImplClass = ReflectHelper.classForName(className);
    } catch (ClassNotFoundException ex) {
        throw new HibernateException(LAZY_RESOURCE.get()
                .notExistingXQueryTransalatorFactoryImpl(XQueryTranslatorFactory.class, className));
    }
    try {
        translatorFactory = (XQueryTranslatorFactory) xQueryTranslatorFactoryImplClass.newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
        throw new HibernateException(LAZY_RESOURCE.get().failedToInstantiateXQueryTranslatorFactory(
                XQueryTranslatorFactory.class, xQueryTranslatorFactoryImplClass), ex);
    }

    return new QueryTranslatorFactory() {

        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public QueryTranslator createQueryTranslator(String queryIdentifier, String queryString, Map filters,
                SessionFactoryImplementor factory, EntityGraphQueryHint entityGraphQueryHint) {
            return translatorFactory.createQueryTranslator(queryIdentifier, queryString,
                    XQueryPlan.currentPathPlanKey(), filters, factory, entityGraphQueryHint);
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public FilterTranslator createFilterTranslator(String queryIdentifier, String queryString, Map filters,
                SessionFactoryImplementor factory) {
            return translatorFactory.createFilterTranslator(queryIdentifier, queryString,
                    XQueryPlan.currentPathPlanKey(), filters, factory);
        }
    };
}

From source file:org.bonitasoft.engine.business.data.impl.SchemaManager.java

License:Open Source License

public Class<?> getMappedClass(final String className) throws MappingException {
    if (className == null) {
        return null;
    }//from w w w.jav  a2s . c o m
    try {
        return ReflectHelper.classForName(className);
    } catch (final ClassNotFoundException cnfe) {
        throw new MappingException("entity class not found: " + className, cnfe);
    }
}

From source file:org.codehaus.groovy.grails.orm.hibernate.GrailsSessionContext.java

License:Apache License

protected Constructor<?> lookupConstructor(String className, Class<?>... argTypes) {
    try {//  w  w  w  .  j ava 2  s. co  m
        Class<?> clazz = ReflectHelper.classForName(className);
        Constructor<?> constructor = clazz.getConstructor(argTypes);
        constructor.setAccessible(true);
        return constructor;
    } catch (ClassNotFoundException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (NoSuchMethodException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (SecurityException e) {
        ReflectionUtils.handleReflectionException(e);
    }
    return null;
}

From source file:utilities.internal.CopyOfDatabaseUtil.java

License:Open Source License

public CopyOfDatabaseUtil() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    // Due to a bug in Hibernate 4.3.0.Final, the old Hibernate persistence
    // provider's selected
    // by default, which causes a deprecation warning to be output to the
    // console. That means that
    // we shouldn't use Persistence to create the entity manager factory.
    // entityManagerFactory =
    // Persistence.createEntityManagerFactory(PersistenceUnit);

    persistenceProvider = new HibernatePersistenceProvider();
    entityManagerFactory = persistenceProvider.createEntityManagerFactory(DatabaseConfig.PersistenceUnit, null);
    entityManager = entityManagerFactory.createEntityManager();

    properties = entityManagerFactory.getProperties();

    databaseUrl = findProperty("javax.persistence.jdbc.url");
    databaseName = StringUtils.substringAfterLast(databaseUrl, "/");
    databaseDialectName = findProperty("hibernate.dialect");
    databaseDialect = (Dialect) ReflectHelper.classForName(databaseDialectName).newInstance();

    configuration = buildConfiguration();

    entityTransaction = entityManager.getTransaction();
}

From source file:utilities.internal.DatabaseUtil.java

License:Open Source License

public DatabaseUtil() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    // Due to a bug in Hibernate 4.3.0.Final, the old Hibernate persistence provider's selected
    // by default, which causes a deprecation warning to be output to the console. That means that
    // we shouldn't use Persistence to create the entity manager factory.
    // entityManagerFactory = Persistence.createEntityManagerFactory(PersistenceUnit);

    persistenceProvider = new HibernatePersistenceProvider();
    entityManagerFactory = persistenceProvider.createEntityManagerFactory(DatabaseConfig.PersistenceUnit, null);
    entityManager = entityManagerFactory.createEntityManager();

    properties = entityManagerFactory.getProperties();

    databaseUrl = findProperty("javax.persistence.jdbc.url");
    databaseName = StringUtils.substringAfterLast(databaseUrl, "/");
    databaseDialectName = findProperty("hibernate.dialect");
    databaseDialect = (Dialect) ReflectHelper.classForName(databaseDialectName).newInstance();

    configuration = buildConfiguration();

    entityTransaction = entityManager.getTransaction();
}