Example usage for org.hibernate.metadata ClassMetadata isInherited

List of usage examples for org.hibernate.metadata ClassMetadata isInherited

Introduction

In this page you can find the example usage for org.hibernate.metadata ClassMetadata isInherited.

Prototype

boolean isInherited();

Source Link

Document

Does this entity extend a mapped superclass?

Usage

From source file:org.compass.gps.device.hibernate.dep.Hibernate3GpsDevice.java

License:Apache License

protected boolean isInherited(ClassMetadata classMetadata) throws HibernateGpsDeviceException {
    try {/*from w w  w.  ja  v a  2s.  c  o m*/
        // just try and invoke the Hibernate 3.2 support for this one
        return classMetadata.isInherited();
    } catch (Throwable t) {
        // do nothing
    }
    try {
        ClassUtils.forName("org.hibernate.event.SessionEventListenerConfig",
                compassGps.getMirrorCompass().getSettings().getClassLoader());
        return isInherited30(classMetadata);
    } catch (ClassNotFoundException e) {
        return isInherited31(classMetadata);
    }
}

From source file:org.compass.gps.device.hibernate.entities.DefaultHibernateEntitiesLocator.java

License:Apache License

/**
 * Returns <code>true</code> if the entity name needs to be filtered.
 *
 * <p>Implementation filteres out inherited hibernate mappings, since the select query
 * for the base class will cover any inherited classes as well.
 *
 * <p>Note, that this method is called after it has been verified that the class has
 * Compass mappings (either directly, or indirectly by an interface or a super class).
 *
 * @param entityname    The name of the entity
 * @param classMetadata The Hibernate class meta data.
 * @param device        The Hibernate Gps device
 * @return <code>true</code> if the entity should be filtered out, <code>false</code> if not.
 *///from  w  w  w .  j  av a 2 s .co m
protected boolean shouldFilter(String entityname, ClassMetadata classMetadata, Map allClassMetaData,
        HibernateGpsDevice device) {
    Class clazz = classMetadata.getMappedClass(EntityMode.POJO);
    // if it is inherited, do not add it to the classes to index, since the "from [entity]"
    // query for the base class will return results for this class as well
    if (classMetadata.isInherited()) {
        String superClassEntityName = ((AbstractEntityPersister) classMetadata).getMappedSuperclass();
        ClassMetadata superClassMetadata = (ClassMetadata) allClassMetaData.get(superClassEntityName);
        Class superClass = superClassMetadata.getMappedClass(EntityMode.POJO);
        // only filter out classes that their super class has compass mappings
        if (superClass != null
                && ((CompassGpsInterfaceDevice) device.getGps()).hasMappingForEntityForIndex(superClass)) {
            if (log.isDebugEnabled()) {
                log.debug("Entity [" + entityname + "] is inherited and super class [" + superClass
                        + "] has compass mapping, filtering it out");
            }
            return true;
        }
    }
    return false;
}

From source file:org.compass.gps.device.jpa.entities.HibernateJpaEntitiesLocator.java

License:Apache License

/**
 * Returns <code>true</code> if the entity name needs to be filtered.
 *
 * <p>Implementation filteres out inherited hibernate mappings, since the select query
 * for the base class will cover any inherited classes as well.
 *
 * <p>Note, that this method is called after it has been verified that the class has
 * Compass mappings (either directly, or indirectly by an interface or a super class).
 *
 * @param entityname    The name of the entity
 * @param classMetadata The Hibernate class meta data.
 * @param device        The Jpa Gps device
 * @return <code>true</code> if the entity should be filtered out, <code>false</code> if not.
 *//*from ww  w .  ja  v a 2  s . c o  m*/
protected boolean shouldFilter(String entityname, ClassMetadata classMetadata, Map allClassMetaData,
        JpaGpsDevice device) {
    Class<?> clazz = classMetadata.getMappedClass(EntityMode.POJO);
    // if it is inherited, do not add it to the classes to index, since the "from [entity]"
    // query for the base class will return results for this class as well
    if (classMetadata.isInherited()) {
        String superClassEntityName = ((AbstractEntityPersister) classMetadata).getMappedSuperclass();
        ClassMetadata superClassMetadata = (ClassMetadata) allClassMetaData.get(superClassEntityName);
        Class superClass = superClassMetadata.getMappedClass(EntityMode.POJO);
        // only filter out classes that their super class has compass mappings
        if (superClass != null
                && ((CompassGpsInterfaceDevice) device.getGps()).hasMappingForEntityForIndex(superClass)) {
            if (log.isDebugEnabled()) {
                log.debug("Entity [" + entityname + "] is inherited and super class [" + superClass
                        + "] has compass mapping, filtering it out");
            }
            return true;
        }
    }
    return false;
}

From source file:org.openspaces.persistency.hibernate.AbstractHibernateExternalDataSource.java

License:Open Source License

