📄 generatedoml.java
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
Copyright (C) 2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.loader.generator;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;
/**
* GenerateDoml class creates the doml file as an output.
* @author Radoslav Dutina
* @version 1.0
*/
public class GenerateDoml {
private Document documentDoml;
private String referenceTableName=null;
private String javaType=null;
private String tableNameToCase=null;
private String referenceTableNameToCase=null;
private Logger logger;
/**
* Construct object GenerateDoml with associated parameters.
* @param documentDoml is the reference to object of the Document class.
* @param rootDoml is reference to the object of Element class, which represents the root element of
* the documentDoml object.
* @param childRoot1 is the child of the root element, of the documentDoml object.
* @param childRoot2 is the child of the root element, of the documentDoml object. The childRoot2
* represent package tag.
* @param importDefinitionAttributes is references to ImportDefinitionAttributes object.
* @param relationshipsAttributes is references to RelationshipsAttributes object.
* @param generatorParameters represents the references to InputParameter object.
* @param tableName is name of the table form which we retrieve data.
* @throws LoaderException
*/
public GenerateDoml(Document documentDoml, Element rootDoml, Element childRoot1, Element childRoot2,
String tableName, ImportDefinitionAttributes importDefinitionAttributes,
RelationshipsAttributes relationshipsAttributes,
InputParameters generatorParameters) throws LoaderException {
setLogger();
this.logger.write("full", "GenerateDoml is started.");
//child1=tag database
try{
boolean notUsingOid=true;
if(importDefinitionAttributes.getTagSourceColumnName().length!=0){
for(int i=0;i<importDefinitionAttributes.getTagSourceColumnName().length;i++){
if(importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid")){
notUsingOid=false;
break;
}
}
}
//Crate child (table)
Element childRoot3 = (Element)documentDoml.createElement("table");
childRoot2.appendChild(childRoot3);
tableNameToCase=tableName.toUpperCase().substring(0,1)+tableName.toLowerCase().substring(1);
childRoot3.setAttribute("id", generatorParameters.getPackageName()+"."+tableNameToCase);
childRoot3.setAttribute("dbTableName", tableName);
// childRoot3.setAttribute("isLazyLoading", "true");
// childRoot3.setAttribute("caching", "none");
// if(notUsingOid){
// childRoot3.setAttribute("notUsingOid", "true");
// }else{
// childRoot3.setAttribute("notUsingOid", "false");
// }
//Crate child (column)
if(importDefinitionAttributes.getTagSourceColumnName().length!=0){
for(int i=0; i<importDefinitionAttributes.getTagSourceColumnName().length; i++){
//checking id the column is the foreign key
boolean fk=false;
if(relationshipsAttributes.getForeignVariables().length!=0 &&
relationshipsAttributes!=null){
for(int j=0;j<relationshipsAttributes.getForeignVariables().length;j=j+5){
if(relationshipsAttributes.getForeignVariables()[j+2].equalsIgnoreCase(
importDefinitionAttributes.getTagSourceColumnName()[i])){
fk=true;
referenceTableName=relationshipsAttributes.getForeignVariables()[j+3];
referenceTableNameToCase=referenceTableName.toUpperCase().substring(0,1)+
referenceTableName.toLowerCase().substring(1);
break;
}
}
}
//checking id the column is the primary key
boolean pk=false;
if(relationshipsAttributes.getPrimaryKeys().length!=0 &&
relationshipsAttributes!=null){
for(int k=0;k<relationshipsAttributes.getPrimaryKeys().length;k=k+2){
if(importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase(
relationshipsAttributes.getPrimaryKeys()[k+1])){
pk=true;
break;
}
}
}
if(!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid")&&
!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("version")){
Element childRoot4 = (Element)documentDoml.createElement("column");
childRoot3.appendChild(childRoot4);
childRoot4.setAttribute("id", importDefinitionAttributes.getTagSourceColumnName()[i]);
childRoot4.setAttribute("usedForQuery", "true");
if(pk){
childRoot4.setAttribute("isPrimaryKey", "true");
}
//this column is the foreign key
if(fk){
Element childRoot5 = (Element)documentDoml.createElement("referenceObject");
childRoot4.appendChild(childRoot5);
childRoot5.setAttribute("constraint", "true");
childRoot5.setAttribute("reference", generatorParameters.getPackageName()+"."+
referenceTableNameToCase);
Element childRoot6 = (Element)documentDoml.createElement("type");
childRoot4.appendChild(childRoot6);
if(importDefinitionAttributes.getTagAllowNulls()[i].equalsIgnoreCase("NOT NULL")){
childRoot6.setAttribute("canBeNull", "false");
}else{
childRoot6.setAttribute("canBeNull", "true");
}
//childRoot6.setAttribute("dbType", importDefinitionAttributes.getTagColumnType()[i]);
childRoot6.setAttribute("dbType", "none");
MappingJavaType mappingJavaType=new MappingJavaType( generatorParameters,
importDefinitionAttributes.getTagColumnType()[i]);
javaType=mappingJavaType.getJavaType();
//childRoot6.setAttribute("javaType", javaType);
childRoot6.setAttribute("javaType", generatorParameters.getPackageName()+"."+
referenceTableNameToCase+"DO");
childRoot6.setAttribute("size", importDefinitionAttributes.getTagColumnLenght()[i]);
//column isn't the foreign key
}else{
Element childRoot6 = (Element)documentDoml.createElement("type");
childRoot4.appendChild(childRoot6);
if(importDefinitionAttributes.getTagAllowNulls()[i].equalsIgnoreCase("NOT NULL")){
childRoot6.setAttribute("canBeNull", "false");
}else{
childRoot6.setAttribute("canBeNull", "true");
}
childRoot6.setAttribute("dbType", importDefinitionAttributes.getTagColumnType()[i]);
MappingJavaType mappingJavaType1=new MappingJavaType( generatorParameters,
importDefinitionAttributes.getTagColumnType()[i]);
javaType=mappingJavaType1.getJavaType();
childRoot6.setAttribute("javaType", javaType);
childRoot6.setAttribute("size", importDefinitionAttributes.getTagColumnLenght()[i]);
}
}
}
}
if(relationshipsAttributes.getIndexVariables().length!=0 &&
relationshipsAttributes!=null){
for(int i=0;i<relationshipsAttributes.getIndexVariables().length;i=i+3){
//Crate child (index)
Element childRoot7 = (Element)documentDoml.createElement("index");
childRoot3.appendChild(childRoot7);
childRoot7.setAttribute("id",relationshipsAttributes.getIndexVariables()[i+1]);
if(relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("1")){
childRoot7.setAttribute("unique","false");
}else{
childRoot7.setAttribute("unique","true");
}
Element childRoot8 = (Element)documentDoml.createElement("indexColumn");
childRoot7.appendChild(childRoot8);
childRoot8.setAttribute("id",relationshipsAttributes.getIndexVariables()[i+2]);
}
}
}catch (Exception e) {
String msg="Exception in class GenerateDoml: Error has occurred when trying to generate doml file!";
LoaderException le=new LoaderException(msg+"\n"+e.getMessage(), (Throwable)e);
this.logger.write("full","Exception in class GenerateDoml: Error has occurred when trying to generate doml file!"+"\n"+le.getStackTraceAsString());
throw le;
}
this.logger.write("full", "GenerateDoml is finished.");
}
/**
* This method will set logger object
* @param logger
*/
private void setLogger() {
this.logger = StandardLogger.getCentralLogger();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -