1 2 22 23 package org.webdocwf.util.loader.generator; 24 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 import org.webdocwf.util.loader.LoaderException; 28 import org.webdocwf.util.loader.logging.Logger; 29 import org.webdocwf.util.loader.logging.StandardLogger; 30 31 36 public class GenerateDoml { 37 38 private Document documentDoml; 39 private String referenceTableName=null; 40 private String javaType=null; 41 private String tableNameToCase=null; 42 private String referenceTableNameToCase=null; 43 private Logger logger; 44 45 59 60 public GenerateDoml(Document documentDoml, Element rootDoml, Element childRoot1, Element childRoot2, 61 String tableName, ImportDefinitionAttributes importDefinitionAttributes, 62 RelationshipsAttributes relationshipsAttributes, 63 InputParameters generatorParameters) throws LoaderException { 64 65 setLogger(); 66 this.logger.write("full", "GenerateDoml is started."); 67 try{ 69 boolean notUsingOid=true; 70 if(importDefinitionAttributes.getTagSourceColumnName().length!=0){ 71 for(int i=0;i<importDefinitionAttributes.getTagSourceColumnName().length;i++){ 72 if(importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid")){ 73 notUsingOid=false; 74 break; 75 } 76 } 77 } 78 79 Element childRoot3 = (Element )documentDoml.createElement("table"); 81 childRoot2.appendChild(childRoot3); 82 tableNameToCase=tableName.toUpperCase().substring(0,1)+tableName.toLowerCase().substring(1); 83 childRoot3.setAttribute("id", generatorParameters.getPackageName()+"."+tableNameToCase); 84 childRoot3.setAttribute("dbTableName", tableName); 85 93 if(importDefinitionAttributes.getTagSourceColumnName().length!=0){ 95 for(int i=0; i<importDefinitionAttributes.getTagSourceColumnName().length; i++){ 96 boolean fk=false; 98 if(relationshipsAttributes.getForeignVariables().length!=0 && 99 relationshipsAttributes!=null){ 100 for(int j=0;j<relationshipsAttributes.getForeignVariables().length;j=j+5){ 101 if(relationshipsAttributes.getForeignVariables()[j+2].equalsIgnoreCase( 102 importDefinitionAttributes.getTagSourceColumnName()[i])){ 103 fk=true; 104 referenceTableName=relationshipsAttributes.getForeignVariables()[j+3]; 105 referenceTableNameToCase=referenceTableName.toUpperCase().substring(0,1)+ 106 referenceTableName.toLowerCase().substring(1); 107 break; 108 } 109 } 110 } 111 boolean pk=false; 113 if(relationshipsAttributes.getPrimaryKeys().length!=0 && 114 relationshipsAttributes!=null){ 115 for(int k=0;k<relationshipsAttributes.getPrimaryKeys().length;k=k+2){ 116 if(importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase( 117 relationshipsAttributes.getPrimaryKeys()[k+1])){ 118 pk=true; 119 break; 120 } 121 } 122 } 123 if(!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid")&& 124 !importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("version")){ 125 Element childRoot4 = (Element )documentDoml.createElement("column"); 126 childRoot3.appendChild(childRoot4); 127 childRoot4.setAttribute("id", importDefinitionAttributes.getTagSourceColumnName()[i]); 128 childRoot4.setAttribute("usedForQuery", "true"); 129 if(pk){ 130 childRoot4.setAttribute("isPrimaryKey", "true"); 131 } 132 133 if(fk){ 135 Element childRoot5 = (Element )documentDoml.createElement("referenceObject"); 136 childRoot4.appendChild(childRoot5); 137 childRoot5.setAttribute("constraint", "true"); 138 childRoot5.setAttribute("reference", generatorParameters.getPackageName()+"."+ 139 referenceTableNameToCase); 140 141 Element childRoot6 = (Element )documentDoml.createElement("type"); 142 childRoot4.appendChild(childRoot6); 143 if(importDefinitionAttributes.getTagAllowNulls()[i].equalsIgnoreCase("NOT NULL")){ 144 childRoot6.setAttribute("canBeNull", "false"); 145 }else{ 146 childRoot6.setAttribute("canBeNull", "true"); 147 } 148 childRoot6.setAttribute("dbType", "none"); 150 MappingJavaType mappingJavaType=new MappingJavaType( generatorParameters, 151 importDefinitionAttributes.getTagColumnType()[i]); 152 javaType=mappingJavaType.getJavaType(); 153 childRoot6.setAttribute("javaType", generatorParameters.getPackageName()+"."+ 155 referenceTableNameToCase+"DO"); 156 childRoot6.setAttribute("size", importDefinitionAttributes.getTagColumnLenght()[i]); 157 }else{ 159 Element childRoot6 = (Element )documentDoml.createElement("type"); 160 childRoot4.appendChild(childRoot6); 161 if(importDefinitionAttributes.getTagAllowNulls()[i].equalsIgnoreCase("NOT NULL")){ 162 childRoot6.setAttribute("canBeNull", "false"); 163 }else{ 164 childRoot6.setAttribute("canBeNull", "true"); 165 } 166 childRoot6.setAttribute("dbType", importDefinitionAttributes.getTagColumnType()[i]); 167 MappingJavaType mappingJavaType1=new MappingJavaType( generatorParameters, 168 importDefinitionAttributes.getTagColumnType()[i]); 169 javaType=mappingJavaType1.getJavaType(); 170 childRoot6.setAttribute("javaType", javaType); 171 childRoot6.setAttribute("size", importDefinitionAttributes.getTagColumnLenght()[i]); 172 } 173 } 174 } 175 } 176 if(relationshipsAttributes.getIndexVariables().length!=0 && 177 relationshipsAttributes!=null){ 178 for(int i=0;i<relationshipsAttributes.getIndexVariables().length;i=i+3){ 179 Element childRoot7 = (Element )documentDoml.createElement("index"); 181 childRoot3.appendChild(childRoot7); 182 childRoot7.setAttribute("id",relationshipsAttributes.getIndexVariables()[i+1]); 183 if(relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("1")){ 184 childRoot7.setAttribute("unique","false"); 185 }else{ 186 childRoot7.setAttribute("unique","true"); 187 } 188 Element childRoot8 = (Element )documentDoml.createElement("indexColumn"); 189 childRoot7.appendChild(childRoot8); 190 childRoot8.setAttribute("id",relationshipsAttributes.getIndexVariables()[i+2]); 191 } 192 } 193 194 }catch (Exception e) { 195 String msg="Exception in class GenerateDoml: Error has occurred when trying to generate doml file!"; 196 LoaderException le=new LoaderException(msg+"\n"+e.getMessage(), (Throwable )e); 197 this.logger.write("full","Exception in class GenerateDoml: Error has occurred when trying to generate doml file!"+"\n"+le.getStackTraceAsString()); 198 throw le; 199 } 200 this.logger.write("full", "GenerateDoml is finished."); 201 } 202 203 207 private void setLogger() { 208 this.logger = StandardLogger.getCentralLogger(); 209 } 210 } | Popular Tags |