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

📄 binder.java

📁 人力资源管理系统主要包括:人员管理、招聘管理、培训管理、奖惩管理和薪金管理五大管理模块。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				if ( indexNode!=null && table!=null ) {					table.getIndex( indexNode.getValue() ).addColumn(col);				}				Attribute uniqueNode = columnElement.attribute("unique-key");				if ( uniqueNode!=null && table!=null ) {					table.getUniqueKey( uniqueNode.getValue() ).addColumn(col);				}			}		}		else {			Column col = new Column( model.getType(), 0 );			bindColumn(node, col, isNullable);			col.setName( mappings.getNamingStrategy().columnName( columnAttribute.getValue() ) );			Table table = model.getTable();			if (table!=null) table.addColumn(col); //table=null -> an association - fill it in later			model.addColumn(col);		}		if ( autoColumn && model.getColumnSpan()==0 ) {			Column col = new Column( model.getType(), 0 );			bindColumn(node, col, isNullable);			col.setName( mappings.getNamingStrategy().propertyToColumnName(propertyPath) );			model.getTable().addColumn(col);			model.addColumn(col);		}	}	//automatically makes a column with the default name if none is specifed by XML	public static void bindSimpleValue(Element node, SimpleValue model, boolean isNullable, String path, Mappings mappings) 	throws MappingException {		model.setType( getTypeFromXML(node) );		Attribute formulaNode = node.attribute("formula");		if (formulaNode!=null) {			Formula f = new Formula();			f.setFormula( formulaNode.getText() );			model.setFormula(f);		}		else {			bindColumns(node, model, isNullable, true, path, mappings);		}		Attribute fkNode = node.attribute("foreign-key");		if (fkNode!=null) model.setForeignKeyName( fkNode.getValue() );	}	public static void bindProperty(Element node, Property model, Mappings mappings) throws MappingException {		model.setName( node.attributeValue("name") );		Type type = model.getValue().getType();		if (type==null) throw new MappingException(			"Could not determine a property type for: " + model.getName()		);		Attribute accessNode = node.attribute("access");		if (accessNode!=null) {			model.setPropertyAccessorName( accessNode.getValue() );		} 		else {			model.setPropertyAccessorName( mappings.getDefaultAccess() );		}		Attribute cascadeNode = node.attribute("cascade");		model.setCascade( (cascadeNode==null) ?			mappings.getDefaultCascade() :			cascadeNode.getValue()		);		Attribute updateNode = node.attribute("update");		model.setUpdateable( (updateNode==null) ?			true :			"true".equals( updateNode.getValue() )		);		Attribute insertNode = node.attribute("insert");		model.setInsertable( (insertNode==null) ?			true :			"true".equals( insertNode.getValue() )		);				if ( log.isDebugEnabled() ) {			String msg = "Mapped property: " + model.getName();			String columns = columns( model.getValue() );			if ( columns.length() > 0  ) msg += " -> " + columns;			if ( model.getType()!=null ) msg += ", type: " + model.getType().getName();			log.debug(msg);		}				model.setMetaAttributes( getMetas(node) );	}	private static String columns(Value val) {		StringBuffer columns = new StringBuffer();		Iterator iter = val.getColumnIterator();		while ( iter.hasNext() ) {			columns.append( ( (Column) iter.next() ).getName() );			if ( iter.hasNext() ) columns.append(", ");		}		return columns.toString();	}	/**	 * Called for all collections	 */	public static void bindCollection(Element node, Collection model, String className, String path, Mappings mappings) throws MappingException {		//ROLENAME		model.setRole( StringHelper.qualify(className, path) );		Attribute inverseNode = node.attribute("inverse");		if ( inverseNode!=null) model.setInverse( StringHelper.booleanValue( inverseNode.getValue() ) );		Attribute orderNode = node.attribute("order-by");		if ( orderNode!=null) {			if ( Environment.jvmSupportsLinkedHashCollections() || ( model instanceof Bag ) ) {				model.setOrderBy( orderNode.getValue() );			}			else {				log.warn("Attribute \"order-by\" ignored in JDK1.3 or less");			}		}		Attribute whereNode = node.attribute("where");		if (whereNode!=null) {			model.setWhere( whereNode.getValue() );		}		Attribute batchNode = node.attribute("batch-size");		if (batchNode!=null) {			model.setBatchSize( Integer.parseInt( batchNode.getValue() ) );		}		//PERSISTER		Attribute persisterNode = node.attribute("persister");		if (persisterNode==null) {			//persister = CollectionPersisterImpl.class;		} 		else {			try {				model.setCollectionPersisterClass( ReflectHelper.classForName( persisterNode.getValue() ) );			}			catch (ClassNotFoundException cnfe) {				throw new MappingException( "Could not find collection persister class: " + persisterNode.getValue() );			}		}		initOuterJoinFetchSetting(node, model);		Element oneToManyNode = node.element("one-to-many");		if (oneToManyNode!=null) {			OneToMany oneToMany = new OneToMany( model.getOwner() );			model.setElement(oneToMany);			bindOneToMany(oneToManyNode, oneToMany, mappings);			//we have to set up the table later!! yuck		}		else {			//TABLE			Attribute tableNode = node.attribute("table");			String tableName;			if (tableNode!=null) {				tableName = mappings.getNamingStrategy()					.tableName( tableNode.getValue() );			}			else {				tableName = mappings.getNamingStrategy()					.propertyToTableName(className, path);			}			Attribute schemaNode = node.attribute("schema");			String schema = schemaNode==null ? mappings.getSchemaName() : schemaNode.getValue();			model.setCollectionTable( mappings.addTable(schema, tableName) );			log.info("Mapping collection: " + model.getRole() + " -> " + model.getCollectionTable().getName() );		}		//LAZINESS		Attribute lazyNode = node.attribute("lazy");		if (lazyNode!=null) {			model.setLazy( StringHelper.booleanValue( lazyNode.getValue() ) );		}		//SORT		Attribute sortedAtt = node.attribute("sort");		// unsorted, natural, comparator.class.name		if ( sortedAtt==null || sortedAtt.getValue().equals("unsorted") ) {			model.setSorted(false);		}		else {			model.setSorted(true);			String comparatorClassName = sortedAtt.getValue();			if ( !comparatorClassName.equals("natural") ) {				try {					model.setComparator( (Comparator) ReflectHelper.classForName(comparatorClassName).newInstance() );				}				catch (Exception e) {					throw new MappingException( "Could not instantiate comparator class: " + comparatorClassName );				}			}		}		//ORPHAN DELETE (used for programmer error detection)		Attribute cascadeAtt = node.attribute("cascade");		if ( cascadeAtt!=null && cascadeAtt.getValue().equals("all-delete-orphan") ) model.setOrphanDelete(true);		//set up second pass		if (model instanceof List) {			mappings.addSecondPass( new ListSecondPass(node, mappings, (List) model) );		}		else if (model instanceof Map) {			mappings.addSecondPass( new MapSecondPass(node, mappings, (Map) model) );		}		else if (model instanceof IdentifierCollection) {			mappings.addSecondPass( new IdentifierCollectionSecondPass(node, mappings, (IdentifierCollection) model) );		}		else {			mappings.addSecondPass( new CollectionSecondPass(node, mappings, model) );		}	}	public static void bindManyToOne(Element node, ManyToOne model, String path, boolean isNullable, Mappings mappings) 	throws MappingException {		bindColumns(node, model, isNullable, true, path, mappings);		initOuterJoinFetchSetting(node, model);		Attribute ukName = node.attribute("property-ref");		if (ukName!=null) model.setReferencedPropertyName( ukName.getValue() );		Attribute classNode = node.attribute("class");		if (classNode!=null) {			try {				model.setType( TypeFactory.manyToOne( 					ReflectHelper.classForName( getClassName(classNode, mappings) ), 					model.getReferencedPropertyName()				) );			}			catch (Exception e) {				throw new MappingException( "Could not find class: " + classNode.getValue() );			}		}		Attribute fkNode = node.attribute("foreign-key");		if (fkNode!=null) model.setForeignKeyName( node.attributeValue("foreign-key") );	}	public static void bindAny(Element node, Any model, boolean isNullable, Mappings mappings) throws MappingException {		model.setIdentifierType( getTypeFromXML(node) );		Attribute metaAttribute = node.attribute("meta-type");		if (metaAttribute!=null) {			Type metaType = TypeFactory.heuristicType( metaAttribute.getValue() );			if ( metaType==null ) throw new MappingException("could not interpret meta-type");			model.setMetaType(metaType);						Iterator iter = node.elementIterator("meta-value");			HashMap values = new HashMap();			while ( iter.hasNext() ) {				Element metaValue = (Element) iter.next();				try {					Object value = ( (DiscriminatorType) model.getMetaType() ).fromString( metaValue.attributeValue("value") );					Class clazz = ReflectHelper.classForName( getClassName( metaValue.attribute("class"), mappings ) );					values.put(value, clazz);				}				catch (ClassCastException cce) {					throw new MappingException( "meta-type was not a DiscriminatorType: " + metaType.getName() );				}				catch (HibernateException he) {					throw new MappingException("could not interpret meta-value", he);				}				catch (ClassNotFoundException cnfe) {					throw new MappingException("meta-value class not found", cnfe);				}			}			if ( values.size()>0 ) model.setMetaType( new MetaType( values, model.getMetaType() ) );		}				bindColumns(node, model, isNullable, false, null, mappings);	}	public static void bindOneToOne(Element node, OneToOne model, boolean isNullable, Mappings mappings) throws MappingException {		//bindColumns(node, model, isNullable, false, null, mappings);		initOuterJoinFetchSetting(node, model);		Attribute constrNode = node.attribute("constrained");		boolean constrained = constrNode!=null && constrNode.getValue().equals("true");		model.setConstrained(constrained);		model.setForeignKeyType(			constrained ?			ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :			ForeignKeyDirection.FOREIGN_KEY_TO_PARENT		);		Attribute fkNode = node.attribute("foreign-key");		if (fkNode!=null) model.setForeignKeyName( fkNode.getValue() );				Attribute ukName = node.attribute("property-ref");		if (ukName!=null) model.setReferencedPropertyName( ukName.getValue() );				Attribute classNode = node.attribute("class");		if (classNode!=null) {			try {				model.setType( TypeFactory.oneToOne(					ReflectHelper.classForName( getClassName(classNode, mappings) ),					model.getForeignKeyType(),					model.getReferencedPropertyName()				) );			}			catch (Exception e) {				throw new MappingException( "Could not find class: " + classNode.getValue() );			}		}	}	public static void bindOneToMany(Element node, OneToMany model, Mappings mappings) throws MappingException {		try {			model.setType( (EntityType) Hibernate.entity(				ReflectHelper.classForName( getClassName( node.attribute("class"), mappings ) )			) );		}		catch (ClassNotFoundException cnfe) {			throw new MappingException("Associated class not found", cnfe);		}	}	public static void bindColumn(Element node, Column model, boolean isNullable) {		Attribute lengthNode = node.attribute("length");		if (lengthNode!=null) model.setLength( Integer.parseInt( lengthNode.getValue() ) );		Attribute nullNode = node.attribute("not-null");		model.setNullable( (nullNode!=null) ?			!StringHelper.booleanValue( nullNode.getValue() ) :			isNullable		);		Attribute unqNode = node.attribute("unique");		model.setUnique( unqNode!=null && StringHelper.booleanValue( unqNode.getValue() ) );		model.setCheckConstraint( node.attributeValue("check") );		//Attribute qtNode = node.attribute("quote");		//model.setQuoted( qtNode!=null && StringHelper.booleanValue( qtNode.getValue() ) );		Attribute typeNode = node.attribute("sql-type");		model.setSqlType( (typeNode==null) ? null : typeNode.getValue() );	}	/**	 * Called for arrays and primitive arrays	 */	public static void bindArray(Element node, Array model, String prefix, String path, Mappings mappings) throws MappingException {		bindCollection(node, model, prefix, path, mappings);		Attribute att = node.attribute("element-class");		if ( att!=null ) {			try {				model.setElementClass( ReflectHelper.classForName( getClassName(att, mappings) ) );			}			catch (ClassNotFoundException cnfe) {				throw new MappingException(cnfe);			}		}		else {			Iterator iter = node.elementIterator();			while ( iter.hasNext() ) {				Element subnode = (Element) iter.next();				String name = subnode.getName();				if ( "element".equals(name) ) {					Type type = getTypeFromXML(subnode);					model.setElementClass( model.isPrimitiveArray() ?						( (PrimitiveType) type ).getPrimitiveClass() :						type.getReturnedClass()					);				}				else if (					"one-to-many".equals(name) ||					"many-to-many".equals(name) ||					"composite-element".equals(name)				) {					try {						model.setElementClass(							ReflectHelper.classForName( getClassName( subnode.attribute("class"), mappings ) )						);					}

⌨️ 快捷键说明

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