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

项目: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());
                        }
                    }
                }
            }
        }
    }
}
项目: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    文件:TypeSafeActivator.java   
private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) {
    boolean hasNotNull = false;
    if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) {
        // single table inheritance should not be forced to null due to shared state
        if ( !( property.getPersistentClass() instanceof SingleTableSubclass ) ) {
            //composite should not add not-null on all columns
            if ( !property.isComposite() ) {
                final Iterator<Selectable> iter = property.getColumnIterator();
                while ( iter.hasNext() ) {
                    final Selectable selectable = iter.next();
                    if ( Column.class.isInstance( selectable ) ) {
                        Column.class.cast( selectable ).setNullable( false );
                    }
                    else {
                        LOG.debugf(
                                "@NotNull was applied to attribute [%s] which is defined (at least partially) " +
                                        "by formula(s); formula portions will be skipped",
                                property.getName()
                        );
                    }
                }
            }
        }
        hasNotNull = true;
    }
    return hasNotNull;
}
项目:lams    文件:AbstractEntityPersister.java   
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
    while ( propertyIterator.hasNext() ) {

        Property prop = ( Property ) propertyIterator.next();
        String propname = path == null ? prop.getName() : path + "." + prop.getName();
        if ( prop.isComposite() ) {
            Component component = ( Component ) prop.getValue();
            Iterator compProps = component.getPropertyIterator();
            internalInitSubclassPropertyAliasesMap( propname, compProps );
        }
        else {
            String[] aliases = new String[prop.getColumnSpan()];
            String[] cols = new String[prop.getColumnSpan()];
            Iterator colIter = prop.getColumnIterator();
            int l = 0;
            while ( colIter.hasNext() ) {
                Selectable thing = ( Selectable ) colIter.next();
                aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
                cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
                l++;
            }

            subclassPropertyAliases.put( propname, aliases );
            subclassPropertyColumnNames.put( propname, cols );
        }
    }

}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
    while ( propertyIterator.hasNext() ) {

        Property prop = ( Property ) propertyIterator.next();
        String propname = path == null ? prop.getName() : path + "." + prop.getName();
        if ( prop.isComposite() ) {
            Component component = ( Component ) prop.getValue();
            Iterator compProps = component.getPropertyIterator();
            internalInitSubclassPropertyAliasesMap( propname, compProps );
        }
        else {
            String[] aliases = new String[prop.getColumnSpan()];
            String[] cols = new String[prop.getColumnSpan()];
            Iterator colIter = prop.getColumnIterator();
            int l = 0;
            while ( colIter.hasNext() ) {
                Selectable thing = ( Selectable ) colIter.next();
                aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
                cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
                l++;
            }

            subclassPropertyAliases.put( propname, aliases );
            subclassPropertyColumnNames.put( propname, cols );
        }
    }

}
项目: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
        );
    }
项目:CAM    文件:HibernateEntityTableMappingImpl.java   
public HibernateEntityTableMappingImpl(Configuration configuration) {
    if(configuration==null){
        throw new IllegalArgumentException("Null hibernate configuration");
    }
    LOG.debug("Found hibernate configuration.");

    this.configuration = configuration;
    HibernateHelper.registerConfiguration(configuration);

    //init entityTableMap
    Iterator<PersistentClass> it = configuration.getClassMappings();
    while(it.hasNext()){
        PersistentClass pClass = it.next();

        EntityMapping entityMapping = new EntityMapping();
        entityMapping.setName(pClass.getEntityName());

        Iterator<Property> iterator = pClass.getPropertyIterator();
        while(iterator.hasNext()){
            Property p = iterator.next();
            Getter getter = p.getGetter(pClass.getMappedClass());
            Member member = getter.getMember();
            //ignore the collection field
            if(Collection.class.isAssignableFrom(getter.getReturnType())){
                LOG.trace("ignore collection member :{}",member);
                continue;
            }

            Iterator<Selectable> colIt = p.getColumnIterator();
            Selectable selectable = colIt.next();
            if(selectable instanceof Column){
                Column col = (Column)selectable;
                String fieldName = ObjectUtils.getterField(member.getName());
                entityMapping.getFieldColumnMap().put(fieldName, col.getName());

                EntityField entityField = new EntityField(fieldName,getter.getReturnType().getName());
                entityMapping.getFieldMap().put(fieldName,entityField);
            }
        }
        entityTableMap.put(entityMapping.getName(), pClass.getTable().getName());
        entityMappingMap.put(entityMapping.getName(),entityMapping);

    }

    LOG.debug("{} entities detected",entityMappingMap.size());
}