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 37 public class WriteImportDefinition { 38 private Logger logger; 39 40 48 49 public WriteImportDefinition(Document document, Element root, ImportDefinitionAttributes importDefinitionAttributes, InputParameters generatorParameters) throws LoaderException { 50 setLogger(); 51 this.logger.write("full", "WriteImportDefinition is started."); 52 if (!generatorParameters.getFullMode()) { 53 54 Element childRoot1 = (Element ) document.createElement("copyTable"); 55 root.appendChild(childRoot1); 56 childRoot1.setAttribute("name", importDefinitionAttributes.getName()); 57 childRoot1.setAttribute("sourceTableName", importDefinitionAttributes.getName()); 58 childRoot1.setAttribute("targetTableName", importDefinitionAttributes.getName()); 59 childRoot1.setAttribute("objectIDIncrement", importDefinitionAttributes.getObjectIDIncrementid()); 61 childRoot1.setAttribute("oidLogic", "false"); 62 childRoot1.setAttribute("onErrorContinue", "false"); 63 64 } else { 65 Element childRoot1 = (Element ) document.createElement("importDefinition"); 66 root.appendChild(childRoot1); 67 childRoot1.setAttribute("name", importDefinitionAttributes.getName()); 68 childRoot1.setAttribute("tableName", importDefinitionAttributes.getTableName()); 69 72 Element childRoot2 = (Element ) document.createElement("valueColumns"); 73 childRoot1.appendChild(childRoot2); 74 75 for (int i = 0; i < importDefinitionAttributes.getTagSourceColumnName().length; i++) { 76 if (generatorParameters.getSourceType().equalsIgnoreCase("csv")) { 77 Element childRoot3 = (Element ) document.createElement("valueColumn"); 78 childRoot2.appendChild(childRoot3); 79 childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]); 80 childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]); 81 childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]); 82 childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]); 83 childRoot3.setAttribute("valueMode", generatorParameters.getValueMode()); 84 } else { 85 if (!generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) { 86 if (!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid") && !importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("version")) { 87 boolean fk = true; 88 for (int j = 0; j < RelationshipsAttributes.getForeignVariables().length; j = j + 5) { 89 if (RelationshipsAttributes.getForeignVariables()[j + 2].equalsIgnoreCase(importDefinitionAttributes.getTagSourceColumnName()[i])) { 90 fk = false; 91 break; 92 } 93 } 94 if (fk) { 95 Element childRoot3 = (Element ) document.createElement("valueColumn"); 96 childRoot2.appendChild(childRoot3); 97 childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]); 98 childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]); 99 childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]); 100 childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]); 101 childRoot3.setAttribute("valueMode", generatorParameters.getValueMode()); 102 103 } 104 } 105 } else { 106 if (!importDefinitionAttributes.getTagColumnType()[i].toLowerCase().endsWith("identity")) { 108 Element childRoot3 = (Element ) document.createElement("valueColumn"); 109 childRoot2.appendChild(childRoot3); 110 childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]); 111 childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]); 112 childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]); 113 childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]); 114 childRoot3.setAttribute("valueMode", generatorParameters.getValueMode()); 115 } 116 } 128 } 129 } 130 131 if (!generatorParameters.getSourceType().equalsIgnoreCase("csv")) { 132 int j = 0; 133 if (generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) { 134 } else { 136 if (RelationshipsAttributes.getForeignVariables().length != 0) { 138 Element childRoot100 = (Element ) document.createElement("relationColumns"); 139 childRoot1.appendChild(childRoot100); 140 for (int i = 0; i < RelationshipsAttributes.getForeignVariables().length; i = i + 5) { 141 Element childRoot101 = (Element ) document.createElement("relationColumn"); 142 childRoot100.appendChild(childRoot101); 143 childRoot101.setAttribute("relationSourceTableName", RelationshipsAttributes.getForeignVariables()[i + 3]); 144 childRoot101.setAttribute("relationTargetTableName", importDefinitionAttributes.getTableName()); 145 childRoot101.setAttribute("relationTargetColumnName", RelationshipsAttributes.getForeignVariables()[i + 2]); 146 147 if (i > 5 && RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(RelationshipsAttributes.getForeignVariables()[(i + 3) - 5])) { 148 j = j + 1; 149 } else { 150 j = 0; 151 } 152 childRoot101.setAttribute("relationSourceTableID", "" + j); 153 childRoot101.setAttribute("relationTargetTableID", "0"); 154 childRoot101.setAttribute("relationMode", generatorParameters.getValueMode()); 155 } 156 } 157 } 158 159 int k = 0; 160 int l = 0; 161 if (RelationshipsAttributes.getForeignVariables().length != 0) { 162 Element childRoot200 = (Element ) document.createElement("tables"); 163 childRoot1.appendChild(childRoot200); 164 for (int i = 0; i < RelationshipsAttributes.getForeignVariables().length; i = i + 5) { 165 TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode()); 166 if (l == 0) { 167 Element childRoot201 = (Element ) document.createElement("table"); 169 childRoot200.appendChild(childRoot201); 170 childRoot201.setAttribute("tableName", tableAttributes.getTableName()); 171 childRoot201.setAttribute("tableID", "" + k); 172 childRoot201.setAttribute("insert", tableAttributes.getInsert()); 173 childRoot201.setAttribute("tableMode", tableAttributes.getTableMode()); 174 childRoot201.setAttribute("oidLogic", tableAttributes.getOidLogic()); 175 l++; 176 k++; 177 } 178 if (generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) { 179 } else { 181 if (RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(importDefinitionAttributes.getTableName())) { 183 Element childRoot202 = (Element ) document.createElement("table"); 185 childRoot200.appendChild(childRoot202); 186 childRoot202.setAttribute("tableName", tableAttributes.getTableName()); 187 childRoot202.setAttribute("tableID", "" + k); 188 childRoot202.setAttribute("insert", "false"); 189 childRoot202.setAttribute("tableMode", tableAttributes.getTableMode()); 190 childRoot202.setAttribute("oidLogic", tableAttributes.getOidLogic()); 191 k++; } else { 193 k = 0; 194 if (i > 5 && RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(RelationshipsAttributes.getForeignVariables()[(i + 3) - 5])) { 195 k = k + 1; 196 } else { 197 k = 0; 198 } 199 Element childRoot205 = (Element ) document.createElement("table"); 200 childRoot200.appendChild(childRoot205); 201 childRoot205.setAttribute("tableName", RelationshipsAttributes.getForeignVariables()[i + 3]); 202 childRoot205.setAttribute("tableID", "" + k); 203 childRoot205.setAttribute("insert", "false"); 204 childRoot205.setAttribute("tableMode", tableAttributes.getTableMode()); 205 childRoot205.setAttribute("oidLogic", tableAttributes.getOidLogic()); 206 } 207 } 208 } 209 } else { 210 Element childRoot200 = (Element ) document.createElement("tables"); 212 childRoot1.appendChild(childRoot200); 213 Element childRoot203 = (Element ) document.createElement("table"); 214 childRoot200.appendChild(childRoot203); 215 TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode()); 216 childRoot203.setAttribute("tableName", tableAttributes.getTableName()); 217 childRoot203.setAttribute("tableID", "" + k); 218 childRoot203.setAttribute("insert", tableAttributes.getInsert()); 219 childRoot203.setAttribute("tableMode", tableAttributes.getTableMode()); 220 childRoot203.setAttribute("oidLogic", tableAttributes.getOidLogic()); 221 } 222 } else { 223 Element childRoot200 = (Element ) document.createElement("tables"); 225 childRoot1.appendChild(childRoot200); 226 Element childRoot201 = (Element ) document.createElement("table"); 227 childRoot200.appendChild(childRoot201); 228 TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode()); 229 childRoot201.setAttribute("tableName", tableAttributes.getTableName()); 230 childRoot201.setAttribute("tableID", tableAttributes.getTableID()); 231 childRoot201.setAttribute("insert", tableAttributes.getInsert()); 232 childRoot201.setAttribute("tableMode", tableAttributes.getTableMode()); 233 childRoot201.setAttribute("oidLogic", tableAttributes.getOidLogic()); 234 235 } 236 } 237 this.logger.write("full", "WriteImportDefinition is finished."); 238 } 239 243 private void setLogger() { 244 this.logger = StandardLogger.getCentralLogger(); 245 } 246 } 247 | Popular Tags |