daodefinition.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 1,619 行 · 第 1/4 页
JAVA
1,619 行
else
attrMapping.setColumn(column);
handleColumnSubElement (elem, attrMapping);
list.add(attrMapping);
return;
}
msg = new JtMessage (JDOMAdapter.GET_CHILDREN);
msg.setMsgContent("hibernate-mapping/class/composite-id");
children = (List) factory.sendMessage (adapter, msg);
if (children == null) {
return;
}
for (i = 0; i < children.size(); i++) {
elem = (Element) children.get(i);
if (!("key-property".equals(elem.getName())))
continue;
id = elem.getAttributeValue("name");
attrMapping = new DAOMapping ();
attrMapping.setAttribute(id);
column = elem.getAttributeValue("column");
attrMapping.setEnabled(true);
attrMapping.setKeyAttribute(true);
if (column == null || column.equals(""))
attrMapping.setColumn(id); //check
else
attrMapping.setColumn(column);
handleColumnSubElement (elem, attrMapping);
list.add(attrMapping);
}
}
private void initializeFormMapping (DAODefinitionForm form) {
JtIterator iterator;
LinkedList list = new LinkedList();
String st;
DAOMapping arr[];
DAOMapping entry;
if (attributes == null) {
//this.mapping = null;
return;
}
iterator = (JtIterator) attributes.processMessage(new JtMessage (JtHashTable.JtGET_KEYS));
if (iterator == null)
return;
for (;;) {
st = (String) iterator.processMessage(new JtMessage (JtIterator.JtNEXT));
if (st == null)
break;
//lvBean = new LabelValueBean (st, st);
entry = new DAOMapping ();
entry.setAttribute(st);
entry.setColumn(st);
entry.setEnabled (true);
list.add(entry);
}
while (list.size() < DAODefinition.MAX_ENTRIES) {
entry = new DAOMapping ();
list.add(entry);
}
//arr = (LabelValueBean[]) keyList.toArray(new LabelValueBean[0]);
arr = (DAOMapping[]) list.toArray(new DAOMapping[0]);
//this.mapping = arr;
form.setDbmappings(arr);
}
private void initializeForm (DAODefinitionForm form) {
JtMessage msg = new JtMessage (JtFactory.JtGET_ATTRIBUTES);
//JtFactory factory = new JtFactory ();
Object obj;
String[] ids;
JtIterator iterator;
int i;
//String st;
//LabelValueBean lvBean;
//LinkedList keyList = new LinkedList();
if (className == null || form == null)
return;
obj = factory.createObject(className);
if (obj == null) {
if (factory.getObjException() != null)
this.setObjException(factory.getObjException());
return; // check
}
msg.setMsgContent(obj);
//attributes = (JtHashTable) factory.processMessage(msg);
//if (attributes == null)
// return;
//iterator = (JtIterator) attributes.processMessage(new JtMessage (JtHashTable.JtGET_KEYS));
iterator = ngetAttributes ();
if (iterator == null)
return;
/*
for (;;) {
st = (String) iterator.processMessage(new JtMessage (JtIterator.JtNEXT));
if (st == null)
break;
lvBean = new LabelValueBean (st, st);
keyList.add(lvBean);
}
form.setAttributes(keyList);
*/
ids = getIDs ();
if (ids != null) {
form.setDbkeys(ids);
for (i=0; i < ids.length; i++) {
handleTrace ("InititializeForm (key[" + i + "]):" + ids[i]);
}
}
}
private String getQualifiedClassName (String pckg, String cname) {
if (pckg == null)
pckg = "";
if (cname == null)
cname = "";
if (pckg.equals(""))
return (cname);
return (pckg + "." + cname);
}
private void initializeFormFromFile (DAODefinitionForm form, InputStream inputStream) {
//JtMessage msg = new JtMessage (JtFactory.JtGET_ATTRIBUTES);
//JtFactory factory = new JtFactory ();
//String[] ids;
JtIterator iterator;
//String st;
//LabelValueBean lvBean;
//LinkedList keyList = new LinkedList();
JtJavaParser parser = new JtJavaParser ();
String qname;
//if (className == null || form == null)
if (form == null || inputStream == null)
return;
//parser.setPath(className);
parser.setInputStream(inputStream);
//iStream.setInputStream(inputStream);
//factory.sendMessage (iStream, new JtMessage (JtInputStream.JtREAD_STREAM));
attributes = (JtHashTable) factory.sendMessage(parser, new JtMessage (JtJavaParser.PARSE));
if (parser.getObjException() != null) {
this.setObjException(factory.getObjException());
return; // check
}
qname = getQualifiedClassName (parser.getClassPackage(),
parser.getClassName());
form.setName(qname);
//attributes = (JtHashTable) factory.processMessage(msg);
if (attributes == null)
return;
iterator = (JtIterator) attributes.processMessage(new JtMessage (JtHashTable.JtGET_KEYS));
if (iterator == null)
return;
/*
for (;;) {
st = (String) iterator.processMessage(new JtMessage (JtIterator.JtNEXT));
if (st == null)
break;
lvBean = new LabelValueBean (st, st);
keyList.add(lvBean);
}
form.setAttributes(keyList);
ids = getIDs ();
if (ids != null)
form.setDbkeys(ids);
*/
}
/*
String findDBKey (String name) {
String[] dbKeys;
int i;
String key;
if (daoForm == null || name == null)
return null;
dbKeys = daoForm.getDbkeys();
if (dbKeys == null)
return null;
for (i = 0; i < dbKeys.length; i++) {
key = dbKeys[i];
if (key == null)
continue;
if (key.equals(name))
return name;
}
return null;
}
*/
// Add Column subelement
private Element addColumnSubElement (DAOMapping attrMapping) {
Element element;
String sqlType;
boolean bool = false;
String columnName;
if (attrMapping == null)
return null;
element = new Element("column");
sqlType = attrMapping.getSql_type();
columnName = attrMapping.getColumn();
if (columnName != null && !columnName.equals("")) {// check white spaces
element.setAttribute("name", columnName);
} else
element.setAttribute("name", attrMapping.getAttribute());
if (sqlType != null && !sqlType.equals("")) {
element.setAttribute("sql_type", sqlType);
bool = true;
}
if (attrMapping.isNotNull()) {
element.setAttribute("not-null", "true");
bool = true;
}
if (attrMapping.isUnique()) {
element.setAttribute("unique", "true");
bool = true;
}
if (bool)
return (element);
return null;
}
private boolean ngenerateProperties () {
JtMessage msg = new JtMessage (JDOMAdapter.ADD_ELEMENT);
String columnName;
Element element, columnElement;
DAOMapping attrMapping;
DAOMapping arr[];
int i;
String attrName;
if (daoForm == null)
return (false);
arr = (DAOMapping[]) daoForm.getDbmappings();
if (arr != null ) {
for (i = 0; i < arr.length; i++) {
attrMapping = arr[i];
if (attrMapping == null)
continue;
if (!attrMapping.isEnabled())
continue;
attrName = attrMapping.getAttribute();
//if (findDBKey (attrName) != null) // is this a key ?
// continue;
if (attrMapping.isKeyAttribute())
continue;
element = new Element ("property");
element.setAttribute("name", attrMapping.getAttribute());
columnName = attrMapping.getColumn();
columnElement = addColumnSubElement (attrMapping);
if (columnElement != null)
element.addContent(columnElement);
else if (columnName != null && !columnName.equals("")) // check white spaces
if (!columnName.equals (attrMapping.getAttribute()))
element.setAttribute("column", columnName);
msg.setMsgContent(element);
msg.setMsgData ("hibernate-mapping/class");
adapter.processMessage(msg);
}
}
return (true);
}
private Element findChild (List children, String name) {
String tmp;
int i;
Element elem;
if (children == null || name == null)
return (null);
for (i = 0; i < children.size(); i++) {
elem = (Element) children.get(i);
if (!("property".equals(elem.getName())))
continue;
tmp = elem.getAttributeValue("name");
if (name.equals(tmp))
return elem;
}
return (null);
}
private boolean isID (List list, String name) {
Iterator iterator;
DAOMapping attrMapping;
if (list == null || name == null)
return false;
iterator = list.iterator();
while (iterator.hasNext()) {
attrMapping = (DAOMapping) iterator.next();
if (attrMapping == null)
continue;
if (name.equals(attrMapping.getAttribute())) {
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?