Example usage for org.hibernate SessionFactory getAllClassMetadata

List of usage examples for org.hibernate SessionFactory getAllClassMetadata

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getAllClassMetadata.

Prototype

@Deprecated
Map<String, ClassMetadata> getAllClassMetadata();

Source Link

Document

Retrieve the ClassMetadata for all mapped entities.

Usage

From source file:gov.nih.nci.security.authorization.attributeLevel.UserClassAttributeMapCache.java

License:BSD License

public static void setAttributeMap(String userName, SessionFactory sessionFactory,
        AuthorizationManager authorizationManager) {
    if (cache == null)
        initializeCache();//from   w ww .j av a  2 s .  c o  m

    String privilegeName = "READ";
    Map map = sessionFactory.getAllClassMetadata();
    Set set = map.keySet();
    ArrayList list = new ArrayList(set);

    List<ClassAttributeMap> classAttributeMapList = new ArrayList<ClassAttributeMap>();

    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        String className = (String) iterator.next();
        ClassAttributeMap classAttributeMap = null;
        if (!StringUtilities.isBlank(className)) {
            classAttributeMap = new ClassAttributeMap(className);
        }
        List attributeList = authorizationManager.getAttributeMap(userName, className, privilegeName);
        if (null != attributeList && attributeList.size() != 0) {
            if (classAttributeMap != null) {
                classAttributeMap.setAttributes(attributeList);
            }
        }
        if (classAttributeMap != null)
            classAttributeMapList.add(classAttributeMap);
    }

    putClassAttributeMapInCache(userName, classAttributeMapList);

}

From source file:gov.nih.nci.security.authorization.attributeLevel.UserClassAttributeMapCache.java

License:BSD License

public static void setAttributeMapForGroup(String[] groupNames, SessionFactory sessionFactory,
        AuthorizationManager authorizationManager) {
    if (cache == null)
        initializeCache();//  w  ww .j  a  v  a2 s. c  om

    String privilegeName = "READ";
    Map map = sessionFactory.getAllClassMetadata();
    Set set = map.keySet();
    ArrayList list = new ArrayList(set);

    for (int i = 0; i < groupNames.length; i++) {
        List<ClassAttributeMap> classAttributeMapList = new ArrayList<ClassAttributeMap>();

        String groupName = groupNames[i];

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            String className = (String) iterator.next();
            ClassAttributeMap classAttributeMap = null;
            if (!StringUtilities.isBlank(className)) {
                classAttributeMap = new ClassAttributeMap(className);
            }
            List attributeList = authorizationManager.getAttributeMapForGroup(groupName, className,
                    privilegeName);
            if (null != attributeList && attributeList.size() != 0) {
                if (classAttributeMap != null) {
                    classAttributeMap.setAttributes(attributeList);
                }
            }
            if (classAttributeMap != null)
                classAttributeMapList.add(classAttributeMap);
        }
        putClassAttributeMapInCache(groupName, classAttributeMapList);

    }
}

From source file:gov.nih.nci.security.upt.util.HibernateHelper.java

License:BSD License

public static List getAllClassNames(SessionFactory sessionFactory) {
    Map map = sessionFactory.getAllClassMetadata();
    Set<String> set = map.keySet();
    ArrayList<String> list = new ArrayList();
    for (String className : set) {
        list.add(className);/*from w  w w.java2s. c  o m*/
    }
    return list;
}

From source file:gumga.framework.application.GumgaUntypedRepository.java

private List<Class> getAllIndexedEntities() {
    List<Class> aRetornar = new ArrayList<>();
    Session session = em.unwrap(Session.class);
    SessionFactory sessionFactory = session.getSessionFactory();
    Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata();
    for (String k : map.keySet()) {
        Class mappedClass = map.get(k).getMappedClass();
        if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) {
            aRetornar.add(mappedClass);/*from w  w w. j a  v  a  2s.co  m*/
        }
    }
    return aRetornar;
}

From source file:io.gumga.application.GumgaUntypedRepository.java

/**
 * Pegar as entidades que esto anotadas com {@link Indexed}
 * @return dados da pesquisa//from w  w w  .  ja v a2  s  .c om
 */
private List<Class> getAllIndexedEntities() {
    List<Class> aRetornar = new ArrayList<>();
    Session session = em.unwrap(Session.class);
    SessionFactory sessionFactory = session.getSessionFactory();
    Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata();
    for (String k : map.keySet()) {
        Class mappedClass = map.get(k).getMappedClass();
        if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) {
            aRetornar.add(mappedClass);
        }
    }
    return aRetornar;
}

From source file:it.eng.qbe.model.structure.builder.hibernate.HibernateModelStructureBuilder.java

License:Mozilla Public License

