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

项目: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() );
        }
    }
}
项目:unitimes    文件:HibernateUtil.java   
public static void fixSchemaInFormulas(Configuration cfg) {
    cfg.buildMappings();
    String schema = cfg.getProperty("default_schema"); 
    if (schema!=null) {
        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;
                        if (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());
                        }
                    }
                }
            }
        }
    }
}
项目: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 ) );
    }
}
项目:unitime    文件:HibernateUtil.java   
public static void fixSchemaInFormulas(Configuration cfg) {
    cfg.buildMappings();
    String schema = cfg.getProperty("default_schema"); 
    if (schema!=null) {
        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;
                        if (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());
                        }
                    }
                }
            }
        }
    }
}
项目:lams    文件: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 );
    }
}
项目: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 );
        }
    }
}
项目: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,
        Mappings mappings){
    return buildColumnFromAnnotation(
            anns, formulaAnn, nullability, propertyHolder, inferredData, null, secondaryTables, mappings
    );
}
项目: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 );
    }
}
项目: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 ) );
    }
}
项目:hibernate-semantic-query    文件:EntityHierarchyImpl.java   
private static List<Column> resolveColumns(
            Table table,
            Value value,
            PersisterCreationContext creationContext) {
        final String[] columnNames = new String[value.getColumnSpan()];
        final String[] formulas = value.hasFormula() ? new String[value.getColumnSpan()] : null;
        //final SqlTypeDescriptor[] sqlTypeDescriptors = new SqlTypeDescriptor[value.getColumnSpan()];
        final int[] jdbcTypeCodes = new int[value.getColumnSpan()];

        final Iterator<Selectable> itr = value.getColumnIterator();
        int i = 0;
        while ( itr.hasNext() ) {
            final Selectable selectable = itr.next();
            if ( selectable instanceof org.hibernate.mapping.Column ) {
//              columnNames[i] = ( (org.hibernate.mapping.Column) selectable ).getQuotedName(
//                      creationContext.getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect()
//              );
                columnNames[i] = '`' + ( (org.hibernate.mapping.Column) selectable ).getName() + '`';
            }
            else {
                if ( formulas == null ) {
                    throw new HibernateException(
                            "Value indicated it does not have formulas, but a formula was encountered : " + selectable );
                }
                formulas[i] = ( (Formula) selectable ).getFormula();
            }

            // todo : need access to the TypeConfiguration...
            //sqlTypeDescriptors[i] = creationContext.getSessionFactory()
            jdbcTypeCodes[i] = value.getType().sqlTypes( null )[i];

            // todo : keep track of readers/writers... how exactly?
            // something like this vv ?
            //      Column#applyReadExpression( col.getReadExpr( dialect ) )
            //      Column#applyWriteExpression( col.getWriteExpr() )

            i++;
        }

        // makeColumns(
        //      creationContext,
        //      tableSelector,
        //      columnNames,
        //      formulas,
        //      sqlTypeDescriptors (or just JDBC type codes?)
        // )
        return PersisterHelper.makeValues(
                creationContext,
                // todo : a Table "selector"...
                table,
                columnNames,
                formulas,
                jdbcTypeCodes
        );
    }