org.hibernate.mapping.PersistentClass#getProperty ( )源码实例Demo

下面列出了org.hibernate.mapping.PersistentClass#getProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void doSecondPass(Map persistentClasses) throws MappingException {
	org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile(
			fetchProfileName
	);
	if ( profile != null ) {
		if ( profile.getSource() != MetadataSource.ANNOTATIONS ) {
			return;
		}
	}
	else {
		profile = new org.hibernate.mapping.FetchProfile( fetchProfileName, MetadataSource.ANNOTATIONS );
		buildingContext.getMetadataCollector().addFetchProfile( profile );
	}

	PersistentClass clazz = buildingContext.getMetadataCollector().getEntityBinding( fetch.entity().getName() );
	// throws MappingException in case the property does not exist
	clazz.getProperty( fetch.association() );

	profile.addFetch(
			fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase(Locale.ROOT)
	);
}
 
源代码2 项目: cacheonix-core   文件: ComponentTest.java
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
	super.afterConfigurationBuilt( mappings, dialect );
	// Oracle and Postgres do not have year() functions, so we need to
	// redefine the 'User.person.yob' formula
	//
	// consider temporary until we add the capability to define
	// mapping foprmulas which can use dialect-registered functions...
	PersistentClass user = mappings.getClass( User.class.getName() );
	org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
	Component component = ( Component ) personProperty.getValue();
	Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();

	SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
	if ( yearFunction == null ) {
		// the dialect not know to support a year() function, so rely on the
		// ANSI SQL extract function
		f.setFormula( "extract( year from dob )");
	}
	else {
		List args = new ArrayList();
		args.add( "dob" );
		f.setFormula( yearFunction.render( args, null ) );
	}
}
 
源代码3 项目: cacheonix-core   文件: NonReflectiveBinderTest.java
public void testComparator() {
	PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
	
	Property property = cm.getProperty("sortedEmployee");
	Collection col = (Collection) property.getValue();
	assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator");
}
 
源代码4 项目: mPaaS   文件: InterfaceMetadataContributor.java
/** 读取索引配置 */
private void readIndex(PersistentClass pclazz, Class<?> iface) {
	Table table = iface.getAnnotation(Table.class);
	if (table == null) {
		return;
	}
	org.hibernate.mapping.Table tb = pclazz.getTable();
	outloop: for (Index index : table.indexes()) {
		List<Identifier> columnNames = new ArrayList<>();
		org.hibernate.mapping.Index idx = new org.hibernate.mapping.Index();
		// columnList="fdId, fdName"
		String[] columns = index.columnList().split(",");
		for (String column : columns) {
			column = column.trim();
			int i = column.indexOf(' ');
			String order = null;
			if (i > -1) {
				order = column.substring(i).trim();
				column = column.substring(0, i);
			}
			Property property = pclazz.getProperty(column);
			org.hibernate.mapping.Column col = (org.hibernate.mapping.Column) property
					.getColumnIterator().next();
			if (col == null) {
				log.error(StringHelper.join(iface.getName(), "指定的索引列不存在:",
						column));
				continue outloop;
			}
			columnNames.add(Identifier.toIdentifier(column));
			idx.addColumn(col, order);
		}
		idx.setTable(tb);
		// 创建索引名称
		String name = index.name();
		if (StringUtils.isBlank(name)) {
			name = NamingHelper.INSTANCE.generateHashedConstraintName("IDX",
					idx.getTable().getNameIdentifier(), columnNames);
		}
		idx.setName(name);
		// 判断索引是否存在
		if (tb.getIndex(name) == null) {
			tb.addIndex(idx);
		}
	}
}