public IModelStructure build() {

    IModelStructure dataMartStructure;/*from ww  w. jav a  2  s.com*/
    List<IDataSourceConfiguration> subConfigurations;
    String datamartName;
    Map classMetadata;

    dataMartStructure = new ModelStructure();
    dataMartStructure.setName(getDataSource().getName());
    propertiesInitializer.addProperties(dataMartStructure);

    subConfigurations = getDataSource().getSubConfigurations();
    for (int i = 0; i < subConfigurations.size(); i++) {
        datamartName = subConfigurations.get(i).getModelName();
        Assert.assertNotNull(getDataSource(), "datasource cannot be null");
        SessionFactory sf = getDataSource().getHibernateSessionFactory(datamartName);
        if (sf == null) {
            throw new MissingResourceException(
                    "Impossible to find the jar file associated to datamart named: [" + datamartName + "]",
                    SessionFactory.class.getName(), datamartName);
        }

        Map calculatedFields = subConfigurations.get(i).loadCalculatedFields();
        dataMartStructure.setCalculatedFields(calculatedFields);

        classMetadata = sf.getAllClassMetadata();
        for (Iterator it = classMetadata.keySet().iterator(); it.hasNext();) {
            String entityType = (String) it.next();
            addEntity(dataMartStructure, datamartName, entityType);
        }
    }

    return dataMartStructure;
}

From source file:kr.debop4j.search.tools.SearchTool.java

License:Apache License

/**
 * ??? ? ? ./*from ww w. j  a  va  2 s .  c o m*/
 *
 * @param sessionFactory the session factory
 * @return ??? ? 
 */
public static Set<Class> getIndexedClasses(SessionFactory sessionFactory) {
    if (log.isDebugEnabled())
        log.debug("? ? ???  ? .");

    final Set<Class> classes = Sets.newHashSet();
    Collection<ClassMetadata> metadatas = sessionFactory.getAllClassMetadata().values();

    for (ClassMetadata meta : metadatas) {
        Class clazz = meta.getMappedClass();
        if (clazz.getAnnotation(Indexed.class) != null) {
            classes.add(clazz);

            log.trace("??? =[{}]", clazz);
        }
    }
    return classes;
}

From source file:ome.services.db.SqlActionTest.java

License:Open Source License

/**
 * Walks through all model object classes, and any that have a generator
 * annotation://from   ww  w  .  java 2 s  .c  o  m
 * <pre>
 * &#64;org.hibernate.annotations.GenericGenerator(name = "seq_lightpathemissionfilterlink",
 *  strategy = "ome.util.TableIdGenerator",
 *  parameters = {
 *      &#64;org.hibernate.annotations.Parameter(name = "table_name", value = "seq_table"),
 *      &#64;org.hibernate.annotations.Parameter(name = "segment_value", value = "seq_lightpathemissionfilterlink"),
 *      &#64;org.hibernate.annotations.Parameter(name = "optimizer", value = "pooled"),
 *      &#64;org.hibernate.annotations.Parameter(name = "increment_size", value = "50")
 *  })
 * </pre>
 * will be tested.
 */
@SuppressWarnings("unchecked")
@Test(groups = "ticket:3886")
public void testGetEachSequenceOnce() throws Exception {

    final SessionFactory factory = applicationContext.getBean("sessionFactory", SessionFactory.class);

    @SuppressWarnings("unchecked")
    final Map<String, ClassMetadata> m = factory.getAllClassMetadata();

    for (String seq : m.keySet()) {
        Class<?> k = Class.forName(seq);
        GenericGenerator gg = k.getAnnotation(GenericGenerator.class);
        if (gg == null) {
            continue;
        }
        String segment_value = null;
        for (Parameter p : gg.parameters()) {
            if (p.name().equals("segment_value")) {
                segment_value = p.value();
                break;
            }
        }
        assertNotNull(segment_value);
        sql.nextValue(segment_value, 1);
    }
}

From source file:org.ambraproject.testutils.DummyHibernateDataStore.java

License:Apache License

@Required
public void setSessionFactory(SessionFactory sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    allClassMetadata = sessionFactory.getAllClassMetadata();
}

From source file:org.beanfuse.entity.context.HibernateEntityContext.java

License:Open Source License

public void initFrom(SessionFactory sessionFactory) {
    if (null != sessionFactory && entityTypes.isEmpty()) {
        Map classMetadatas = sessionFactory.getAllClassMetadata();
        for (Iterator iter = classMetadatas.values().iterator(); iter.hasNext();) {
            ClassMetadata cm = (ClassMetadata) iter.next();
            buildEntityType(sessionFactory, cm.getEntityName());
        }/*  w  w w.  ja  v a  2  s.co m*/
        logger.info("success confiure {} entity types from hibernate!", new Integer(entityTypes.size()));
        logger.info("success confiure {} collection types from hibernate!",
                new Integer(collectionTypes.size()));

        if (logger.isDebugEnabled()) {
            loggerTypeInfo();
        }
        collectionTypes.clear();
    }
}