当前位置: 首页>>代码示例>>Java>>正文


Java ClassMetadata类代码示例

本文整理汇总了Java中org.hibernate.metadata.ClassMetadata的典型用法代码示例。如果您正苦于以下问题:Java ClassMetadata类的具体用法?Java ClassMetadata怎么用?Java ClassMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassMetadata类属于org.hibernate.metadata包,在下文中一共展示了ClassMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fixCompositeIdentifierInMetaModel

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
private static void fixCompositeIdentifierInMetaModel(SessionFactory sessionFactory, Class clazz) {
    ClassMetadata classMetadata = sessionFactory.getClassMetadata(clazz);
    if (classMetadata instanceof AbstractEntityPersister) {
        AbstractEntityPersister persister = (AbstractEntityPersister) classMetadata;
        EntityMetamodel model = persister.getEntityMetamodel();
        IdentifierProperty identifier = model.getIdentifierProperty();

        try {
            Field field = IdentifierProperty.class.getDeclaredField("hasIdentifierMapper");
            field.setAccessible(true);
            field.set(identifier, true);
            field.setAccessible(false);
        } catch (Exception ex) {
            throw new SystemException("Attempt to fix entity meta model with hack failed, reason: "
                    + ex.getMessage(), ex);
        }
    }
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:19,代码来源:RUtil.java

示例2: getIdName

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
/**
 * 取得对象的主键名,辅助函数.
 * 
 * @param entityClass
 *            实体类型
 * @return 主键名称
 */
public String getIdName(Class entityClass) {
    Assert.notNull(entityClass);
    entityClass = ReflectUtils.getOriginalClass(entityClass);

    ClassMetadata meta = this.getSessionFactory().getClassMetadata(
            entityClass);
    Assert.notNull(meta, "Class " + entityClass
            + " not define in hibernate session factory.");

    String idName = meta.getIdentifierPropertyName();
    Assert.hasText(idName, entityClass.getSimpleName()
            + " has no identifier property define.");

    return idName;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:23,代码来源:HibernateBasicDao.java

示例3: truncate

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
@Transactional
public void truncate() throws Exception {
	List<String> tableNames = new ArrayList<>();
	Session session = entityManager.unwrap(Session.class);
	Map<String, ClassMetadata> hibernateMetadata = session.getSessionFactory().getAllClassMetadata();

	for (ClassMetadata classMetadata : hibernateMetadata.values()) {
		AbstractEntityPersister aep = (AbstractEntityPersister) classMetadata;
		tableNames.add(aep.getTableName());
	}

	entityManager.flush();
	entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate();
	tableNames.forEach(tableName -> entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate());
	entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate();
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:17,代码来源:TruncateDatabaseService.java

示例4: _hasRecord

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
private boolean _hasRecord(Object value, Map<String, Object> fieldMap, String idName, Serializable idValue, ClassMetadata meta){
    DetachedCriteria criteria = DetachedCriteria
            .forClass(value.getClass())
            .setProjection(Projections.rowCount());

    for(Map.Entry<String, Object> fieldEntry: fieldMap.entrySet()){
        criteria.add(Restrictions.eq(fieldEntry.getKey(), fieldEntry.getValue()));
    }

    if(idValue != null){
        criteria.add(Restrictions.ne(idName, idValue));
    }

    Number count = (Number)criteria
            .getExecutableCriteria(getTmpSession())
            .list().iterator().next();

    return count.intValue() > 0;
}
 
开发者ID:Klinton90,项目名称:UniqueValidator,代码行数:20,代码来源:UniqueValidator.java

示例5: _countRows

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
private TreeMap<String, Object> _countRows(Object value) {
    ClassMetadata meta = getSessionFactory().getClassMetadata(value.getClass());
    String idName = meta.getIdentifierPropertyName();
    Serializable idValue = meta.getIdentifier(value, (SessionImplementor)getTmpSession());

    ArrayList<String[]> fieldSets;
    if(this._fields.length > 0){
        fieldSets = _prepareFields();
    }else{
        fieldSets = _getFieldsFromUniqueConstraint(value);
        fieldSets.addAll(_extractFieldsFromObject(value));
    }

    for(String[] fieldSet : fieldSets){
        TreeMap<String, Object> fieldMap = new TreeMap<>();
        for(String fieldName: fieldSet){
            fieldMap.put(fieldName, meta.getPropertyValue(value, fieldName));
        }
        if(_hasRecord(value, fieldMap, idName, idValue, meta)){
            return fieldMap;
        }
    }

    return null;
}
 
开发者ID:Klinton90,项目名称:UniqueValidator,代码行数:26,代码来源:UniqueValidator.java

示例6: modifyConstraints

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
private static void modifyConstraints(SessionFactoryImpl sessionFactoryImpl) {
    ClassMetadata classMetadata = sessionFactoryImpl.getClassMetadata(MCRCategoryImpl.class);
    AbstractEntityPersister aep = (AbstractEntityPersister) classMetadata;
    String qualifiedTableName = aep.getTableName();
    try (Session session = sessionFactoryImpl.openSession()) {
        session.doWork(connection -> {
            String updateStmt = Stream.of("ClassLeftUnique", "ClassRightUnique")
                .flatMap(idx -> Stream.of("drop constraint if exists " + idx,
                    MessageFormat.format(
                        "add constraint {0} unique ({1}) deferrable initially deferred",
                        idx, getUniqueColumns(MCRCategoryImpl.class, idx))))
                .collect(Collectors.joining(", ", getAlterTableString(connection) + qualifiedTableName + " ", ""));
            try (Statement stmt = connection.createStatement()) {
                LogManager.getLogger().info("Fixing PostgreSQL Schema for {}:\n{}", qualifiedTableName, updateStmt);
                stmt.execute(updateStmt);
            }
        });
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:20,代码来源:MCRHibernateConfigHelper.java

示例7: main

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
    final Session session = getSession();
    try {
        System.out.println("querying all the managed entities...");
        final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
        for (Object key : metadataMap.keySet()) {
            final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
            final String entityName = classMetadata.getEntityName();
            final Query query = session.createQuery("from " + entityName);
            System.out.println("executing: " + query.getQueryString());
            for (Object o : query.list()) {
                System.out.println("  " + o);
            }
        }
    } finally {
        session.close();
    }
}
 
开发者ID:jonashao,项目名称:ssh,代码行数:19,代码来源:Main.java

示例8: testCreationOfSessionFactory

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
@Test
public void testCreationOfSessionFactory() {
    Properties props = getProperties();
    Config conf = ConfigFactory.parseProperties(props);

    hs = new HibernateService(conf);
    SessionFactory sf = hs.getSessionFactory();
    assertNotNull(sf);
    assertFalse(sf.isClosed());

    // traverse through the session factory to get at configuration values
    SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
    StandardServiceRegistry ssr = sfo.getServiceRegistry();
    ConfigurationService cs = ssr.getService(ConfigurationService.class);
    assertEquals(props.getProperty("hibernate.connection.driver_class"), cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.connection.url"), cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.dialect"), cs.getSetting("hibernate.dialect", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.hbm2ddl.auto"), cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));

    // check mapping
    ClassMetadata cm = sf.getClassMetadata(TestObject.class);
    String[] names = cm.getPropertyNames();
    assertEquals(1, names.length);
    assertEquals("name", names[0]);
    assertEquals("string", cm.getPropertyType("name").getName());
}
 
开发者ID:DorsetProject,项目名称:dorset-framework,代码行数:27,代码来源:HibernateServiceTest.java

示例9: extractIdPropertyNames

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
    final IdClass idClassAnn = entity.getClass().getAnnotation(IdClass.class);
    if (idClassAnn != null)
    {
        final Class<?> entityClass = idClassAnn.value();
        final List<String> retVal = new ArrayList<>(3);
        ReflectionUtils.doWithFields(entityClass, (f)->
           {
               if (! Modifier.isStatic(f.getModifiers()))
               {
                   retVal.add(f.getName());
               }
           });
        return retVal.toArray(new String[retVal.size()]);
    }
    else
    {
        final ClassMetadata classMetadata = factory.getClassMetadata(entity.getClass());
        final String propertyName = classMetadata.getIdentifierPropertyName();
        return propertyName != null ? new String[]{propertyName} : null;
    }
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:25,代码来源:HibernateLazyIdExtractor.java

示例10: getAllDbMetaData

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
public HealthInfoDTO getAllDbMetaData() {
    List<TableInfoDTO> tables = new ArrayList<>();
    try {
        Map<String, ClassMetadata> map = saudeDao.getAllDbMetaData();
        map.forEach((k, v) -> tables.add(getTableInfo((AbstractEntityPersister) v)));

        Optional<IValidatorDatabase> validator = verificaDialetoUtilizado();
        if (validator.isPresent()) {
            validator.get().checkAllInfoTable(tables);
        }
    } catch (Exception e) {
        getLogger().error(e.getMessage(), e);
        tables.clear();
    }
    return new HealthInfoDTO(tables);
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:17,代码来源:HealthSystemDbService.java

示例11: getIdMetadata

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
    Map<String, Object> response = new HashMap<String, Object>();
    SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
    
    ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
    if (metadata == null) {
        return null;
    }
    
    String idProperty = metadata.getIdentifierPropertyName();
    response.put("name", idProperty);
    Type idType = metadata.getIdentifierType();
    response.put("type", idType);

    return response;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:18,代码来源:DynamicDaoHelperImpl.java

示例12: exists

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
protected boolean exists(BulkItem bulkItem, StatelessSession session) {
    
    Criteria criteria = null;
    switch (bulkItem.getOperation()) {
        case BulkItem.REMOVE:
        case BulkItem.WRITE:
        case BulkItem.UPDATE:
            Object entry = bulkItem.getItem();
            criteria = session.createCriteria(entry.getClass().getName());
            ClassMetadata classMetaData = getSessionFactory().getClassMetadata(entry.getClass());
            criteria.add(Restrictions.idEq(classMetaData.getIdentifier(entry)));
            criteria.setProjection(Projections.rowCount());
            return ((Number) criteria.uniqueResult()).intValue() > 0;
        case BulkItem.PARTIAL_UPDATE:
            criteria = session.createCriteria(bulkItem.getTypeName());
            criteria.add(Restrictions.idEq(bulkItem.getIdPropertyValue()));
            criteria.setProjection(Projections.rowCount());
            return ((Number) criteria.uniqueResult()).intValue() > 0;
       default:
            return false;
    }
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:23,代码来源:StatelessHibernateExternalDataSource.java

示例13: getId

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
/**
 * Return pojo identifier
 */
protected Object getId(Object template) {
    Object id = null;

    ClassMetadata classMetaData = getMetadata(template);

    if (classMetaData == null) //Unexpected class entity
        return null;

    if (template instanceof IGSEntry) {
        id = ((IGSEntry) template).getFieldValue(classMetaData.getIdentifierPropertyName());
    } else {
        id = classMetaData.getIdentifier(template);
    }

    return id;
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:20,代码来源:CriteriaHibernateExternalDataSource.java

示例14: getMetadata

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
/**
 * Return pojo entry metadata
 */
protected ClassMetadata getMetadata(Object entry) {
    String pojoName = null;
    if (entry instanceof IGSEntry)
        pojoName = ((IGSEntry) entry).getClassName();
    else
        pojoName = entry.getClass().getName();

    ClassMetadata entryClassMetadata = metaDataTable.get(pojoName);
    if (entryClassMetadata == null) {
        entryClassMetadata = getSessionFactory().getClassMetadata(pojoName);
        if (entryClassMetadata != null)
            metaDataTable.put(pojoName, entryClassMetadata);
    }
    return entryClassMetadata;
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:19,代码来源:CriteriaHibernateExternalDataSource.java

示例15: updaterCopyToPersistentObject

import org.hibernate.metadata.ClassMetadata; //导入依赖的package包/类
/**
 * 将更新对象拷贝至实体对象,并处理many-to-one的更新。
 * 
 * @param updater
 * @param po
 */
private void updaterCopyToPersistentObject(Updater<T> updater, T po,
		ClassMetadata cm) {
	String[] propNames = cm.getPropertyNames();
	String identifierName = cm.getIdentifierPropertyName();
	T bean = updater.getBean();
	Object value;
	for (String propName : propNames) {
		if (propName.equals(identifierName)) {
			continue;
		}
		try {
			value = MyBeanUtils.getSimpleProperty(bean, propName);
			if (!updater.isUpdate(propName, value)) {
				continue;
			}
			cm.setPropertyValue(po, propName, value, POJO);
		} catch (Exception e) {
			throw new RuntimeException(
					"copy property to persistent object failed: '"
							+ propName + "'", e);
		}
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:30,代码来源:HibernateBaseDao.java


注:本文中的org.hibernate.metadata.ClassMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。