Java Code Examples for org.hibernate.SessionFactory#getAllClassMetadata()

The following examples show how to use org.hibernate.SessionFactory#getAllClassMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericBaseCommonDao.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有数据表
 * 
 * @return
 */
public List<DBTable> getAllDbTableName() {
	List<DBTable> resultList = new ArrayList<DBTable>();
	SessionFactory factory = getSession().getSessionFactory();
	Map<String, ClassMetadata> metaMap = factory.getAllClassMetadata();
	for (String key : (Set<String>) metaMap.keySet()) {
		DBTable dbTable = new DBTable();
		AbstractEntityPersister classMetadata = (AbstractEntityPersister) metaMap
				.get(key);
		dbTable.setTableName(classMetadata.getTableName());
		dbTable.setEntityName(classMetadata.getEntityName());
		Class<?> c;
		try {
			c = Class.forName(key);
			JeecgEntityTitle t = c.getAnnotation(JeecgEntityTitle.class);
			dbTable.setTableTitle(t != null ? t.name() : "");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		resultList.add(dbTable);
	}
	return resultList;
}
 
Example 2
Source File: GenericBaseCommonDao.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有数据表
 *
 * @return
 */
public List<DBTable> getAllDbTableName() {
	List<DBTable> resultList = new ArrayList<DBTable>();
	SessionFactory factory = getSession().getSessionFactory();
	Map<String, ClassMetadata> metaMap = factory.getAllClassMetadata();
	for (String key : (Set<String>) metaMap.keySet()) {
		DBTable dbTable = new DBTable();
		AbstractEntityPersister classMetadata = (AbstractEntityPersister) metaMap
				.get(key);
		dbTable.setTableName(classMetadata.getTableName());
		dbTable.setEntityName(classMetadata.getEntityName());
		Class<?> c;
		try {
			c = Class.forName(key);
			JeecgEntityTitle t = c.getAnnotation(JeecgEntityTitle.class);
			dbTable.setTableTitle(t != null ? t.name() : "");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		resultList.add(dbTable);
	}
	return resultList;
}
 
Example 3
Source File: HibernateModelStructureBuilder.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public IModelStructure build() {
	
	IModelStructure dataMartStructure;
	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;
}
 
Example 4
Source File: DatabaseH2Service.java    From abixen-platform with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void loadSystemTableList(SessionFactory sessionFactory) {
    Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata();
    allClassMetadata.forEach((key, value) -> {
        AbstractEntityPersister abstractEntityPersister = (AbstractEntityPersister) value;
        SYSTEM_TABLE_LIST.add(abstractEntityPersister.getTableName());
    });
}
 
Example 5
Source File: GenericBaseCommonDao.java    From jeewx with Apache License 2.0 4 votes vote down vote up
/**
 * 获取所有数据表
 * 
 * @return
 */
public Integer getAllDbTableSize() {
	SessionFactory factory = getSession().getSessionFactory();
	Map<String, ClassMetadata> metaMap = factory.getAllClassMetadata();
	return metaMap.size();
}
 
Example 6
Source File: GenericBaseCommonDao.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/**
 * 获取所有数据表
 *
 * @return
 */
public Integer getAllDbTableSize() {
	SessionFactory factory = getSession().getSessionFactory();
	Map<String, ClassMetadata> metaMap = factory.getAllClassMetadata();
	return metaMap.size();
}