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

📄 classmapping.java

📁 Hibernate深入浅出
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         // add an import and field for this property         addImport(classType);          FieldProperty f = new FieldProperty(manyToOne, this, propertyName, classType, nullable && !key, key, false, metaForManyToOne);         addFieldProperty(f);      }          // collections      doCollections(classPackage, classElement, "list", "java.util.List", "java.util.ArrayList", getMetaAttribs());      doCollections(classPackage, classElement, "map", "java.util.Map", "java.util.HashMap", getMetaAttribs());      doCollections(classPackage, classElement, "set", "java.util.Set", "java.util.HashSet", getMetaAttribs());      doCollections(classPackage, classElement, "bag", System.getProperty("hbm2java.bag.interface","java.util.List"), "java.util.ArrayList", getMetaAttribs());      doCollections(classPackage, classElement, "idbag", System.getProperty("hbm2java.idbag.interface","java.util.List"), "java.util.ArrayList", getMetaAttribs());      doArrays(classElement, "array", getMetaAttribs());      doArrays(classElement, "primitive-array", getMetaAttribs());                      //components          for ( Iterator iter = classElement.getChildren("component").iterator(); iter.hasNext(); ) {         Element cmpe = (Element) iter.next();         MultiMap metaForComponent = MetaAttributeHelper.loadAndMergeMetaMap(cmpe, getMetaAttribs());         String cmpname = cmpe.getAttributeValue("name");         String cmpclass = cmpe.getAttributeValue("class");         if ( cmpclass==null || cmpclass.equals(StringHelper.EMPTY_STRING) ) {            log.warn("component \"" + cmpname + "\" in class " + getName() + " does not specify a class");            continue;         }         ClassMapping mapping = new ClassMapping(classPackage, cmpe, this, true, getMetaAttribs());                  ClassName classType = new ClassName(cmpclass);         // add an import and field for this property         addImport(classType);         FieldProperty ff =  new FieldProperty(cmpe, this, cmpname, classType, false, metaForComponent);         addFieldProperty(ff);         components.put( mapping.getFullyQualifiedName(), mapping );      }                    //    subclasses (done last so they can access this superclass for info)             for ( Iterator iter = classElement.getChildren("subclass").iterator(); iter.hasNext(); ) {            Element subclass = (Element) iter.next();            ClassMapping subclassMapping = new ClassMapping(classPackage, this, name, this,subclass, getMetaAttribs());            addSubClass(subclassMapping);         }             for ( Iterator iter = classElement.getChildren("joined-subclass").iterator(); iter.hasNext(); ) {            Element subclass = (Element) iter.next();            ClassMapping subclassMapping = new ClassMapping(classPackage, this, name, this, subclass, getMetaAttribs());			addSubClass(subclassMapping);         }                  validateMetaAttribs();}    private void addFieldProperty(FieldProperty fieldProperty) {        if(fieldProperty.getParentClass()==null) {            fields.add(fieldProperty);        } else {            throw new IllegalStateException("Field " + fieldProperty + " is already associated with a class: " + fieldProperty.getParentClass());        }            }      public void implementEquals() {      implementEquals(true);   }      public void implementEquals(boolean f) {   		mustImplementEquals = f;   }      public boolean mustImplementEquals() {      return (!isInterface()) && mustImplementEquals;   }      public List getFields() {      return fields;   }      public Set getImports() {      return imports;   }      /** shorthand method for getClassName().getFullyQualifiedName() */   public String getFullyQualifiedName() {      return getClassName().getFullyQualifiedName();   }      /** shorthand method for getClassName().getName() */   public String getName() {      return getClassName().getName();   }     /** shorthand method for getClassName().getPackageName() */      public String getPackageName() {        return getClassName().getPackageName();   }         public ClassName getClassName() {   	return name;	   }      public String getGeneratedName() {       return generatedName.getName();   }            public String getGeneratedPackageName() {     return generatedName.getPackageName();      }        public String getProxy() {      return proxyClass;   }      public List getSubclasses() {      return subclasses;   }      public String getSuperClass() {      return superClass;   }         // We need a minimal constructor only if it's different from   // the full constructor or the no-arg constructor.   // A minimal construtor is one that lets   // you specify only the required fields.   public boolean needsMinimalConstructor() {   	   	return (getAllFieldsForFullConstructor().size()!=getAllFieldsForMinimalConstructor().size()) &&			getAllFieldsForMinimalConstructor().size()>0;               }      public List getLocalFieldsForFullConstructor() {          List result = new ArrayList();            for(Iterator myFields = getFields().iterator(); myFields.hasNext();) {                 FieldProperty field = (FieldProperty) myFields.next();                 if(!field.isIdentifier() || (field.isIdentifier() && !field.isGenerated())) {                     result.add(field);                 }             }                        return result;      }          public List getFieldsForSupersFullConstructor() {          List result = new ArrayList();          if(getSuperClassMapping()!=null) {              // The correct sequence is vital here, as the subclass should be              // able to invoke the fullconstructor based on the sequence returned              // by this method!              result.addAll(getSuperClassMapping().getFieldsForSupersFullConstructor());              result.addAll(getSuperClassMapping().getLocalFieldsForFullConstructor());          }                 return result;      }            public List getLocalFieldsForMinimalConstructor() {    List result = new ArrayList();    for (Iterator myFields = getFields().iterator(); myFields.hasNext();) {        FieldProperty field = (FieldProperty) myFields.next();        if ((!field.isIdentifier() && !field.isNullable()) ||              (field.isIdentifier() && !field.isGenerated())) {            result.add(field);        }    }    return result;}	public List getAllFields() {		List result = new ArrayList();				if(getSuperClassMapping()!=null) {		 result.addAll(getSuperClassMapping().getAllFields());			} 		result.addAll(getFields());				return result;	}			public List getAllFieldsForFullConstructor() {              List result = getFieldsForSupersFullConstructor();       result.addAll(getLocalFieldsForFullConstructor());       return result;   }        public List getFieldsForSupersMinimalConstructor() {          List result = new ArrayList();          if(getSuperClassMapping()!=null) {              // The correct sequence is vital here, as the subclass should be              // able to invoke the fullconstructor based on the sequence returned              // by this method!              result.addAll(getSuperClassMapping().getFieldsForSupersMinimalConstructor());              result.addAll(getSuperClassMapping().getLocalFieldsForMinimalConstructor());          }                 return result;      }          public List getAllFieldsForMinimalConstructor() {                List result = getFieldsForSupersMinimalConstructor();         result.addAll(getLocalFieldsForMinimalConstructor());         return result;       }          public void addImport(ClassName className) {      // if the package is java.lang or our own package don't add      if ( !className.inJavaLang() && !className.inSamePackage(generatedName) && !className.isPrimitive()) {          if(className.isArray()) {            imports.add( className.getFullyQualifiedName().substring(0,className.getFullyQualifiedName().length()-2) ); // remove []          } else {              imports.add( className.getFullyQualifiedName() );          }      }   }      public void addImport(String className) {       ClassName cn = new ClassName(className);       addImport(cn);          }        public Map getComponents() {      return components;   }      private void doCollections(String classPackage, Element classElement, String xmlName, String interfaceClass, String implementingClass, MultiMap inheritedMeta) {         	String originalInterface = interfaceClass;   	String originalImplementation = implementingClass;            for (Iterator collections = classElement.getChildren(xmlName).iterator(); collections.hasNext();) {               Element collection = (Element) collections.next();         MultiMap metaForCollection = MetaAttributeHelper.loadAndMergeMetaMap(collection, inheritedMeta);         String propertyName = collection.getAttributeValue("name");         			//		Small hack to switch over to sortedSet/sortedMap if sort is specified. (that is sort != unsorted)			String sortValue = collection.getAttributeValue("sort");			if (sortValue!=null && !"unsorted".equals(sortValue) && !"".equals(sortValue.trim())) {				  if("map".equals(xmlName)) {					  interfaceClass = SortedMap.class.getName();					  implementingClass = TreeMap.class.getName();				  } else if("set".equals(xmlName)) {					  interfaceClass = SortedSet.class.getName();					  implementingClass = TreeSet.class.getName();				  }			   } else {			   		interfaceClass = originalInterface;			   		implementingClass = originalImplementation;			   }        		ClassName interfaceClassName = new ClassName(interfaceClass);		ClassName implementationClassName = new ClassName(implementingClass);      	                  // add an import and field for this collection         addImport(interfaceClassName);          // import implementingClassName should only be           // added if the initialisaiton code of the field           // is actually used - and currently it isn't!         //addImport(implementingClassName);                            ClassName foreignClass = null;

⌨️ 快捷键说明

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