⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapbinder.java

📁 hibernate3.2.6源码和jar包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					}					else {						throw new AssertionFailure( "Unable to guess collection property accessor name" );					}					//boolean propertyAccess = embeddable == null || AccessType.PROPERTY.equals( embeddable.access() );					//FIXME "index" is it right?					PropertyData inferredData = new PropertyPreloadedData( "property", "index", elementClass );					//TODO be smart with isNullable					Component component = AnnotationBinder.fillComponent(							holder, inferredData, isPropertyAnnotated, isPropertyAnnotated ? "property" : "field", true,							entityBinder, false, false,							true, mappings					);					mapValue.setIndex( component );				}				else {					SimpleValueBinder elementBinder = new SimpleValueBinder();					elementBinder.setMappings( mappings );					elementBinder.setReturnedClassName( mapKeyType );					Ejb3Column[] elementColumns = mapKeyColumns;					if ( elementColumns == null || elementColumns.length == 0 ) {						elementColumns = new Ejb3Column[1];						Ejb3Column column = new Ejb3Column();						column.setImplicit( false );						column.setNullable( true );						column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );						column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME );						//TODO create an EMPTY_JOINS collection						column.setJoins( new HashMap<String, Join>() );						column.setMappings( mappings );						column.bind();						elementColumns[0] = column;					}					//override the table					for (Ejb3Column column : elementColumns) {						column.setTable( mapValue.getCollectionTable() );					}					elementBinder.setColumns( elementColumns );					//do not call setType as it extract the type from @Type					//the algorithm generally does not apply for map key anyway					MapKey mapKeyAnn = property.getAnnotation( org.hibernate.annotations.MapKey.class );					if (mapKeyAnn != null && ! BinderHelper.isDefault( mapKeyAnn.type().type() ) ) {						elementBinder.setExplicitType( mapKeyAnn.type() );					}					mapValue.setIndex( elementBinder.make() );				}			}			//FIXME pass the Index Entity JoinColumns			if ( !collection.isOneToMany() ) {				//index column shoud not be null				for (Ejb3JoinColumn col : mapKeyManyToManyColumns) {					col.forceNotNull();				}			}			if ( isIndexOfEntities ) {				bindManytoManyInverseFk(						collectionEntity,						mapKeyManyToManyColumns,						element,						false, //a map key column has no unique constraint						mappings				);			}		}	}	protected Value createFormulatedValue(			Value value, Collection collection, String targetPropertyName, PersistentClass associatedClass	) {		Value element = collection.getElement();		String fromAndWhere = null;		if ( !( element instanceof OneToMany ) ) {			String referencedPropertyName = null;			if ( element instanceof ToOne ) {				referencedPropertyName = ( (ToOne) element ).getReferencedPropertyName();			}			else if ( element instanceof DependantValue ) {				//TODO this never happen I think				if ( propertyName != null ) {					referencedPropertyName = collection.getReferencedPropertyName();				}				else {					throw new AnnotationException( "SecondaryTable JoinColumn cannot reference a non primary key" );				}			}			Iterator referencedEntityColumns;			if ( referencedPropertyName == null ) {				referencedEntityColumns = associatedClass.getIdentifier().getColumnIterator();			}			else {				Property referencedProperty = associatedClass.getRecursiveProperty( referencedPropertyName );				referencedEntityColumns = referencedProperty.getColumnIterator();			}			String alias = "$alias$";			StringBuilder fromAndWhereSb = new StringBuilder( " from " )					.append( associatedClass.getTable().getName() )							//.append(" as ") //Oracle doesn't support it in subqueries					.append( " " )					.append( alias ).append( " where " );			Iterator collectionTableColumns = element.getColumnIterator();			while ( collectionTableColumns.hasNext() ) {				Column colColumn = (Column) collectionTableColumns.next();				Column refColumn = (Column) referencedEntityColumns.next();				fromAndWhereSb.append( alias ).append( '.' ).append( refColumn.getQuotedName() )						.append( '=' ).append( colColumn.getQuotedName() ).append( " and " );			}			fromAndWhere = fromAndWhereSb.substring( 0, fromAndWhereSb.length() - 5 );		}		if ( value instanceof Component ) {			Component component = (Component) value;			Iterator properties = component.getPropertyIterator();			Component indexComponent = new Component( collection );			indexComponent.setComponentClassName( component.getComponentClassName() );			//TODO I don't know if this is appropriate			indexComponent.setNodeName( "index" );			while ( properties.hasNext() ) {				Property current = (Property) properties.next();				Property newProperty = new Property();				newProperty.setCascade( current.getCascade() );				newProperty.setGeneration( current.getGeneration() );				newProperty.setInsertable( false );				newProperty.setUpdateable( false );				newProperty.setMetaAttributes( current.getMetaAttributes() );				newProperty.setName( current.getName() );				newProperty.setNodeName( current.getNodeName() );				newProperty.setNaturalIdentifier( false );				//newProperty.setOptimisticLocked( false );				newProperty.setOptional( false );				newProperty.setPersistentClass( current.getPersistentClass() );				newProperty.setPropertyAccessorName( current.getPropertyAccessorName() );				newProperty.setSelectable( current.isSelectable() );				newProperty.setValue( createFormulatedValue( current.getValue(), collection, targetPropertyName,						associatedClass				) );				indexComponent.addProperty( newProperty );			}			return indexComponent;		}		else if ( value instanceof SimpleValue ) {			SimpleValue sourceValue = (SimpleValue) value;			SimpleValue targetValue;			if ( value instanceof ManyToOne ) {				ManyToOne sourceManyToOne = (ManyToOne) sourceValue;				ManyToOne targetManyToOne = new ManyToOne( collection.getCollectionTable() );				targetManyToOne.setFetchMode( FetchMode.DEFAULT );				targetManyToOne.setLazy( true );				//targetValue.setIgnoreNotFound( ); does not make sense for a map key				targetManyToOne.setReferencedEntityName( sourceManyToOne.getReferencedEntityName() );				targetValue = targetManyToOne;			}			else {				targetValue = new SimpleValue( collection.getCollectionTable() );				targetValue.setTypeName( sourceValue.getTypeName() );				targetValue.setTypeParameters( sourceValue.getTypeParameters() );			}			Iterator columns = sourceValue.getColumnIterator();			Random random = new Random();			while ( columns.hasNext() ) {				Object current = columns.next();				Formula formula = new Formula();				String formulaString;				if ( current instanceof Column ) {					formulaString = ( (Column) current ).getQuotedName();				}				else if ( current instanceof Formula ) {					formulaString = ( (Formula) current ).getFormula();				}				else {					throw new AssertionFailure( "Unknown element in column iterator: " + current.getClass() );				}				if ( fromAndWhere != null ) {					formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", new HSQLDialect() );					formulaString = "(select " + formulaString + fromAndWhere + ")";					formulaString = StringHelper.replace(							formulaString,							"$alias$",							"a" + random.nextInt( 16 )					);				}				formula.setFormula( formulaString );				targetValue.addFormula( formula );			}			return targetValue;		}		else {			throw new AssertionFailure( "Unknown type encounters for map key: " + value.getClass() );		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -