當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。