/**
 * Initializes the hibernate data source. Called by the Space.
 *
 * <p>If the session factory was not injected using {@link #setSessionFactory(org.hibernate.SessionFactory)},
 * will try can create it from the Properties file expecting to find a property called
 * <code>hibernate-config-file</code> with the location of the Hibernate config file.
 *
 * <p>Initializes the {@link #setManagedEntries(String...)} if they were not set explicitly by
 * iterating over all the mapped classes in Hibernate and adding them.
 *
 * <p>Also initializes the {@link #setInitialLoadEntries(String...)} if not set explicitly.
 *//* w  w  w. ja v a2 s. c o m*/
public void init(Properties properties) throws DataSourceException {
    if (logger.isDebugEnabled()) {
        logger.debug("Using initialLoadChunkSize [" + initialLoadChunkSize + "], fetchSize [" + fetchSize
                + "], initialLoadThreadPoolSize [" + initialLoadThreadPoolSize + "], performOrderById ["
                + performOrderById + "]");
    }
    if (sessionFactory == null) {
        createdSessionFactory = true;
        String hibernateFile = properties.getProperty(HIBERNATE_CFG_PROPERTY);
        if (hibernateFile == null) {
            logger.error("No session factory injected, and [" + HIBERNATE_CFG_PROPERTY
                    + "] is not provided in the properties file, can't create session factory");
        } else {
            logger.debug("[" + HIBERNATE_CFG_PROPERTY + "] " + hibernateFile
                    + " is provided in the properties file ");
        }
        try {
            sessionFactory = SessionFactoryBuilder.getFactory(hibernateFile);
        } catch (Exception e) {
            throw new DataSourceException(
                    "Failed to create session factory from properties file [" + hibernateFile + "]", e);
        }
    }
    if (managedEntries == null) {
        managedEntries = new HashSet<String>();
        // try and derive the managedEntries
        Map<String, ClassMetadata> allClassMetaData = sessionFactory.getAllClassMetadata();
        for (String entityname : allClassMetaData.keySet()) {
            managedEntries.add(entityname);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Using Hibernate managedEntries [" + managedEntries + "]");
    }
    if (initialLoadEntries == null) {
        Set<String> initialLoadEntries = new HashSet<String>();
        // try and derive the managedEntries
        Map<String, ClassMetadata> allClassMetaData = sessionFactory.getAllClassMetadata();
        for (Map.Entry<String, ClassMetadata> entry : allClassMetaData.entrySet()) {
            String entityname = entry.getKey();
            ClassMetadata classMetadata = entry.getValue();
            if (classMetadata.isInherited()) {
                String superClassEntityName = ((AbstractEntityPersister) classMetadata).getMappedSuperclass();
                ClassMetadata superClassMetadata = allClassMetaData.get(superClassEntityName);
                Class superClass = superClassMetadata.getMappedClass();
                // only filter out classes that their super class has mappings
                if (superClass != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Entity [" + entityname + "] is inherited and has a super class ["
                                + superClass + "] filtering it out for initial load managedEntries");
                    }
                    continue;
                }
            }
            initialLoadEntries.add(entityname);
        }
        this.initialLoadEntries = initialLoadEntries.toArray(new String[initialLoadEntries.size()]);
    }
    if (logger.isDebugEnabled()) {
        logger.debug(
                "Using Hibernate initial load managedEntries [" + Arrays.toString(initialLoadEntries) + "]");
    }
}

From source file:org.openspaces.persistency.hibernate.AbstractHibernateSpaceDataSource.java

License:Open Source License

private Set<String> createInitialLoadEntries(String[] initialLoadEntries, SessionFactory sessionFactory) {
    Set<String> result = new HashSet<String>();
    if (initialLoadEntries != null) {
        for (String entry : initialLoadEntries) {
            result.add(entry);//from   ww w  . ja  va 2  s .c o m
        }
    } else {
        // try and derive the managedEntries
        allMappedClassMetaData = sessionFactory.getAllClassMetadata();
        for (Map.Entry<String, ClassMetadata> entry : allMappedClassMetaData.entrySet()) {
            String entityName = entry.getKey();
            ClassMetadata classMetadata = entry.getValue();
            if (classMetadata.isInherited()) {
                String superClassEntityName = ((AbstractEntityPersister) classMetadata).getMappedSuperclass();
                ClassMetadata superClassMetadata = allMappedClassMetaData.get(superClassEntityName);
                Class superClass = superClassMetadata.getMappedClass();
                // only filter out classes that their super class has mappings
                if (superClass != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Entity [" + entityName + "] is inherited and has a super class ["
                                + superClass + "] filtering it out for initial load managedEntries");
                    }
                    continue;
                }
            }
            result.add(entityName);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(
                "Using Hibernate initial load managedEntries [" + Arrays.toString(initialLoadEntries) + "]");
    }
    return result;
}