类org.hibernate.mapping.Formula源码实例Demo

下面列出了怎么用org.hibernate.mapping.Formula的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: Ejb3Column.java
public void bind() {
	if ( StringHelper.isNotEmpty( formulaString ) ) {
		LOG.debugf( "Binding formula %s", formulaString );
		formula = new Formula();
		formula.setFormula( formulaString );
	}
	else {
		initMappingColumn(
				logicalColumnName, propertyName, length, precision, scale, nullable, sqlType, unique, true
		);
		if ( defaultValue != null ) {
			mappingColumn.setDefaultValue( defaultValue );
		}
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf( "Binding column: %s", toString() );
		}
	}
}
 
源代码2 项目: lams   文件: Ejb3Column.java
public static Ejb3Column[] buildColumnFromAnnotation(
		javax.persistence.Column[] anns,
		org.hibernate.annotations.Formula formulaAnn,
		Nullability nullability,
		PropertyHolder propertyHolder,
		PropertyData inferredData,
		Map<String, Join> secondaryTables,
		MetadataBuildingContext context) {
	return buildColumnFromAnnotation(
			anns,
			formulaAnn,
			nullability,
			propertyHolder,
			inferredData,
			null,
			secondaryTables,
			context
	);
}
 
源代码3 项目: lams   文件: RelationalObjectBinder.java
public void bindColumnsAndFormulas(
		MappingDocument sourceDocument,
		List<RelationalValueSource> relationalValueSources,
		SimpleValue simpleValue,
		boolean areColumnsNullableByDefault,
		ColumnNamingDelegate columnNamingDelegate) {
	for ( RelationalValueSource relationalValueSource : relationalValueSources ) {
		if ( ColumnSource.class.isInstance( relationalValueSource ) ) {
			final ColumnSource columnSource = (ColumnSource) relationalValueSource;
			bindColumn(
					sourceDocument,
					columnSource,
					simpleValue,
					areColumnsNullableByDefault,
					columnNamingDelegate
			);
		}
		else {
			final DerivedValueSource formulaSource = (DerivedValueSource) relationalValueSource;
			simpleValue.addFormula( new Formula( formulaSource.getExpression() ) );
		}
	}
}
 
源代码4 项目: 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 ) );
	}
}
 
源代码5 项目: lams   文件: Ejb3Column.java
protected void initMappingColumn(
		String columnName,
		String propertyName,
		int length,
		int precision,
		int scale,
		boolean nullable,
		String sqlType,
		boolean unique,
		boolean applyNamingStrategy) {
	if ( StringHelper.isNotEmpty( formulaString ) ) {
		this.formula = new Formula();
		this.formula.setFormula( formulaString );
	}
	else {
		this.mappingColumn = new Column();
		redefineColumnName( columnName, propertyName, applyNamingStrategy );
		this.mappingColumn.setLength( length );
		if ( precision > 0 ) {  //revelent precision
			this.mappingColumn.setPrecision( precision );
			this.mappingColumn.setScale( scale );
		}
		this.mappingColumn.setNullable( nullable );
		this.mappingColumn.setSqlType( sqlType );
		this.mappingColumn.setUnique( unique );

		if(writeExpression != null && !writeExpression.matches("[^?]*\\?[^?]*")) {
			throw new AnnotationException(
					"@WriteExpression must contain exactly one value placeholder ('?') character: property ["
							+ propertyName + "] and column [" + logicalColumnName + "]"
			);
		}
		if ( readExpression != null) {
			this.mappingColumn.setCustomRead( readExpression );
		}
		if ( writeExpression != null) {
			this.mappingColumn.setCustomWrite( writeExpression );
		}
	}
}
 
源代码6 项目: lams   文件: RelationalObjectBinder.java
public void bindFormulas(
		MappingDocument sourceDocument,
		List<DerivedValueSource> formulaSources,
		OneToOne oneToOneBinding) {
	for ( DerivedValueSource formulaSource : formulaSources ) {
		oneToOneBinding.addFormula( new Formula( formulaSource.getExpression() ) );
	}
}
 
源代码7 项目: cacheonix-core   文件: HbmBinder.java
private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path,
		boolean isNullable, Mappings mappings) {
	Attribute formulaNode = node.attribute( "formula" );
	if ( formulaNode != null ) {
		Formula f = new Formula();
		f.setFormula( formulaNode.getText() );
		simpleValue.addFormula( f );
	}
	else {
		bindColumns( node, simpleValue, isNullable, true, path, mappings );
	}
}
 
源代码8 项目: cacheonix-core   文件: CompositeElementTest.java
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
	super.afterConfigurationBuilt( mappings, dialect );
	Collection children = mappings.getCollection( Parent.class.getName() + ".children" );
	Component childComponents = ( Component ) children.getElement();
	Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next();

	SQLFunction lengthFunction = ( SQLFunction ) dialect.getFunctions().get( "length" );
	if ( lengthFunction != null ) {
		ArrayList args = new ArrayList();
		args.add( "bio" );
		f.setFormula( lengthFunction.render( args, null ) );
	}
}
 
源代码9 项目: unitime   文件: HibernateUtil.java
public static void fixSchemaInFormulas(Configuration cfg) throws ClassNotFoundException {
	cfg.buildMappings();
	Class dialect = Class.forName(cfg.getProperty("dialect"));
	String schema = cfg.getProperty("default_schema");
	for (Iterator i=cfg.getClassMappings();i.hasNext();) {
        PersistentClass pc = (PersistentClass)i.next();
        for (Iterator j=pc.getPropertyIterator();j.hasNext();) {
            Property p = (Property)j.next();
            for (Iterator k=p.getColumnIterator();k.hasNext();) {
                Selectable c = (Selectable)k.next();
                if (c instanceof Formula) {
                    Formula f = (Formula)c;
                    boolean updated = false;
                    if (schema != null && f.getFormula() != null && f.getFormula().indexOf("%SCHEMA%")>=0) {
                        f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema));
                        sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula());
                    }
                    if (f.getFormula()!=null && (f.getFormula().indexOf("%TRUE%")>=0 || f.getFormula().indexOf("%FALSE%")>=0)) {
                    	if (isPostgress(dialect)) {
                    		f.setFormula(f.getFormula().replaceAll("%TRUE%", "'t'").replaceAll("%FALSE%", "'f'"));
                    	} else {
                    		f.setFormula(f.getFormula().replaceAll("%TRUE%", "1").replaceAll("%FALSE%", "0"));
                    	}
                    }
                    if (updated)
                    	sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula());
                }
            }
        }
    }
}
 
 类所在包
 类方法
 同包方法