You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(80) |
Nov
(64) |
Dec
(24) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(15) |
Feb
(28) |
Mar
(92) |
Apr
(42) |
May
(30) |
Jun
(27) |
Jul
(50) |
Aug
(38) |
Sep
(30) |
Oct
(2) |
Nov
(5) |
Dec
(5) |
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(20) |
Jun
(14) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(11) |
Nov
(5) |
Dec
(2) |
2005 |
Jan
(4) |
Feb
(11) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(37) |
Nov
(18) |
Dec
|
2006 |
Jan
(22) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Dan C. <dch...@us...> - 2006-06-22 19:16:23
|
Update of /cvsroot/xorm/xorm/src/org/xorm/util/jdoxml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11663/src/org/xorm/util/jdoxml Modified Files: Tag: dan-no-jdom JDOXML.java Log Message: getElementsByTagName descends deep. Need to filter for only direct descendants in most cases. Index: JDOXML.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/util/jdoxml/JDOXML.java,v retrieving revision 1.5.4.1 retrieving revision 1.5.4.2 diff -C2 -d -r1.5.4.1 -r1.5.4.2 *** JDOXML.java 8 Jun 2006 17:50:55 -0000 1.5.4.1 --- JDOXML.java 22 Jun 2006 19:16:20 -0000 1.5.4.2 *************** *** 84,88 **** Document doc = docBuilder.parse(inputSource); ! return parsePackage((Element)doc.getDocumentElement().getElementsByTagName("package").item(0)); } catch (javax.xml.parsers.ParserConfigurationException e) { --- 84,94 ---- Document doc = docBuilder.parse(inputSource); ! Element docElement = doc.getDocumentElement(); ! Element packageElement = (Element)docElement.getElementsByTagName("package").item(0); ! // Only look for direct descendants ! if (packageElement != null && ! packageElement.getParentNode().equals(docElement)) { ! return parsePackage(packageElement); ! } } catch (javax.xml.parsers.ParserConfigurationException e) { *************** *** 101,106 **** NodeList classes = element.getElementsByTagName("class"); for (int i = 0; i < classes.getLength(); ++i) { ! element = (Element)classes.item(i); ! jdoPackage.getClasses().add(parseClass(element)); } return jdoPackage; --- 107,116 ---- NodeList classes = element.getElementsByTagName("class"); for (int i = 0; i < classes.getLength(); ++i) { ! Element classElement = (Element)classes.item(i); ! // Only look for direct descendants ! if (!classElement.getParentNode().equals(element)) { ! continue; ! } ! jdoPackage.getClasses().add(parseClass(classElement)); } return jdoPackage; *************** *** 117,122 **** NodeList fields = element.getElementsByTagName("field"); for (int i = 0; i < fields.getLength(); ++i) { ! element = (Element)fields.item(i); ! jdoClass.getFields().add(parseField(element)); } return jdoClass; --- 127,136 ---- NodeList fields = element.getElementsByTagName("field"); for (int i = 0; i < fields.getLength(); ++i) { ! Element fieldElement = (Element)fields.item(i); ! // Only look for direct descendants ! if (!fieldElement.getParentNode().equals(element)) { ! continue; ! } ! jdoClass.getFields().add(parseField(fieldElement)); } return jdoClass; *************** *** 140,151 **** --- 154,177 ---- Element child = (Element)element.getElementsByTagName("collection").item(0); + // Only look for direct descendants + if (child != null && !child.getParentNode().equals(element)) { + child = null; + } if (child != null) { jdoField.setCollection(parseCollection(child)); } else { child = (Element)element.getElementsByTagName("map").item(0); + // Only look for direct descendants + if (child != null && !child.getParentNode().equals(element)) { + child = null; + } if (child != null) { jdoField.setMap(parseMap(child)); } else { child = (Element)element.getElementsByTagName("array").item(0); + // Only look for direct descendants + if (child != null && !child.getParentNode().equals(element)) { + child = null; + } if (child != null) { jdoField.setArray(parseArray(child)); *************** *** 197,205 **** NodeList exts = element.getElementsByTagName("extension"); for (int e = 0; e < exts.getLength(); ++e) { ! element = (Element)exts.item(e); JDOExtension jdoExtension = new JDOExtension(); ! jdoExtension.setVendorName(emptyIsNull(element.getAttribute("vendor-name"))); ! jdoExtension.setKey(emptyIsNull(element.getAttribute("key"))); ! jdoExtension.setValue(emptyIsNull(element.getAttribute("value"))); extendable.addExtension(jdoExtension); } --- 223,235 ---- NodeList exts = element.getElementsByTagName("extension"); for (int e = 0; e < exts.getLength(); ++e) { ! Element ext = (Element)exts.item(e); ! // Only look for direct descendants ! if (!ext.getParentNode().equals(element)) { ! continue; ! } JDOExtension jdoExtension = new JDOExtension(); ! jdoExtension.setVendorName(emptyIsNull(ext.getAttribute("vendor-name"))); ! jdoExtension.setKey(emptyIsNull(ext.getAttribute("key"))); ! jdoExtension.setValue(emptyIsNull(ext.getAttribute("value"))); extendable.addExtension(jdoExtension); } |
From: Dan C. <dch...@us...> - 2006-06-22 19:16:23
|
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11663/src/org/xorm/datastore/xml Modified Files: Tag: dan-no-jdom W3CDocumentDriver.java Log Message: getElementsByTagName descends deep. Need to filter for only direct descendants in most cases. Index: W3CDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/W3CDocumentDriver.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** W3CDocumentDriver.java 8 Jun 2006 17:33:47 -0000 1.2 --- W3CDocumentDriver.java 22 Jun 2006 19:16:20 -0000 1.2.2.1 *************** *** 167,171 **** xmlResults = new ArrayList(); for (int c = 0; c < children.getLength(); ++c) { ! xmlResults.add(children.item(c)); } } --- 167,175 ---- xmlResults = new ArrayList(); for (int c = 0; c < children.getLength(); ++c) { ! // Only add direct descendants ! Element child = (Element)children.item(c); ! if (child.getParentNode().equals(parent)) { ! xmlResults.add(child); ! } } } *************** *** 233,237 **** return element.getParentNode(); } else { ! return (Element)element.getElementsByTagName(path).item(0); } } --- 237,248 ---- return element.getParentNode(); } else { ! Element child = (Element)element.getElementsByTagName(path).item(0); ! // Only return direct descendants ! if (child.getParentNode().equals(element)) { ! return child; ! } ! else { ! return null; ! } } } *************** *** 258,262 **** Element parent = element; element = (Element)element.getElementsByTagName(path).item(0); ! if (create && (element == null)) { element = document.createElement(path); parent.appendChild(element); --- 269,277 ---- Element parent = element; element = (Element)element.getElementsByTagName(path).item(0); ! if (!element.getParentNode().equals(parent)) { ! // Only look for direct descendants ! element = null; ! } ! if (create && element == null) { element = document.createElement(path); parent.appendChild(element); |
From: Dan C. <dch...@us...> - 2006-06-22 19:16:23
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11663/src/org/xorm Modified Files: Tag: dan-no-jdom ModelMapping.java Log Message: getElementsByTagName descends deep. Need to filter for only direct descendants in most cases. Index: ModelMapping.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ModelMapping.java,v retrieving revision 1.62 retrieving revision 1.62.2.1 diff -C2 -d -r1.62 -r1.62.2.1 *** ModelMapping.java 8 Jun 2006 17:33:47 -0000 1.62 --- ModelMapping.java 22 Jun 2006 19:16:20 -0000 1.62.2.1 *************** *** 671,674 **** --- 671,678 ---- for (int t = 0; t < tables.getLength(); ++t) { Element element = (Element)tables.item(t); + // Only look for direct descendants + if (!element.getParentNode().equals(root)) { + continue; + } String tableName = element.getAttribute("name"); Table table = new Table(tableName); *************** *** 677,680 **** --- 681,688 ---- for (int c = 0; c < columns.getLength(); ++c) { Element colElement = (Element)columns.item(c); + // Only look for direct descendants + if (!colElement.getParentNode().equals(element)) { + continue; + } String columnName = colElement.getAttribute("name"); Column column = new Column(table, columnName); |
From: Dan C. <dch...@us...> - 2006-06-08 18:21:27
|
Update of /cvsroot/xorm/xorm/tools/src/org/xorm/tools/generator In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26770 Modified Files: Tag: dan-no-jdom DBToXML.java GenerateJDO.java Log Message: removed dependency on JDOM Index: GenerateJDO.java =================================================================== RCS file: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/generator/GenerateJDO.java,v retrieving revision 1.5 retrieving revision 1.5.8.1 diff -C2 -d -r1.5 -r1.5.8.1 *** GenerateJDO.java 15 Apr 2003 19:00:51 -0000 1.5 --- GenerateJDO.java 8 Jun 2006 18:21:17 -0000 1.5.8.1 *************** *** 20,25 **** package org.xorm.tools.generator; - import org.jdom.*; - import org.jdom.output.XMLOutputter; import org.xorm.ClassMapping; import org.xorm.util.FieldDescriptor; --- 20,23 ---- *************** *** 49,57 **** private static void buildDocument(File path, String dir, String pkgName) throws Exception { ! Element jdo = new Element("jdo"); ! Element pkg = new Element("package"); ! pkg.setAttribute("name", pkgName); ! jdo.addContent(pkg); path = new File(path, dir); File[] classFiles = path.listFiles(new FileFilter() { --- 47,57 ---- private static void buildDocument(File path, String dir, String pkgName) throws Exception { ! PrintStream out = System.out; + out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); + out.println("<!DOCTYPE jdo SYSTEM \"jdo.dtd\">"); + out.println("<jdo>"); + out.println(" <package name=\"" + pkgName + "\">"); + path = new File(path, dir); File[] classFiles = path.listFiles(new FileFilter() { *************** *** 67,83 **** Class clazz = Class.forName(pkgName + "." + name); if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { ! ! Element classElem = new Element("class"); ! pkg.addContent(classElem); ! classElem.setAttribute("name", name); ! Element ext = new Element("extension"); ! ext.setAttribute("vendor-name", "XORM"); ! ext.setAttribute("key", "table"); ! ext.setAttribute("value", makeColumnName(name)); ! classElem.addContent(ext); ! // THIS IS THE DEFAULT ! //classElem.setAttribute("identity-type", "datastore"); ! ArrayList fds = new ArrayList(FieldDescriptor.getFieldDescriptors(clazz)); Collections.sort(fds, new Comparator() { --- 67,77 ---- Class clazz = Class.forName(pkgName + "." + name); if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { ! out.print(" <class name=\"" + name + "\""); // THIS IS THE DEFAULT ! //out.print(" identity-type=\"datastore\""); ! out.println(">"); ! ! out.println(" <ext vendor-name=\"XORM\" key=\"table\" value=\"" + makeColumnName(name) + "\"/>"); ! ArrayList fds = new ArrayList(FieldDescriptor.getFieldDescriptors(clazz)); Collections.sort(fds, new Comparator() { *************** *** 91,96 **** for (Iterator j = fds.iterator(); j.hasNext(); ) { FieldDescriptor fd = (FieldDescriptor) j.next(); ! Element field = new Element("field"); ! field.setAttribute("name", fd.name); Class pdType = fd.type; if (pdType.isArray()) { --- 85,89 ---- for (Iterator j = fds.iterator(); j.hasNext(); ) { FieldDescriptor fd = (FieldDescriptor) j.next(); ! out.println(" <field name=\"" + fd.name + "\">"); Class pdType = fd.type; if (pdType.isArray()) { *************** *** 99,134 **** // TODO handling for map } else if (Collection.class.isAssignableFrom(pdType)) { ! Element collection = new Element("collection"); ! collection.setAttribute("element-type", makeCollectionElementType(fd.name)); ! field.addContent(collection); ! ext = new Element("extension"); ! ext.setAttribute("vendor-name", "XORM"); ! ext.setAttribute("key", "table"); ! ext.setAttribute("value", ""); ! collection.addContent(ext); ! ext = new Element("extension"); ! ext.setAttribute("vendor-name", "XORM"); ! ext.setAttribute("key", "source"); ! ext.setAttribute("value", ""); ! collection.addContent(ext); } else { String columnName = makeColumnName(fd.name); ! ext = new Element("extension"); ! ext.setAttribute("vendor-name", "XORM"); ! ext.setAttribute("key", "column"); ! ext.setAttribute("value", columnName); ! field.addContent(ext); ! //field.setAttribute("default-fetch-group", "true"); } ! classElem.addContent(field); } } // isInterface } // for each file } // classFiles != null ! Document doc = new Document(jdo); ! DocType dt = new DocType("jdo"); ! dt.setSystemID("jdo.dtd"); ! doc.setDocType(dt); ! new XMLOutputter(" ", true).output(doc, System.out); } --- 92,115 ---- // TODO handling for map } else if (Collection.class.isAssignableFrom(pdType)) { ! out.println(" <collection element-type=\"" + ! makeCollectionElementType(fd.name) + "\">"); ! out.println(" <extension vendor-name=\"XORM\" key=\"table\" value=\"\"/>"); ! out.println(" <extension vendor-name=\"XORM\" key=\"source\" value=\"\"/>"); ! out.println(" </collection>"); } else { String columnName = makeColumnName(fd.name); ! out.print(" <extension vendor-name=\"XORM\" key=\"column\" value=\"" + columnName + "\""); ! //out.print(" default-fetch-group=\"true\""); ! out.println("/>"); } ! out.println(" </field>"); } + out.println(" </class>"); } // isInterface } // for each file } // classFiles != null ! ! out.println(" </package>"); ! out.println("</jdo>"); } Index: DBToXML.java =================================================================== RCS file: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/generator/DBToXML.java,v retrieving revision 1.9 retrieving revision 1.9.4.1 diff -C2 -d -r1.9 -r1.9.4.1 *** DBToXML.java 6 Jan 2006 20:50:21 -0000 1.9 --- DBToXML.java 8 Jun 2006 18:21:17 -0000 1.9.4.1 *************** *** 22,25 **** --- 22,26 ---- import java.io.FileInputStream; import java.io.FileOutputStream; + import java.io.PrintStream; import java.sql.*; import java.util.ArrayList; *************** *** 30,35 **** import java.util.regex.Pattern; import javax.sql.DataSource; - import org.jdom.*; - import org.jdom.output.XMLOutputter; import org.xorm.XORM; import org.xorm.datastore.sql.SQLConnectionInfo; --- 31,34 ---- *************** *** 103,107 **** } ! Element database = new Element("database"); Properties properties = new Properties(); properties.load(new FileInputStream(propertiesFileName)); --- 102,117 ---- } ! PrintStream out; ! if (outputFileName == null) { ! out = System.out; ! } ! else { ! out = new PrintStream(new FileOutputStream(outputFileName)); ! } ! ! out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); ! out.println("<!DOCTYPE database SYSTEM \"database.dtd\">"); ! out.println("<database>"); ! Properties properties = new Properties(); properties.load(new FileInputStream(propertiesFileName)); *************** *** 164,190 **** results.close(); - Element table = new Element("table"); - database.addContent(table); String outputTableName = tableName; if (upper) outputTableName = tableName.toUpperCase(); else if (lower) outputTableName = tableName.toLowerCase(); ! table.setAttribute("name", outputTableName); results = metadata.getColumns(null, null, tableName, null); while (results.next()) { - Element column = new Element("column"); String columnName = results.getString("COLUMN_NAME"); String outputColumnName = columnName; if (upper) outputColumnName = columnName.toUpperCase(); if (lower) outputColumnName = columnName.toLowerCase(); ! column.setAttribute("name", outputColumnName); String typeName = SQLType.nameFor(results.getInt("DATA_TYPE")); if (typeName != null) { ! column.setAttribute("type", typeName); } if (columnName.equals(tableToPK.get(tableName))) { ! column.setAttribute("primary-key", "true"); if (autoincrement) { ! column.setAttribute("auto", "true"); } if (sequencePattern != null) { --- 174,198 ---- results.close(); String outputTableName = tableName; if (upper) outputTableName = tableName.toUpperCase(); else if (lower) outputTableName = tableName.toLowerCase(); ! out.println(" <table name=\"" + outputTableName + "\">"); ! results = metadata.getColumns(null, null, tableName, null); while (results.next()) { String columnName = results.getString("COLUMN_NAME"); String outputColumnName = columnName; if (upper) outputColumnName = columnName.toUpperCase(); if (lower) outputColumnName = columnName.toLowerCase(); ! out.print(" <column name=\"" + outputColumnName + "\""); String typeName = SQLType.nameFor(results.getInt("DATA_TYPE")); if (typeName != null) { ! out.print(" type=\"" + typeName + "\""); } if (columnName.equals(tableToPK.get(tableName))) { ! out.print(" primary-key=\"true\""); if (autoincrement) { ! out.print(" auto=\"true\""); } if (sequencePattern != null) { *************** *** 193,219 **** sequenceName = Pattern.compile("/T/").matcher(sequenceName).replaceAll(tableName); if (sequences.contains(sequenceName)) { ! column.setAttribute("sequence", sequenceName); } } } if ("NO".equals(results.getString("IS_NULLABLE"))) { ! column.setAttribute("non-null", "true"); } ! table.addContent(column); } results.close(); } connection.close(); ! Document document = new Document(database); ! DocType dt = new DocType("database"); ! dt.setSystemID("database.dtd"); ! document.setDocType(dt); ! XMLOutputter xml = new XMLOutputter(" ", true); ! if (outputFileName == null) { ! xml.output(document, System.out); ! } else { ! xml.output(document, new FileOutputStream(outputFileName)); ! } } } --- 201,220 ---- sequenceName = Pattern.compile("/T/").matcher(sequenceName).replaceAll(tableName); if (sequences.contains(sequenceName)) { ! out.print(" sequence=\"" + sequenceName + "\""); } } } if ("NO".equals(results.getString("IS_NULLABLE"))) { ! out.print(" non-null=\"true\""); } ! out.println("/>"); } results.close(); + + out.println(" </table>"); } connection.close(); ! out.println("</database>"); } } |
From: Dan C. <dch...@us...> - 2006-06-08 17:50:59
|
Update of /cvsroot/xorm/xorm/lib In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10914/lib Removed Files: Tag: dan-no-jdom jdom.jar Log Message: branch where JDOM is no more...JDOXML uses W3C DOM --- jdom.jar DELETED --- |
From: Dan C. <dch...@us...> - 2006-06-08 17:50:59
|
Update of /cvsroot/xorm/xorm/src/org/xorm/util/jdoxml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10914/src/org/xorm/util/jdoxml Modified Files: Tag: dan-no-jdom JDOXML.java Log Message: branch where JDOM is no more...JDOXML uses W3C DOM Index: JDOXML.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/util/jdoxml/JDOXML.java,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -C2 -d -r1.5 -r1.5.4.1 *** JDOXML.java 3 May 2005 13:59:06 -0000 1.5 --- JDOXML.java 8 Jun 2006 17:50:55 -0000 1.5.4.1 *************** *** 24,31 **** import java.util.Iterator; ! import org.jdom.Document; ! import org.jdom.Element; ! import org.jdom.JDOMException; ! import org.jdom.input.SAXBuilder; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; --- 24,33 ---- import java.util.Iterator; ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; ! import org.xml.sax.SAXException; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; *************** *** 63,67 **** // Load the mappingFile using JDOM, validating against DTD // if required ! SAXBuilder biff = new SAXBuilder(validateXML); EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { --- 65,70 ---- // Load the mappingFile using JDOM, validating against DTD // if required ! DocumentBuilder docBuilder = ! DocumentBuilderFactory.newInstance().newDocumentBuilder(); EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { *************** *** 74,86 **** } }; ! biff.setEntityResolver(resolver); InputSource inputSource = new InputSource(input); // Fake out Crimson inputSource.setSystemId(JDOXML.class.getResource(JDO_DTD_PATH).toString()); ! Document doc = biff.build(inputSource); ! return parsePackage(doc.getRootElement().getChild("package")); ! } catch (JDOMException e) { e.printStackTrace(); } --- 77,93 ---- } }; ! docBuilder.setEntityResolver(resolver); InputSource inputSource = new InputSource(input); // Fake out Crimson inputSource.setSystemId(JDOXML.class.getResource(JDO_DTD_PATH).toString()); ! Document doc = docBuilder.parse(inputSource); ! return parsePackage((Element)doc.getDocumentElement().getElementsByTagName("package").item(0)); ! } ! catch (javax.xml.parsers.ParserConfigurationException e) { ! e.printStackTrace(); ! } ! catch (SAXException e) { e.printStackTrace(); } *************** *** 90,98 **** private static JDOPackage parsePackage(Element element) { JDOPackage jdoPackage = new JDOPackage(); ! jdoPackage.setName(element.getAttributeValue("name")); addExtensions(element, jdoPackage); ! Iterator i = element.getChildren("class").iterator(); ! while (i.hasNext()) { ! element = (Element) i.next(); jdoPackage.getClasses().add(parseClass(element)); } --- 97,105 ---- private static JDOPackage parsePackage(Element element) { JDOPackage jdoPackage = new JDOPackage(); ! jdoPackage.setName(emptyIsNull(element.getAttribute("name"))); addExtensions(element, jdoPackage); ! NodeList classes = element.getElementsByTagName("class"); ! for (int i = 0; i < classes.getLength(); ++i) { ! element = (Element)classes.item(i); jdoPackage.getClasses().add(parseClass(element)); } *************** *** 102,114 **** private static JDOClass parseClass(Element element) { JDOClass jdoClass = new JDOClass(); ! jdoClass.setName(element.getAttributeValue("name")); ! jdoClass.setIdentityType(JDOIdentityType.forName(element.getAttributeValue("identity-type"))); ! jdoClass.setObjectIdClass(element.getAttributeValue("objectid-class")); ! jdoClass.setRequiresExtent("true".equals(element.getAttributeValue("requires-extent"))); ! jdoClass.setPersistenceCapableSuperclass(element.getAttributeValue("persistence-capable-superclass")); addExtensions(element, jdoClass); ! Iterator i = element.getChildren("field").iterator(); ! while (i.hasNext()) { ! element = (Element) i.next(); jdoClass.getFields().add(parseField(element)); } --- 109,121 ---- private static JDOClass parseClass(Element element) { JDOClass jdoClass = new JDOClass(); ! jdoClass.setName(emptyIsNull(element.getAttribute("name"))); ! jdoClass.setIdentityType(JDOIdentityType.forName(emptyIsNull(element.getAttribute("identity-type")))); ! jdoClass.setObjectIdClass(emptyIsNull(element.getAttribute("objectid-class"))); ! jdoClass.setRequiresExtent("true".equals(element.getAttribute("requires-extent"))); ! jdoClass.setPersistenceCapableSuperclass(emptyIsNull(element.getAttribute("persistence-capable-superclass"))); addExtensions(element, jdoClass); ! NodeList fields = element.getElementsByTagName("field"); ! for (int i = 0; i < fields.getLength(); ++i) { ! element = (Element)fields.item(i); jdoClass.getFields().add(parseField(element)); } *************** *** 118,144 **** private static JDOField parseField(Element element) { JDOField jdoField = new JDOField(); ! jdoField.setName(element.getAttributeValue("name")); addExtensions(element, jdoField); ! jdoField.setNullValue(JDONullValue.forName(element.getAttributeValue("null-value"))); ! jdoField.setPersistenceModifier(JDOPersistenceModifier.forName(element.getAttributeValue("persistence-modifier"))); ! String value = element.getAttributeValue("default-fetch-group"); if (value != null) { jdoField.setDefaultFetchGroup(Boolean.valueOf(value)); } ! value = element.getAttributeValue("embedded"); if (value != null) { jdoField.setEmbedded(Boolean.valueOf(value)); } ! jdoField.setPrimaryKey("true".equals(element.getAttributeValue("primary-key"))); ! Element child = element.getChild("collection"); if (child != null) { jdoField.setCollection(parseCollection(child)); } else { ! child = element.getChild("map"); if (child != null) { jdoField.setMap(parseMap(child)); } else { ! child = element.getChild("array"); if (child != null) { jdoField.setArray(parseArray(child)); --- 125,151 ---- private static JDOField parseField(Element element) { JDOField jdoField = new JDOField(); ! jdoField.setName(emptyIsNull(element.getAttribute("name"))); addExtensions(element, jdoField); ! jdoField.setNullValue(JDONullValue.forName(emptyIsNull(element.getAttribute("null-value")))); ! jdoField.setPersistenceModifier(JDOPersistenceModifier.forName(emptyIsNull(element.getAttribute("persistence-modifier")))); ! String value = emptyIsNull(element.getAttribute("default-fetch-group")); if (value != null) { jdoField.setDefaultFetchGroup(Boolean.valueOf(value)); } ! value = emptyIsNull(element.getAttribute("embedded")); if (value != null) { jdoField.setEmbedded(Boolean.valueOf(value)); } ! jdoField.setPrimaryKey("true".equals(element.getAttribute("primary-key"))); ! Element child = (Element)element.getElementsByTagName("collection").item(0); if (child != null) { jdoField.setCollection(parseCollection(child)); } else { ! child = (Element)element.getElementsByTagName("map").item(0); if (child != null) { jdoField.setMap(parseMap(child)); } else { ! child = (Element)element.getElementsByTagName("array").item(0); if (child != null) { jdoField.setArray(parseArray(child)); *************** *** 152,157 **** JDOCollection jdoCollection = new JDOCollection(); addExtensions(element, jdoCollection); ! jdoCollection.setElementType(element.getAttributeValue("element-type")); ! String value = element.getAttributeValue("embedded-element"); if (value != null) { jdoCollection.setEmbeddedElement(Boolean.valueOf(value)); --- 159,164 ---- JDOCollection jdoCollection = new JDOCollection(); addExtensions(element, jdoCollection); ! jdoCollection.setElementType(emptyIsNull(element.getAttribute("element-type"))); ! String value = emptyIsNull(element.getAttribute("embedded-element")); if (value != null) { jdoCollection.setEmbeddedElement(Boolean.valueOf(value)); *************** *** 163,173 **** JDOMap jdoMap = new JDOMap(); addExtensions(element, jdoMap); ! jdoMap.setKeyType(element.getAttributeValue("key-type")); ! String value = element.getAttributeValue("embedded-key"); if (value != null) { jdoMap.setEmbeddedKey(Boolean.valueOf(value)); } ! jdoMap.setValueType(element.getAttributeValue("value-type")); ! value = element.getAttributeValue("embedded-value"); if (value != null) { jdoMap.setEmbeddedValue(Boolean.valueOf(value)); --- 170,180 ---- JDOMap jdoMap = new JDOMap(); addExtensions(element, jdoMap); ! jdoMap.setKeyType(emptyIsNull(element.getAttribute("key-type"))); ! String value = emptyIsNull(element.getAttribute("embedded-key")); if (value != null) { jdoMap.setEmbeddedKey(Boolean.valueOf(value)); } ! jdoMap.setValueType(emptyIsNull(element.getAttribute("value-type"))); ! value = emptyIsNull(element.getAttribute("embedded-value")); if (value != null) { jdoMap.setEmbeddedValue(Boolean.valueOf(value)); *************** *** 179,183 **** JDOArray jdoArray = new JDOArray(); addExtensions(element, jdoArray); ! String value = element.getAttributeValue("embedded-element"); if (value != null) { jdoArray.setEmbeddedElement(Boolean.valueOf(value)); --- 186,190 ---- JDOArray jdoArray = new JDOArray(); addExtensions(element, jdoArray); ! String value = emptyIsNull(element.getAttribute("embedded-element")); if (value != null) { jdoArray.setEmbeddedElement(Boolean.valueOf(value)); *************** *** 188,198 **** /** Shared function for all elements that can have extensions. */ private static void addExtensions(Element element, JDOExtendable extendable) { ! Iterator exts = element.getChildren("extension").iterator(); ! while (exts.hasNext()) { ! element = (Element) exts.next(); JDOExtension jdoExtension = new JDOExtension(); ! jdoExtension.setVendorName(element.getAttributeValue("vendor-name")); ! jdoExtension.setKey(element.getAttributeValue("key")); ! jdoExtension.setValue(element.getAttributeValue("value")); extendable.addExtension(jdoExtension); } --- 195,205 ---- /** Shared function for all elements that can have extensions. */ private static void addExtensions(Element element, JDOExtendable extendable) { ! NodeList exts = element.getElementsByTagName("extension"); ! for (int e = 0; e < exts.getLength(); ++e) { ! element = (Element)exts.item(e); JDOExtension jdoExtension = new JDOExtension(); ! jdoExtension.setVendorName(emptyIsNull(element.getAttribute("vendor-name"))); ! jdoExtension.setKey(emptyIsNull(element.getAttribute("key"))); ! jdoExtension.setValue(emptyIsNull(element.getAttribute("value"))); extendable.addExtension(jdoExtension); } *************** *** 204,206 **** --- 211,225 ---- } */ + + static String emptyIsNull(String s) { + if (s == null) { + return s; + } + else if (s.equals("")) { + return null; + } + else { + return s; + } + } } |
From: Dan C. <dch...@us...> - 2006-06-08 17:50:59
|
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10914/src/org/xorm/datastore/xml Modified Files: Tag: dan-no-jdom XMLConnectionInfo.java Removed Files: Tag: dan-no-jdom JDOMDocumentDriver.java JDOMDocumentHolder.java Log Message: branch where JDOM is no more...JDOXML uses W3C DOM --- JDOMDocumentHolder.java DELETED --- --- JDOMDocumentDriver.java DELETED --- Index: XMLConnectionInfo.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLConnectionInfo.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** XMLConnectionInfo.java 8 Jun 2006 17:33:47 -0000 1.3 --- XMLConnectionInfo.java 8 Jun 2006 17:50:54 -0000 1.3.2.1 *************** *** 27,32 **** public class XMLConnectionInfo extends ConnectionInfo { - static final boolean useJDOM = true; - public DatastoreDriver getDriver() { URL url; --- 27,30 ---- *************** *** 37,46 **** throw new RuntimeException(e); } ! if (useJDOM) { ! return new JDOMDocumentDriver(url); ! } ! else { ! return new W3CDocumentDriver(url); ! } } } --- 35,39 ---- throw new RuntimeException(e); } ! return new W3CDocumentDriver(url); } } |
From: Dan C. <dch...@us...> - 2006-06-08 17:33:55
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv4174/src/org/xorm Modified Files: ModelMapping.java Log Message: The XML driver stuff is still hard-coded to use JDOM, but that can be swapped out easily if and when. ModelMapping now uses W3C DOM. Index: ModelMapping.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ModelMapping.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** ModelMapping.java 5 Feb 2006 21:42:47 -0000 1.61 --- ModelMapping.java 8 Jun 2006 17:33:47 -0000 1.62 *************** *** 43,52 **** import javax.sql.DataSource; ! import org.jdom.Document; ! import org.jdom.Element; ! import org.jdom.JDOMException; ! import org.jdom.input.SAXBuilder; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xorm.datastore.Column; --- 43,54 ---- import javax.sql.DataSource; ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; + import org.xml.sax.SAXException; import org.xorm.datastore.Column; *************** *** 298,303 **** String databaseXML = properties.getProperty(DATABASE_XML); if (databaseXML != null) { ! SAXBuilder biff = new SAXBuilder(validateXML); ! biff.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if ("database.dtd".equals(systemId)) { --- 300,312 ---- String databaseXML = properties.getProperty(DATABASE_XML); if (databaseXML != null) { ! DocumentBuilder docBuilder = null; ! try { ! docBuilder = ! DocumentBuilderFactory.newInstance().newDocumentBuilder(); ! } ! catch (javax.xml.parsers.ParserConfigurationException e) { ! throw new RuntimeException(e); ! } ! docBuilder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if ("database.dtd".equals(systemId)) { *************** *** 320,327 **** try { ! Document doc = biff.build(inputSource); ! Element root = doc.getRootElement(); parseTables(root); ! } catch (JDOMException e) { throw new JDOFatalException(I18N.msg("E_parse_db_xml", databaseXML), e); } catch (IOException e) { --- 329,336 ---- try { ! Document doc = docBuilder.parse(inputSource); ! Element root = doc.getDocumentElement(); parseTables(root); ! } catch (SAXException e) { throw new JDOFatalException(I18N.msg("E_parse_db_xml", databaseXML), e); } catch (IOException e) { *************** *** 659,687 **** private void parseTables(Element root) { ! List tables = root.getChildren("table"); ! Iterator i = tables.iterator(); ! while (i.hasNext()) { ! Element element = (Element) i.next(); ! String tableName = element.getAttributeValue("name"); Table table = new Table(tableName); nameToTable.put(tableName, table); ! List columns = element.getChildren("column"); ! Iterator j = columns.iterator(); ! while (j.hasNext()) { ! Element colElement = (Element) j.next(); ! String columnName = colElement.getAttributeValue("name"); Column column = new Column(table, columnName); ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("primary-key"))) { table.setPrimaryKey(column); } ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("read-only"))) { column.setReadOnly(true); } ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("non-null"))) { column.setNonNull(true); } // Is it a sequenced column? ! if (colElement.getAttributeValue("sequence") != null) { ! column.setSequence(colElement.getAttributeValue("sequence")); } else { // Use org.xorm.datastore.option.sequenceNamePattern to set --- 668,695 ---- private void parseTables(Element root) { ! NodeList tables = root.getElementsByTagName("table"); ! for (int t = 0; t < tables.getLength(); ++t) { ! Element element = (Element)tables.item(t); ! String tableName = element.getAttribute("name"); Table table = new Table(tableName); nameToTable.put(tableName, table); ! NodeList columns = element.getElementsByTagName("column"); ! for (int c = 0; c < columns.getLength(); ++c) { ! Element colElement = (Element)columns.item(c); ! String columnName = colElement.getAttribute("name"); Column column = new Column(table, columnName); ! if ("true".equalsIgnoreCase(colElement.getAttribute("primary-key"))) { table.setPrimaryKey(column); } ! if ("true".equalsIgnoreCase(colElement.getAttribute("read-only"))) { column.setReadOnly(true); } ! if ("true".equalsIgnoreCase(colElement.getAttribute("non-null"))) { column.setNonNull(true); } // Is it a sequenced column? ! if (colElement.getAttribute("sequence") != null && ! !colElement.getAttribute("sequence").equals("")) { ! column.setSequence(colElement.getAttribute("sequence")); } else { // Use org.xorm.datastore.option.sequenceNamePattern to set *************** *** 697,706 **** // Is it an autoincremented column? ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("auto"))) { column.setAutoIncremented(true); } // Is it manually typed? ! column.setType(colElement.getAttributeValue("type")); ! column.setFormat(colElement.getAttributeValue("format")); } // columns iterator // map the table for later reference --- 705,718 ---- // Is it an autoincremented column? ! if ("true".equalsIgnoreCase(colElement.getAttribute("auto"))) { column.setAutoIncremented(true); } // Is it manually typed? ! column.setType("".equals(colElement.getAttribute("type")) ? ! null : ! colElement.getAttribute("type")); ! column.setFormat("".equals(colElement.getAttribute("format")) ? ! null : ! colElement.getAttribute("format")); } // columns iterator // map the table for later reference |
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv4174/src/org/xorm/datastore/xml Modified Files: DocumentHolder.java JDOMDocumentDriver.java W3CDocumentDriver.java W3CDocumentHolder.java XMLConnectionInfo.java Log Message: The XML driver stuff is still hard-coded to use JDOM, but that can be swapped out easily if and when. ModelMapping now uses W3C DOM. Index: JDOMDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentDriver.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** JDOMDocumentDriver.java 8 Feb 2006 17:26:28 -0000 1.9 --- JDOMDocumentDriver.java 8 Jun 2006 17:33:47 -0000 1.10 *************** *** 21,24 **** --- 21,25 ---- import java.io.IOException; + import java.net.URL; import java.util.ArrayList; import java.util.Collection; *************** *** 65,70 **** * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(DocumentHolder documentHolder) { ! this.documentHolder = documentHolder; } --- 66,72 ---- * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(URL url) { ! documentHolder = new JDOMDocumentHolder(); ! documentHolder.setURL(url); } *************** *** 73,77 **** */ public void begin(boolean readOnly) { ! document = documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; --- 75,79 ---- */ public void begin(boolean readOnly) { ! document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; Index: XMLConnectionInfo.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLConnectionInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XMLConnectionInfo.java 17 Dec 2002 17:51:09 -0000 1.2 --- XMLConnectionInfo.java 8 Jun 2006 17:33:47 -0000 1.3 *************** *** 27,47 **** public class XMLConnectionInfo extends ConnectionInfo { ! private DocumentHolder documentHolder; ! ! private DocumentHolder getDocumentHolder() { ! if (documentHolder == null) { ! try { ! URL url = new URL(getConnectionURL()); ! documentHolder = new DocumentHolder(url); ! } catch (MalformedURLException e) { ! // TODO ! e.printStackTrace(); ! } ! } ! return documentHolder; ! } ! public DatastoreDriver getDriver() { ! return new JDOMDocumentDriver(getDocumentHolder()); } } --- 27,46 ---- public class XMLConnectionInfo extends ConnectionInfo { ! static final boolean useJDOM = true; ! public DatastoreDriver getDriver() { ! URL url; ! try { ! url = new URL(getConnectionURL()); ! } catch (MalformedURLException e) { ! // TODO ! throw new RuntimeException(e); ! } ! if (useJDOM) { ! return new JDOMDocumentDriver(url); ! } ! else { ! return new W3CDocumentDriver(url); ! } } } Index: DocumentHolder.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/DocumentHolder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DocumentHolder.java 15 Jul 2003 22:53:10 -0000 1.2 --- DocumentHolder.java 8 Jun 2006 17:33:47 -0000 1.3 *************** *** 20,91 **** package org.xorm.datastore.xml; - import java.io.FileOutputStream; - import java.io.IOException; - import java.io.OutputStream; - import java.net.URL; - import java.net.URLConnection; - import java.net.MalformedURLException; - - import org.jdom.Document; - import org.jdom.JDOMException; - import org.jdom.input.SAXBuilder; - import org.jdom.output.XMLOutputter; /** ! * Wraps a JDOM Document and allows transactional access. * ! * @author Wes Biggs */ ! public class DocumentHolder { ! private URL url; ! private Document document; ! ! public DocumentHolder(URL url) { ! this.url = url; ! try { ! document = new SAXBuilder().build(url); ! } catch (JDOMException e) { ! e.printStackTrace(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * Returns a cloned copy of the document. ! */ ! public Document checkout() { ! return (Document) document.clone(); ! } ! ! /** ! * Accepts the changes from the document. If possible, rewrites ! * the content. Changes are synchronized but not checked; if two ! * concurrent threads make different changes, the last one to call ! * checkin() will win. This effectively gives the process a ! * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. ! */ ! public void checkin(Document document) { ! this.document = document; ! ! synchronized (url) { ! OutputStream outputStream = null; ! try { ! if ("file".equals(url.getProtocol())) { ! outputStream = new FileOutputStream(url.getFile()); ! } else { ! // Try to set "doOutput", may not work ! URLConnection connection = url.openConnection(); ! connection.setDoOutput(true); ! outputStream = connection.getOutputStream(); ! } ! new XMLOutputter(" ", true).output(document, outputStream); ! outputStream.flush(); ! outputStream.close(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } // synchronized ! } } --- 20,33 ---- package org.xorm.datastore.xml; import java.net.URL; /** ! * Interface for Document holder objects * ! * @author Dan Checkoway */ ! public interface DocumentHolder { ! void setURL(URL url); ! Object checkout(); ! void checkin(Object document); } |
From: Dan C. <dch...@us...> - 2006-06-08 17:05:24
|
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25548 Modified Files: Tag: dan-w3c-dom DocumentHolder.java JDOMDocumentDriver.java XMLConnectionInfo.java Added Files: Tag: dan-w3c-dom JDOMDocumentHolder.java W3CDocumentDriver.java W3CDocumentHolder.java Log Message: doh...committing on the branch --- NEW FILE: W3CDocumentDriver.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/W3CDocumentDriver.java,v 1.1.2.2 2006/06/08 17:05:17 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Set; import org.xorm.datastore.Row; import org.xorm.datastore.Column; import org.xorm.datastore.Table; import org.xorm.datastore.DataFetchGroup; import org.xorm.datastore.DatastoreDriver; import org.xorm.datastore.DriverException; import org.xorm.query.Condition; import org.xorm.query.Selector; import org.xorm.query.SimpleCondition; import org.xorm.util.TypeConverter; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * A datastore driver that uses an XML document as the datastore. * Datastore XML descriptor files need to specify a column named "." * as the primary key column; table names should match element names. * Data column names should be specified in a limited XPath notation. * Examples are "@name", "description/text()", and ".." for a parent * reference. * * This class relies on the transactional mechanics of the DocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls * checkin(). * * @author Dan Checkoway */ public class W3CDocumentDriver implements DatastoreDriver { private DocumentHolder documentHolder; private Document document; private boolean readOnly; private boolean onlyDidReads; /** * Sets the data source, which must be an instance of DocumentHolder. */ public W3CDocumentDriver(URL url) { documentHolder = new W3CDocumentHolder(); documentHolder.setURL(url); } /** * Begins a transaction by calling checkout on the DocumentHolder. */ public void begin(boolean readOnly) { document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; } /** * Calls checkin() on the DocumentHolder if any write operations * were called during the transaction. */ public void commit() throws DriverException { if (!onlyDidReads) { documentHolder.checkin(document); } document = null; // reacquire in next transaction } public void rollback() { document = null; // reacquire in next transaction } // CRUD methods public void create(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = document.createElement(table.getName()); row.setValue(primaryKey, element); Iterator it = table.getColumns().iterator(); while (it.hasNext()) { Column c = (Column) it.next(); setValue(element, c, row.getValue(c), true); } // If the newly created element is unattached at this point, // it is not contained within any other element tag, and therefore // it must be added under the document root. if (element.getParentNode() == null && !element.isSameNode(document.getDocumentElement())) { document.getDocumentElement().appendChild(element); } } public void update(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = (Element) row.getValue(primaryKey); Iterator it = table.getColumns().iterator(); while (it.hasNext()) { Column c = (Column) it.next(); if (row.isDirty(c)) { setValue(element, c, row.getValue(c), false); } } } public void delete(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = (Element) row.getValue(primaryKey); if (element.getParentNode() != null) { element.getParentNode().removeChild(element); } // TODO: deal with cascaded delete ramifications on the cache } public Collection select(Selector selector, Set extraRows) { Condition condition = selector.getCondition(); Table table = selector.getTable(); Collection xmlResults = null; if (condition == null) { xmlResults = new ArrayList(); xmlResults.add(deriveValue(document.getDocumentElement(), table.getName())); } else if (condition instanceof SimpleCondition) { SimpleCondition sc = (SimpleCondition) condition; Column column = sc.getColumn(); Object value = sc.getValue(); // ".." == (Element) means get all children of an element // with an element name matching the table name. if ("..".equals(column.getName()) && (value instanceof Element)) { Element parent = (Element) value; NodeList children = parent.getElementsByTagName(table.getName()); xmlResults = new ArrayList(); for (int c = 0; c < children.getLength(); ++c) { xmlResults.add(children.item(c)); } } } // Populate the rows ArrayList rows = new ArrayList(); if (xmlResults == null) return rows; // no results Iterator i = xmlResults.iterator(); while (i.hasNext()) { Element element = (Element)i.next(); Row row = new Row(table); populate(row, element); rows.add(row); } return rows; } private void populate(Row row, Element element) { Iterator j = row.getTable().getColumns().iterator(); while (j.hasNext()) { Column c = (Column) j.next(); Object value = deriveValue(element, c.getName()); if (value instanceof String) { // Convert to Java Type Class javaType = XMLType.forName(c.getType()); if (javaType != null) { value = TypeConverter.convertToType(value, javaType, c.getFormat()); } } row.setValue(c, value); } } public int count(Selector selector) { return select(selector, null).size(); } // Path corresponds to a very small subset of abbreviated XPath syntax private Object deriveValue(Element element, String path) { int pos = path.lastIndexOf('/'); if (pos != -1) { element = navigateToElement(element, path, false); path = path.substring(pos + 1); } // attribute if (path.startsWith("@")) { return element.getAttribute(path.substring(1)); } // text node if ("text()".equals(path)) { String text = element.getTextContent(); if (text != null) { text = text.trim(); } return text; } if (".".equals(path)) { return element; } else if ("..".equals(path)) { return element.getParentNode(); } else { return (Element)element.getElementsByTagName(path).item(0); } } /** * Returns the Element indicated by the subpath (everything up to * the last '/'). */ private Element navigateToElement(Element element, String path, boolean create) { int pos = path.indexOf('/'); String pathTail = null; if (pos != -1) { pathTail = path.substring(pos + 1); path = path.substring(0, pos); if ("..".equals(path)) { Node parent = element.getParentNode(); if (parent instanceof Element) { element = (Element)parent; } else { // DAS: What to do? return element; } } else { Element parent = element; element = (Element)element.getElementsByTagName(path).item(0); if (create && (element == null)) { element = document.createElement(path); parent.appendChild(element); } } return navigateToElement(element, pathTail, create); } return element; } private void setValue(Element element, Column c, Object value, boolean create) { String path = c.getName(); if (!(value instanceof Element)) { // Convert value to String value = TypeConverter.convertToType(value, String.class, c.getFormat()); } int pos = path.lastIndexOf('/'); if (pos != -1) { element = navigateToElement(element, path, create); path = path.substring(pos + 1); } // attribute if (path.startsWith("@")) { Attr attr = document.createAttribute(path.substring(1)); attr.setValue((String)value); element.getAttributes().setNamedItem(attr); } else if ("text()".equals(path)) { element.setTextContent((String)value); } else if (".".equals(path)) { // self-reference (primary key) -- ignore } else if ("..".equals(path)) { Element parent = (Element)value; if (element.getParentNode() != null) { element.getParentNode().removeChild(element); } parent.appendChild(element); } else { // Child reference element.appendChild((Element)value); } } } --- NEW FILE: JDOMDocumentHolder.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentHolder.java,v 1.1.2.2 2006/06/08 17:05:17 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; /** * Wraps a JDOM Document and allows transactional access. * * @author Wes Biggs */ public class JDOMDocumentHolder implements DocumentHolder { private URL url; private Document document; public JDOMDocumentHolder() {} public void setURL(URL url) { this.url = url; try { document = new SAXBuilder().build(url); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * Returns a cloned copy of the document. */ public Object checkout() { return document.clone(); } /** * Accepts the changes from the document. If possible, rewrites * the content. Changes are synchronized but not checked; if two * concurrent threads make different changes, the last one to call * checkin() will win. This effectively gives the process a * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. */ public void checkin(Object _document) { this.document = (Document)_document; synchronized (url) { OutputStream outputStream = null; try { if ("file".equals(url.getProtocol())) { outputStream = new FileOutputStream(url.getFile()); } else { // Try to set "doOutput", may not work URLConnection connection = url.openConnection(); connection.setDoOutput(true); outputStream = connection.getOutputStream(); } new XMLOutputter(" ", true).output(this.document, outputStream); outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } // synchronized } } --- NEW FILE: W3CDocumentHolder.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/W3CDocumentHolder.java,v 1.1.2.2 2006/06/08 17:05:17 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.SAXException; /** * Wraps a W3C Document and allows transactional access. * * @author Dan Checkoway */ public class W3CDocumentHolder implements DocumentHolder { private DocumentBuilder docBuilder; private URL url; private Document document; public W3CDocumentHolder() {} public void setURL(URL url) { this.url = url; try { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); document = docBuilder.parse(url.openStream()); } catch (javax.xml.parsers.ParserConfigurationException e) { e.printStackTrace(); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } } /** * Returns a cloned copy of the document. */ public Object checkout() { Document copy = docBuilder.newDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new DOMResult(copy)); } catch (javax.xml.transform.TransformerException e) { e.printStackTrace(); } return copy; } /** * Accepts the changes from the document. If possible, rewrites * the content. Changes are synchronized but not checked; if two * concurrent threads make different changes, the last one to call * checkin() will win. This effectively gives the process a * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. */ public void checkin(Object _document) { this.document = (Document)_document; synchronized (url) { OutputStream outputStream = null; try { if ("file".equals(url.getProtocol())) { outputStream = new FileOutputStream(url.getFile()); } else { // Try to set "doOutput", may not work URLConnection connection = url.openConnection(); connection.setDoOutput(true); outputStream = connection.getOutputStream(); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new StreamResult(outputStream)); outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } catch (javax.xml.transform.TransformerException e) { e.printStackTrace(); } } // synchronized } } Index: DocumentHolder.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/DocumentHolder.java,v retrieving revision 1.2.4.1 retrieving revision 1.2.4.2 diff -C2 -d -r1.2.4.1 -r1.2.4.2 *** DocumentHolder.java 8 Jun 2006 17:00:50 -0000 1.2.4.1 --- DocumentHolder.java 8 Jun 2006 17:05:17 -0000 1.2.4.2 *************** *** 20,33 **** package org.xorm.datastore.xml; import java.net.URL; /** ! * Generic abstract base class for XML document holders * ! * @author Dan Checkoway */ ! public interface DocumentHolder { ! void setURL(URL url); ! Object checkout(); ! void checkin(Object document); } --- 20,91 ---- package org.xorm.datastore.xml; + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.OutputStream; + import java.net.URL; + import java.net.URLConnection; + import java.net.MalformedURLException; + + import org.jdom.Document; + import org.jdom.JDOMException; + import org.jdom.input.SAXBuilder; + import org.jdom.output.XMLOutputter; /** ! * Wraps a JDOM Document and allows transactional access. * ! * @author Wes Biggs */ ! public class DocumentHolder { ! private URL url; ! private Document document; ! ! public DocumentHolder(URL url) { ! this.url = url; ! try { ! document = new SAXBuilder().build(url); ! } catch (JDOMException e) { ! e.printStackTrace(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * Returns a cloned copy of the document. ! */ ! public Document checkout() { ! return (Document) document.clone(); ! } ! ! /** ! * Accepts the changes from the document. If possible, rewrites ! * the content. Changes are synchronized but not checked; if two ! * concurrent threads make different changes, the last one to call ! * checkin() will win. This effectively gives the process a ! * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. ! */ ! public void checkin(Document document) { ! this.document = document; ! ! synchronized (url) { ! OutputStream outputStream = null; ! try { ! if ("file".equals(url.getProtocol())) { ! outputStream = new FileOutputStream(url.getFile()); ! } else { ! // Try to set "doOutput", may not work ! URLConnection connection = url.openConnection(); ! connection.setDoOutput(true); ! outputStream = connection.getOutputStream(); ! } ! new XMLOutputter(" ", true).output(document, outputStream); ! outputStream.flush(); ! outputStream.close(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } // synchronized ! } } Index: XMLConnectionInfo.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLConnectionInfo.java,v retrieving revision 1.2.6.1 retrieving revision 1.2.6.2 diff -C2 -d -r1.2.6.1 -r1.2.6.2 *** XMLConnectionInfo.java 8 Jun 2006 17:00:50 -0000 1.2.6.1 --- XMLConnectionInfo.java 8 Jun 2006 17:05:17 -0000 1.2.6.2 *************** *** 27,47 **** public class XMLConnectionInfo extends ConnectionInfo { public DatastoreDriver getDriver() { ! try { ! URL url = new URL(getConnectionURL()); ! /* ! if (use JDOM) { ! return new JDOMDocumentDriver(url); ! } ! else if (use W3C) { ! */ ! return new W3CDocumentDriver(url); ! /* ! } ! */ ! } catch (MalformedURLException e) { ! // TODO ! throw new RuntimeException(e); ! } } } --- 27,47 ---- public class XMLConnectionInfo extends ConnectionInfo { + private DocumentHolder documentHolder; + + private DocumentHolder getDocumentHolder() { + if (documentHolder == null) { + try { + URL url = new URL(getConnectionURL()); + documentHolder = new DocumentHolder(url); + } catch (MalformedURLException e) { + // TODO + e.printStackTrace(); + } + } + return documentHolder; + } + public DatastoreDriver getDriver() { ! return new JDOMDocumentDriver(getDocumentHolder()); } } Index: JDOMDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentDriver.java,v retrieving revision 1.9.2.1 retrieving revision 1.9.2.2 diff -C2 -d -r1.9.2.1 -r1.9.2.2 *** JDOMDocumentDriver.java 8 Jun 2006 17:00:50 -0000 1.9.2.1 --- JDOMDocumentDriver.java 8 Jun 2006 17:05:17 -0000 1.9.2.2 *************** *** 21,25 **** import java.io.IOException; - import java.net.URL; import java.util.ArrayList; import java.util.Collection; --- 21,24 ---- *************** *** 50,54 **** * reference. * ! * This class relies on the transactional mechanics of the JDOMDocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls --- 49,53 ---- * reference. * ! * This class relies on the transactional mechanics of the DocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls *************** *** 58,62 **** */ public class JDOMDocumentDriver implements DatastoreDriver { ! private JDOMDocumentHolder documentHolder; private Document document; private boolean readOnly; --- 57,61 ---- */ public class JDOMDocumentDriver implements DatastoreDriver { ! private DocumentHolder documentHolder; private Document document; private boolean readOnly; *************** *** 66,72 **** * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(URL url) { ! documentHolder = new JDOMDocumentHolder(); ! documentHolder.setURL(url); } --- 65,70 ---- * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(DocumentHolder documentHolder) { ! this.documentHolder = documentHolder; } *************** *** 75,79 **** */ public void begin(boolean readOnly) { ! document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; --- 73,77 ---- */ public void begin(boolean readOnly) { ! document = documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; |
From: Dan C. <dch...@us...> - 2006-06-08 17:01:17
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23547/src/org/xorm Modified Files: Tag: dan-w3c-dom ModelMapping.java Log Message: Doing this on a branch... Added W3C DOM support in an effort (perhaps) to rid XORM of JDOM. Index: ModelMapping.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ModelMapping.java,v retrieving revision 1.61 retrieving revision 1.61.2.1 diff -C2 -d -r1.61 -r1.61.2.1 *** ModelMapping.java 5 Feb 2006 21:42:47 -0000 1.61 --- ModelMapping.java 8 Jun 2006 17:00:49 -0000 1.61.2.1 *************** *** 43,52 **** import javax.sql.DataSource; ! import org.jdom.Document; ! import org.jdom.Element; ! import org.jdom.JDOMException; ! import org.jdom.input.SAXBuilder; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xorm.datastore.Column; --- 43,54 ---- import javax.sql.DataSource; ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; + import org.xml.sax.SAXException; import org.xorm.datastore.Column; *************** *** 298,303 **** String databaseXML = properties.getProperty(DATABASE_XML); if (databaseXML != null) { ! SAXBuilder biff = new SAXBuilder(validateXML); ! biff.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if ("database.dtd".equals(systemId)) { --- 300,312 ---- String databaseXML = properties.getProperty(DATABASE_XML); if (databaseXML != null) { ! DocumentBuilder docBuilder = null; ! try { ! docBuilder = ! DocumentBuilderFactory.newInstance().newDocumentBuilder(); ! } ! catch (javax.xml.parsers.ParserConfigurationException e) { ! throw new RuntimeException(e); ! } ! docBuilder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if ("database.dtd".equals(systemId)) { *************** *** 320,327 **** try { ! Document doc = biff.build(inputSource); ! Element root = doc.getRootElement(); parseTables(root); ! } catch (JDOMException e) { throw new JDOFatalException(I18N.msg("E_parse_db_xml", databaseXML), e); } catch (IOException e) { --- 329,336 ---- try { ! Document doc = docBuilder.parse(inputSource); ! Element root = doc.getDocumentElement(); parseTables(root); ! } catch (SAXException e) { throw new JDOFatalException(I18N.msg("E_parse_db_xml", databaseXML), e); } catch (IOException e) { *************** *** 659,687 **** private void parseTables(Element root) { ! List tables = root.getChildren("table"); ! Iterator i = tables.iterator(); ! while (i.hasNext()) { ! Element element = (Element) i.next(); ! String tableName = element.getAttributeValue("name"); Table table = new Table(tableName); nameToTable.put(tableName, table); ! List columns = element.getChildren("column"); ! Iterator j = columns.iterator(); ! while (j.hasNext()) { ! Element colElement = (Element) j.next(); ! String columnName = colElement.getAttributeValue("name"); Column column = new Column(table, columnName); ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("primary-key"))) { table.setPrimaryKey(column); } ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("read-only"))) { column.setReadOnly(true); } ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("non-null"))) { column.setNonNull(true); } // Is it a sequenced column? ! if (colElement.getAttributeValue("sequence") != null) { ! column.setSequence(colElement.getAttributeValue("sequence")); } else { // Use org.xorm.datastore.option.sequenceNamePattern to set --- 668,695 ---- private void parseTables(Element root) { ! NodeList tables = root.getElementsByTagName("table"); ! for (int t = 0; t < tables.getLength(); ++t) { ! Element element = (Element)tables.item(t); ! String tableName = element.getAttribute("name"); Table table = new Table(tableName); nameToTable.put(tableName, table); ! NodeList columns = element.getElementsByTagName("column"); ! for (int c = 0; c < columns.getLength(); ++c) { ! Element colElement = (Element)columns.item(c); ! String columnName = colElement.getAttribute("name"); Column column = new Column(table, columnName); ! if ("true".equalsIgnoreCase(colElement.getAttribute("primary-key"))) { table.setPrimaryKey(column); } ! if ("true".equalsIgnoreCase(colElement.getAttribute("read-only"))) { column.setReadOnly(true); } ! if ("true".equalsIgnoreCase(colElement.getAttribute("non-null"))) { column.setNonNull(true); } // Is it a sequenced column? ! if (colElement.getAttribute("sequence") != null && ! !colElement.getAttribute("sequence").equals("")) { ! column.setSequence(colElement.getAttribute("sequence")); } else { // Use org.xorm.datastore.option.sequenceNamePattern to set *************** *** 697,706 **** // Is it an autoincremented column? ! if ("true".equalsIgnoreCase(colElement.getAttributeValue("auto"))) { column.setAutoIncremented(true); } // Is it manually typed? ! column.setType(colElement.getAttributeValue("type")); ! column.setFormat(colElement.getAttributeValue("format")); } // columns iterator // map the table for later reference --- 705,718 ---- // Is it an autoincremented column? ! if ("true".equalsIgnoreCase(colElement.getAttribute("auto"))) { column.setAutoIncremented(true); } // Is it manually typed? ! column.setType("".equals(colElement.getAttribute("type")) ? ! null : ! colElement.getAttribute("type")); ! column.setFormat("".equals(colElement.getAttribute("format")) ? ! null : ! colElement.getAttribute("format")); } // columns iterator // map the table for later reference |
From: Dan C. <dch...@us...> - 2006-06-08 17:01:01
|
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23547/src/org/xorm/datastore/xml Modified Files: Tag: dan-w3c-dom DocumentHolder.java JDOMDocumentDriver.java XMLConnectionInfo.java Added Files: JDOMDocumentHolder.java W3CDocumentDriver.java W3CDocumentHolder.java Log Message: Doing this on a branch... Added W3C DOM support in an effort (perhaps) to rid XORM of JDOM. --- NEW FILE: W3CDocumentDriver.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/W3CDocumentDriver.java,v 1.1 2006/06/08 17:00:50 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Set; import org.xorm.datastore.Row; import org.xorm.datastore.Column; import org.xorm.datastore.Table; import org.xorm.datastore.DataFetchGroup; import org.xorm.datastore.DatastoreDriver; import org.xorm.datastore.DriverException; import org.xorm.query.Condition; import org.xorm.query.Selector; import org.xorm.query.SimpleCondition; import org.xorm.util.TypeConverter; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * A datastore driver that uses an XML document as the datastore. * Datastore XML descriptor files need to specify a column named "." * as the primary key column; table names should match element names. * Data column names should be specified in a limited XPath notation. * Examples are "@name", "description/text()", and ".." for a parent * reference. * * This class relies on the transactional mechanics of the DocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls * checkin(). * * @author Dan Checkoway */ public class W3CDocumentDriver implements DatastoreDriver { private DocumentHolder documentHolder; private Document document; private boolean readOnly; private boolean onlyDidReads; /** * Sets the data source, which must be an instance of DocumentHolder. */ public W3CDocumentDriver(URL url) { documentHolder = new W3CDocumentHolder(); documentHolder.setURL(url); } /** * Begins a transaction by calling checkout on the DocumentHolder. */ public void begin(boolean readOnly) { document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; } /** * Calls checkin() on the DocumentHolder if any write operations * were called during the transaction. */ public void commit() throws DriverException { if (!onlyDidReads) { documentHolder.checkin(document); } document = null; // reacquire in next transaction } public void rollback() { document = null; // reacquire in next transaction } // CRUD methods public void create(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = document.createElement(table.getName()); row.setValue(primaryKey, element); Iterator it = table.getColumns().iterator(); while (it.hasNext()) { Column c = (Column) it.next(); setValue(element, c, row.getValue(c), true); } // If the newly created element is unattached at this point, // it is not contained within any other element tag, and therefore // it must be added under the document root. if (element.getParentNode() == null && !element.isSameNode(document.getDocumentElement())) { document.getDocumentElement().appendChild(element); } } public void update(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = (Element) row.getValue(primaryKey); Iterator it = table.getColumns().iterator(); while (it.hasNext()) { Column c = (Column) it.next(); if (row.isDirty(c)) { setValue(element, c, row.getValue(c), false); } } } public void delete(Row row) { onlyDidReads = false; Table table = row.getTable(); Column primaryKey = table.getPrimaryKey(); Element element = (Element) row.getValue(primaryKey); if (element.getParentNode() != null) { element.getParentNode().removeChild(element); } // TODO: deal with cascaded delete ramifications on the cache } public Collection select(Selector selector, Set extraRows) { Condition condition = selector.getCondition(); Table table = selector.getTable(); Collection xmlResults = null; if (condition == null) { xmlResults = new ArrayList(); xmlResults.add(deriveValue(document.getDocumentElement(), table.getName())); } else if (condition instanceof SimpleCondition) { SimpleCondition sc = (SimpleCondition) condition; Column column = sc.getColumn(); Object value = sc.getValue(); // ".." == (Element) means get all children of an element // with an element name matching the table name. if ("..".equals(column.getName()) && (value instanceof Element)) { Element parent = (Element) value; NodeList children = parent.getElementsByTagName(table.getName()); xmlResults = new ArrayList(); for (int c = 0; c < children.getLength(); ++c) { xmlResults.add(children.item(c)); } } } // Populate the rows ArrayList rows = new ArrayList(); if (xmlResults == null) return rows; // no results Iterator i = xmlResults.iterator(); while (i.hasNext()) { Element element = (Element)i.next(); Row row = new Row(table); populate(row, element); rows.add(row); } return rows; } private void populate(Row row, Element element) { Iterator j = row.getTable().getColumns().iterator(); while (j.hasNext()) { Column c = (Column) j.next(); Object value = deriveValue(element, c.getName()); if (value instanceof String) { // Convert to Java Type Class javaType = XMLType.forName(c.getType()); if (javaType != null) { value = TypeConverter.convertToType(value, javaType, c.getFormat()); } } row.setValue(c, value); } } public int count(Selector selector) { return select(selector, null).size(); } // Path corresponds to a very small subset of abbreviated XPath syntax private Object deriveValue(Element element, String path) { int pos = path.lastIndexOf('/'); if (pos != -1) { element = navigateToElement(element, path, false); path = path.substring(pos + 1); } // attribute if (path.startsWith("@")) { return element.getAttribute(path.substring(1)); } // text node if ("text()".equals(path)) { String text = element.getTextContent(); if (text != null) { text = text.trim(); } return text; } if (".".equals(path)) { return element; } else if ("..".equals(path)) { return element.getParentNode(); } else { return (Element)element.getElementsByTagName(path).item(0); } } /** * Returns the Element indicated by the subpath (everything up to * the last '/'). */ private Element navigateToElement(Element element, String path, boolean create) { int pos = path.indexOf('/'); String pathTail = null; if (pos != -1) { pathTail = path.substring(pos + 1); path = path.substring(0, pos); if ("..".equals(path)) { Node parent = element.getParentNode(); if (parent instanceof Element) { element = (Element)parent; } else { // DAS: What to do? return element; } } else { Element parent = element; element = (Element)element.getElementsByTagName(path).item(0); if (create && (element == null)) { element = document.createElement(path); parent.appendChild(element); } } return navigateToElement(element, pathTail, create); } return element; } private void setValue(Element element, Column c, Object value, boolean create) { String path = c.getName(); if (!(value instanceof Element)) { // Convert value to String value = TypeConverter.convertToType(value, String.class, c.getFormat()); } int pos = path.lastIndexOf('/'); if (pos != -1) { element = navigateToElement(element, path, create); path = path.substring(pos + 1); } // attribute if (path.startsWith("@")) { Attr attr = document.createAttribute(path.substring(1)); attr.setValue((String)value); element.getAttributes().setNamedItem(attr); } else if ("text()".equals(path)) { element.setTextContent((String)value); } else if (".".equals(path)) { // self-reference (primary key) -- ignore } else if ("..".equals(path)) { Element parent = (Element)value; if (element.getParentNode() != null) { element.getParentNode().removeChild(element); } parent.appendChild(element); } else { // Child reference element.appendChild((Element)value); } } } --- NEW FILE: JDOMDocumentHolder.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentHolder.java,v 1.1 2006/06/08 17:00:50 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; /** * Wraps a JDOM Document and allows transactional access. * * @author Wes Biggs */ public class JDOMDocumentHolder implements DocumentHolder { private URL url; private Document document; public JDOMDocumentHolder() {} public void setURL(URL url) { this.url = url; try { document = new SAXBuilder().build(url); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * Returns a cloned copy of the document. */ public Object checkout() { return document.clone(); } /** * Accepts the changes from the document. If possible, rewrites * the content. Changes are synchronized but not checked; if two * concurrent threads make different changes, the last one to call * checkin() will win. This effectively gives the process a * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. */ public void checkin(Object _document) { this.document = (Document)_document; synchronized (url) { OutputStream outputStream = null; try { if ("file".equals(url.getProtocol())) { outputStream = new FileOutputStream(url.getFile()); } else { // Try to set "doOutput", may not work URLConnection connection = url.openConnection(); connection.setDoOutput(true); outputStream = connection.getOutputStream(); } new XMLOutputter(" ", true).output(this.document, outputStream); outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } // synchronized } } --- NEW FILE: W3CDocumentHolder.java --- /* $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/W3CDocumentHolder.java,v 1.1 2006/06/08 17:00:50 dcheckoway Exp $ This file is part of XORM. XORM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. XORM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XORM; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xorm.datastore.xml; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.SAXException; /** * Wraps a W3C Document and allows transactional access. * * @author Dan Checkoway */ public class W3CDocumentHolder implements DocumentHolder { private DocumentBuilder docBuilder; private URL url; private Document document; public W3CDocumentHolder() {} public void setURL(URL url) { this.url = url; try { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); document = docBuilder.parse(url.openStream()); } catch (javax.xml.parsers.ParserConfigurationException e) { e.printStackTrace(); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } } /** * Returns a cloned copy of the document. */ public Object checkout() { Document copy = docBuilder.newDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new DOMResult(copy)); } catch (javax.xml.transform.TransformerException e) { e.printStackTrace(); } return copy; } /** * Accepts the changes from the document. If possible, rewrites * the content. Changes are synchronized but not checked; if two * concurrent threads make different changes, the last one to call * checkin() will win. This effectively gives the process a * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. */ public void checkin(Object _document) { this.document = (Document)_document; synchronized (url) { OutputStream outputStream = null; try { if ("file".equals(url.getProtocol())) { outputStream = new FileOutputStream(url.getFile()); } else { // Try to set "doOutput", may not work URLConnection connection = url.openConnection(); connection.setDoOutput(true); outputStream = connection.getOutputStream(); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new StreamResult(outputStream)); outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } catch (javax.xml.transform.TransformerException e) { e.printStackTrace(); } } // synchronized } } Index: DocumentHolder.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/DocumentHolder.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** DocumentHolder.java 15 Jul 2003 22:53:10 -0000 1.2 --- DocumentHolder.java 8 Jun 2006 17:00:50 -0000 1.2.4.1 *************** *** 20,91 **** package org.xorm.datastore.xml; - import java.io.FileOutputStream; - import java.io.IOException; - import java.io.OutputStream; - import java.net.URL; - import java.net.URLConnection; - import java.net.MalformedURLException; - - import org.jdom.Document; - import org.jdom.JDOMException; - import org.jdom.input.SAXBuilder; - import org.jdom.output.XMLOutputter; /** ! * Wraps a JDOM Document and allows transactional access. * ! * @author Wes Biggs */ ! public class DocumentHolder { ! private URL url; ! private Document document; ! ! public DocumentHolder(URL url) { ! this.url = url; ! try { ! document = new SAXBuilder().build(url); ! } catch (JDOMException e) { ! e.printStackTrace(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * Returns a cloned copy of the document. ! */ ! public Document checkout() { ! return (Document) document.clone(); ! } ! ! /** ! * Accepts the changes from the document. If possible, rewrites ! * the content. Changes are synchronized but not checked; if two ! * concurrent threads make different changes, the last one to call ! * checkin() will win. This effectively gives the process a ! * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. ! */ ! public void checkin(Document document) { ! this.document = document; ! ! synchronized (url) { ! OutputStream outputStream = null; ! try { ! if ("file".equals(url.getProtocol())) { ! outputStream = new FileOutputStream(url.getFile()); ! } else { ! // Try to set "doOutput", may not work ! URLConnection connection = url.openConnection(); ! connection.setDoOutput(true); ! outputStream = connection.getOutputStream(); ! } ! new XMLOutputter(" ", true).output(document, outputStream); ! outputStream.flush(); ! outputStream.close(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } // synchronized ! } } --- 20,33 ---- package org.xorm.datastore.xml; import java.net.URL; /** ! * Generic abstract base class for XML document holders * ! * @author Dan Checkoway */ ! public interface DocumentHolder { ! void setURL(URL url); ! Object checkout(); ! void checkin(Object document); } Index: XMLConnectionInfo.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLConnectionInfo.java,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -C2 -d -r1.2 -r1.2.6.1 *** XMLConnectionInfo.java 17 Dec 2002 17:51:09 -0000 1.2 --- XMLConnectionInfo.java 8 Jun 2006 17:00:50 -0000 1.2.6.1 *************** *** 27,47 **** public class XMLConnectionInfo extends ConnectionInfo { - private DocumentHolder documentHolder; - - private DocumentHolder getDocumentHolder() { - if (documentHolder == null) { - try { - URL url = new URL(getConnectionURL()); - documentHolder = new DocumentHolder(url); - } catch (MalformedURLException e) { - // TODO - e.printStackTrace(); - } - } - return documentHolder; - } - public DatastoreDriver getDriver() { ! return new JDOMDocumentDriver(getDocumentHolder()); } } --- 27,47 ---- public class XMLConnectionInfo extends ConnectionInfo { public DatastoreDriver getDriver() { ! try { ! URL url = new URL(getConnectionURL()); ! /* ! if (use JDOM) { ! return new JDOMDocumentDriver(url); ! } ! else if (use W3C) { ! */ ! return new W3CDocumentDriver(url); ! /* ! } ! */ ! } catch (MalformedURLException e) { ! // TODO ! throw new RuntimeException(e); ! } } } Index: JDOMDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentDriver.java,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -C2 -d -r1.9 -r1.9.2.1 *** JDOMDocumentDriver.java 8 Feb 2006 17:26:28 -0000 1.9 --- JDOMDocumentDriver.java 8 Jun 2006 17:00:50 -0000 1.9.2.1 *************** *** 21,24 **** --- 21,25 ---- import java.io.IOException; + import java.net.URL; import java.util.ArrayList; import java.util.Collection; *************** *** 49,53 **** * reference. * ! * This class relies on the transactional mechanics of the DocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls --- 50,54 ---- * reference. * ! * This class relies on the transactional mechanics of the JDOMDocumentHolder * class. At the beginning of each transaction, it acquires a document * by calling checkout(); upon commit (but not rollback) it calls *************** *** 57,61 **** */ public class JDOMDocumentDriver implements DatastoreDriver { ! private DocumentHolder documentHolder; private Document document; private boolean readOnly; --- 58,62 ---- */ public class JDOMDocumentDriver implements DatastoreDriver { ! private JDOMDocumentHolder documentHolder; private Document document; private boolean readOnly; *************** *** 65,70 **** * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(DocumentHolder documentHolder) { ! this.documentHolder = documentHolder; } --- 66,72 ---- * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(URL url) { ! documentHolder = new JDOMDocumentHolder(); ! documentHolder.setURL(url); } *************** *** 73,77 **** */ public void begin(boolean readOnly) { ! document = documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; --- 75,79 ---- */ public void begin(boolean readOnly) { ! document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; |
From: Douglas A. S. <sei...@us...> - 2006-02-10 18:51:38
|
Update of /cvsroot/xorm/xorm/unit-tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14163/unit-tests Modified Files: README Log Message: Add note regarding necessity of putting junit.jar in $ANT_HOME/lib before running tests. Index: README =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/README,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** README 6 Jan 2006 20:48:56 -0000 1.5 --- README 10 Feb 2006 18:51:30 -0000 1.6 *************** *** 15,20 **** > ant dist ! in the top level xorm directory. Then switch to the unit-tests ! directory and run > ant clean gen-jdo test --- 15,21 ---- > ant dist ! in the top level xorm directory. Also ensure that you have copied ! the junit.jar XORM's lib directory to $ANT_HOME/lib. Then switch to ! the unit-tests directory and run > ant clean gen-jdo test |
From: Wes B. <wb...@us...> - 2006-02-10 16:48:46
|
Update of /cvsroot/xorm/xorm/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15020 Modified Files: changelog.html Log Message: Keeping up with changelog. Index: changelog.html =================================================================== RCS file: /cvsroot/xorm/xorm/docs/changelog.html,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** changelog.html 25 Feb 2005 00:21:24 -0000 1.20 --- changelog.html 10 Feb 2006 16:48:36 -0000 1.21 *************** *** 52,55 **** --- 52,56 ---- <TR> <TD> + <!-- Begin Main Content --> <h2> <a name="beta7">Current CVS Version (Work in Progress)</a> *************** *** 59,72 **** <li><b>General:</b></li> <ul> ! <li>Modified some source-level constructs to compile cleanly with J2SE 5.0 javac.</li> <li>Fixed problems handling hollow objects that get cloned.</li> <li>Allow already-transactional objects to be the target of makePersistent().</li> <li>Modifications to ordering of objects for datastore flush; fixes some problems with object graphs that contain circular references.</li> <li>Only mark an instance dirty if a change that needs to be reflected in the datastore is made.</li> - <li>New property "org.xorm.option.TestConnectionOnStartup" can be selected to report datastore information and immediately connect with failfast behavior.</li> <li>Provide very primitive concurrency checks for multiple threads using the same Transaction (if multithreaded option is set).</li> <li>Support the JDO 1.0.1 conventions for finding a .jdo metadata file. Support for the legacy XORM method is still included but prints a warning.</li> <li>Fix a bug with using the XORM datastore-level "order-by" option for many-to-many relationships.</li> ! <li>Added methods to CodeQuery/CodeParser to better handle null values used as parameters.</li> </ul> <li><b>SQL Datastore:</b></li> --- 60,79 ---- <li><b>General:</b></li> <ul> ! <li>Modified some source-level constructs to compile cleanly with JDK 1.5 javac.</li> <li>Fixed problems handling hollow objects that get cloned.</li> <li>Allow already-transactional objects to be the target of makePersistent().</li> <li>Modifications to ordering of objects for datastore flush; fixes some problems with object graphs that contain circular references.</li> <li>Only mark an instance dirty if a change that needs to be reflected in the datastore is made.</li> <li>Provide very primitive concurrency checks for multiple threads using the same Transaction (if multithreaded option is set).</li> + <li>Added methods to CodeQuery/CodeParser to better handle null values used as parameters.</li> + <li>Upgraded to JDOM 1.0.</li> + <li>Added new testsuite framework and some basic regression tests. No longer requires user to configure a database (uses included HSQL). See the README in directory unit-tests.</li> + </ul> + <li><b>Configuration:</b></li> + <ul> + <li>New property "org.xorm.option.TestConnectionOnStartup" can be selected to report datastore information and immediately connect with failfast behavior.</li> <li>Support the JDO 1.0.1 conventions for finding a .jdo metadata file. Support for the legacy XORM method is still included but prints a warning.</li> <li>Fix a bug with using the XORM datastore-level "order-by" option for many-to-many relationships.</li> ! <li>Fixed issue where key="ordering" was ignored on a filtered relationship.</li> </ul> <li><b>SQL Datastore:</b></li> *************** *** 74,81 **** <li>Made the DISTINCT keyword configurable per query when using SQLCondition.</li> <li>Ensure all PreparedStatements are closed when no longer needed.</li> </ul> </ul> - <!-- Begin Main Content --> <h2> <a name="beta6">Beta 6 (30 May 2004)</a> --- 81,88 ---- <li>Made the DISTINCT keyword configurable per query when using SQLCondition.</li> <li>Ensure all PreparedStatements are closed when no longer needed.</li> + <li>Added option for SybaseDriver. "org.xorm.datastore.sql.SybaseDriver.maxVarcharLength" defaults to 255 but can be overridden to specify the size at which the code will truncate strings in columns marked as (or assumed to be) varchars.</li> </ul> </ul> <h2> <a name="beta6">Beta 6 (30 May 2004)</a> |
From: Wes B. <wb...@us...> - 2006-02-08 19:14:17
|
Update of /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31049 Modified Files: StateTestCase.java Log Message: Add some tests related to recent issues with nontransactional persistent objects and deletion. Index: StateTestCase.java =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic/StateTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StateTestCase.java 27 Oct 2005 23:18:38 -0000 1.1 --- StateTestCase.java 8 Feb 2006 19:14:09 -0000 1.2 *************** *** 10,13 **** --- 10,14 ---- import javax.jdo.JDOHelper; + import javax.jdo.JDOObjectNotFoundException; import javax.jdo.spi.JDOImplHelper; import javax.jdo.spi.PersistenceCapable; *************** *** 109,112 **** --- 110,176 ---- } + public void testPersistentNontransactional() { + mManager.currentTransaction().begin(); + Baz pc = (Baz) XORM.newInstance(mManager, Baz.class); + pc.setName("Luka"); + mManager.makePersistent(pc); + mManager.currentTransaction().commit(); + + assertTrue("IsPersistent should be true", + JDOHelper.isPersistent(pc)); + assertFalse("IsTransactional should be false", + JDOHelper.isTransactional(pc)); + + assertTrue("Can read value back after commit", + "Luka".equals(pc.getName())); + assertFalse("IsTransactional is still false", + JDOHelper.isTransactional(pc)); + + mManager.currentTransaction().begin(); + + pc.getName(); + assertTrue("IsTransactional is now true", + JDOHelper.isTransactional(pc)); + + mManager.currentTransaction().commit(); + } + + /** + * Tests that a persistent nontransactional object + * is properly enlisted in a transaction and deleted + * from the database. + */ + public void testDeletePersistentNontransactional() { + mManager.currentTransaction().begin(); + Baz pc = (Baz) XORM.newInstance(mManager, Baz.class); + pc.setName("Luka"); + mManager.makePersistent(pc); + mManager.currentTransaction().commit(); + + Object oid = JDOHelper.getObjectId(pc); + + // Make sure it's there in the DB + Baz pc2 = (Baz) mManager.getObjectById(oid, true); + assertNotNull("Object should exist in the database", + pc2); + + // Start a new transaction to delete + mManager.currentTransaction().begin(); + mManager.deletePersistent(pc); + mManager.currentTransaction().commit(); + + // See if we can read it now + JDOObjectNotFoundException expected = null; + try { + Baz pc3 = (Baz) mManager.getObjectById(oid, true); + } catch (JDOObjectNotFoundException e) { + expected = e; + } + + assertNotNull("Retrieving deleted object should throw JDOObjectNotFoundException", + expected); + + } + /** * Asserts that an object fulfills all requirements |
From: Douglas A. S. <sei...@us...> - 2006-02-08 17:26:39
|
Update of /cvsroot/xorm/xorm/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9840/lib Modified Files: jdom.jar Log Message: Upgrade to JDOM 1.0. Add some parent/child creation in same tx unit tests. Index: jdom.jar =================================================================== RCS file: /cvsroot/xorm/xorm/lib/jdom.jar,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 Binary files /tmp/cvsjixfGf and /tmp/cvsa4JSZa differ |
From: Douglas A. S. <sei...@us...> - 2006-02-08 17:26:37
|
Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9840/src/org/xorm/datastore/xml Modified Files: JDOMDocumentDriver.java Log Message: Upgrade to JDOM 1.0. Add some parent/child creation in same tx unit tests. Index: JDOMDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentDriver.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** JDOMDocumentDriver.java 14 Aug 2003 05:46:41 -0000 1.8 --- JDOMDocumentDriver.java 8 Feb 2006 17:26:28 -0000 1.9 *************** *** 39,42 **** --- 39,43 ---- import org.jdom.Document; import org.jdom.Element; + import org.jdom.Parent; /** *************** *** 226,247 **** */ private Element navigateToElement(Element element, String path, boolean create) { ! int pos = path.indexOf('/'); ! String pathTail = null; ! if (pos != -1) { ! pathTail = path.substring(pos + 1); ! path = path.substring(0, pos); ! if ("..".equals(path)) { ! element = element.getParent(); ! } else { ! Element parent = element; ! element = element.getChild(path); ! if (create && (element == null)) { ! element = new Element(path); ! parent.addContent(element); ! } ! } ! return navigateToElement(element, pathTail, create); ! } ! return element; } --- 227,254 ---- */ private Element navigateToElement(Element element, String path, boolean create) { ! int pos = path.indexOf('/'); ! String pathTail = null; ! if (pos != -1) { ! pathTail = path.substring(pos + 1); ! path = path.substring(0, pos); ! if ("..".equals(path)) { ! Parent parent = element.getParent(); ! if (parent instanceof Element) { ! element = (Element) parent; ! } else { ! // DAS: What to do? ! return element; ! } ! } else { ! Element parent = element; ! element = element.getChild(path); ! if (create && (element == null)) { ! element = new Element(path); ! parent.addContent(element); ! } ! } ! return navigateToElement(element, pathTail, create); ! } ! return element; } |
From: Douglas A. S. <sei...@us...> - 2006-02-08 17:26:37
|
Update of /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/relationships In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9840/unit-tests/src/java/org/xorm/test/relationships Modified Files: SelfRefTestCase.java Log Message: Upgrade to JDOM 1.0. Add some parent/child creation in same tx unit tests. Index: SelfRefTestCase.java =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/relationships/SelfRefTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelfRefTestCase.java 3 Nov 2005 22:36:19 -0000 1.1 --- SelfRefTestCase.java 8 Feb 2006 17:26:28 -0000 1.2 *************** *** 165,167 **** --- 165,175 ---- } + public void testCreateParentAndChildInSameTx() throws Exception { + begin(); + SelfRef child = (SelfRef) createPersistentObject(SelfRef.class, true); + SelfRef parent = (SelfRef) createPersistentObject(SelfRef.class, true); + child.setParent(parent); + commit(); + } + } |
From: Douglas A. S. <sei...@us...> - 2006-02-08 17:26:37
|
Update of /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9840/unit-tests/src/java/org/xorm/test/basic Modified Files: BasicTestCase.java Log Message: Upgrade to JDOM 1.0. Add some parent/child creation in same tx unit tests. Index: BasicTestCase.java =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic/BasicTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BasicTestCase.java 25 Jan 2006 23:36:31 -0000 1.4 --- BasicTestCase.java 8 Feb 2006 17:26:28 -0000 1.5 *************** *** 86,92 **** --- 86,124 ---- } + // This works, but perhaps it shouldn't? Foo foo0 = (Foo) mManager.getObjectById(XORM.newObjectId(Foo.class, "0"), true); mLog.info("Got foo with id=0, name=" + foo0.getName()); } + public void testCreateParentAndChildInSameTx() throws Exception { + begin(); + Foo newFoo = (Foo) createPersistentObject(Foo.class, true); + newFoo.setName("newFoo"); + ChildOfFoo childOfFoo = (ChildOfFoo) createPersistentObject(ChildOfFoo.class, true); + childOfFoo.setName("newChild"); + childOfFoo.setFoo(newFoo); + commit(); + + int fooId = getObjectIdAsInt(newFoo); + int childId = getObjectIdAsInt(childOfFoo); + + mLog.info("New foo id = " + fooId); + mLog.info("New child of foo id = " + childId); + + assertTrue("Id should be >= 0", fooId >= 0); + assertTrue("Id should be >= 0", childId >= 0); + + // look them up again and assert the relationships + childOfFoo = (ChildOfFoo) lookupPersistentObject(ChildOfFoo.class, childId); + newFoo = (Foo) lookupPersistentObject(Foo.class, fooId); + + assertNotNull("lookup of new child failed", childOfFoo); + assertNotNull("lookup of new foo failed", newFoo); + + assertNotNull("child's foo ref is null", childOfFoo.getFoo()); + assertTrue("child's foo ref isn't equal to the new foo", childOfFoo.getFoo().equals(newFoo)); + assertTrue("new foo should have one child, has " + newFoo.getChildren().size(), newFoo.getChildren().size() == 1); + + } + } |
From: Wes B. <wb...@us...> - 2006-02-07 01:58:56
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10544 Modified Files: InterfaceManager.java Log Message: Ensure that argument instances passed to deletePersistent() are entered into transactions if they're persistent-nontransactional. Index: InterfaceManager.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/InterfaceManager.java,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** InterfaceManager.java 9 Jan 2006 21:48:08 -0000 1.87 --- InterfaceManager.java 7 Feb 2006 01:58:44 -0000 1.88 *************** *** 556,562 **** handler.setStatus(handler.STATUS_PERSISTENT_NEW_DELETED); break; case ObjectState.STATUS_PERSISTENT_CLEAN: case ObjectState.STATUS_PERSISTENT_DIRTY: - case ObjectState.STATUS_PERSISTENT_NONTRANSACTIONAL: if (object instanceof InstanceCallbacks) { ((InstanceCallbacks) object).jdoPreDelete(); --- 556,563 ---- handler.setStatus(handler.STATUS_PERSISTENT_NEW_DELETED); break; + case ObjectState.STATUS_PERSISTENT_NONTRANSACTIONAL: + handler.enterTransaction((TransactionImpl) currentTransaction()); case ObjectState.STATUS_PERSISTENT_CLEAN: case ObjectState.STATUS_PERSISTENT_DIRTY: if (object instanceof InstanceCallbacks) { ((InstanceCallbacks) object).jdoPreDelete(); |
From: Wes B. <wb...@us...> - 2006-02-05 21:42:55
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6784 Modified Files: ModelMapping.java Log Message: Fix functioning of org.xorm.option.BootstrapJDO (regression bug). Index: ModelMapping.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ModelMapping.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** ModelMapping.java 6 May 2005 13:14:43 -0000 1.60 --- ModelMapping.java 5 Feb 2006 21:42:47 -0000 1.61 *************** *** 106,110 **** if (!PersistenceCapable.class.isAssignableFrom(clazz)) { ! PersistenceCapable pc = (PersistenceCapable) XORM.create(factory, clazz); Collection managedFields = mapping.getManagedFields(); --- 106,112 ---- if (!PersistenceCapable.class.isAssignableFrom(clazz)) { ! // Note: can't call XORM.create() from here because we may still be in ModelMapping<init>, and InterfaceManagerFactory.modelMapping may be null ! InterfaceInvocationHandler handler = InterfaceInvocationHandler.newTransientInstance(factory, mapping); ! PersistenceCapable pc = (PersistenceCapable) handler.newProxy(); Collection managedFields = mapping.getManagedFields(); *************** *** 341,344 **** --- 343,349 ---- for (int i = 0; i < parts.length; i++) { InputStream jdo = getClass().getResourceAsStream(parts[i]); + if (jdo == null) { + throw new JDOFatalUserException("Can't read bootstrap JDO file " + parts[i]); + } initJDO(jdo); } |
From: Wes B. <wb...@us...> - 2006-02-05 21:39:20
|
Update of /cvsroot/xorm/xorm/unit-tests/src/resources In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5153 Modified Files: testdb.properties Log Message: Use BootstrapJDO option to preload JDO file; needed for TestJDOImplHelper. Index: testdb.properties =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/src/resources/testdb.properties,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testdb.properties 27 Oct 2005 23:16:56 -0000 1.2 --- testdb.properties 5 Feb 2006 21:39:13 -0000 1.3 *************** *** 18,19 **** --- 18,22 ---- # DAS: TODO: Don't hard code this org.xorm.datastore.database=testdb.xml + + org.xorm.option.BootstrapJDO=/org/xorm/test/model.jdo + |
From: Douglas A. S. <sei...@us...> - 2006-02-04 16:53:45
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16497/src/org/xorm Modified Files: InterfaceInvocationHandler.java Log Message: After rolling back, old state was not restored correctly. More improvements could be made here ... StateTestCase.testPersistent tests this and was failing before. Index: InterfaceInvocationHandler.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/InterfaceInvocationHandler.java,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** InterfaceInvocationHandler.java 11 Jan 2006 23:38:40 -0000 1.86 --- InterfaceInvocationHandler.java 4 Feb 2006 16:53:37 -0000 1.87 *************** *** 354,358 **** enterTransaction(txn, false); } - snapshot(); } } --- 354,357 ---- *************** *** 790,793 **** --- 789,800 ---- } + // If we are not dirty, take a snapshot ... need to do it here + // because theRow.setValue is going to change the row !! + // TODO: Optimization: Only take snapshot if theRow.setValue + // *would* dirty the row ... need a method for determining this + // on Row maybe: if theRow.wouldDirty(c, value)??? + if (!isDirty()) { + snapshot(); + } // Only mark dirty if the set actually dirties the row if (theRow.setValue(c, value) && !isDirty()) { |
From: Douglas A. S. <sei...@us...> - 2006-02-04 16:51:52
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15739/src/org/xorm Modified Files: ObjectId.java Log Message: Minor formatting fix. Index: ObjectId.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ObjectId.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ObjectId.java 3 Feb 2006 20:58:56 -0000 1.5 --- ObjectId.java 4 Feb 2006 16:51:43 -0000 1.6 *************** *** 65,77 **** public boolean equals(Object o) { ! if (o == this) return true; ! if (o == null) return false; ! if (!(o instanceof ObjectId)) return false; ! ObjectId other = (ObjectId) o; ! boolean e1 = (mappedClass == null) ? ! (other.mappedClass == null) : (mappedClass.equals(other.mappedClass)); ! boolean e2 = (id == null) ? ! (other.id == null) : (id.equals(other.id)); ! return e1 && e2; } --- 65,77 ---- public boolean equals(Object o) { ! if (o == this) return true; ! if (o == null) return false; ! if (!(o instanceof ObjectId)) return false; ! ObjectId other = (ObjectId) o; ! boolean e1 = (mappedClass == null) ? ! (other.mappedClass == null) : (mappedClass.equals(other.mappedClass)); ! boolean e2 = (id == null) ? ! (other.id == null) : (id.equals(other.id)); ! return e1 && e2; } |
From: Douglas A. S. <sei...@us...> - 2006-02-03 20:59:05
|
Update of /cvsroot/xorm/xorm/src/org/xorm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4882/src/org/xorm Modified Files: ObjectId.java Log Message: Implement hashCode on ObjectId so that it can be used as a key in hash collections. Index: ObjectId.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/ObjectId.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ObjectId.java 1 Oct 2002 01:51:52 -0000 1.4 --- ObjectId.java 3 Feb 2006 20:58:56 -0000 1.5 *************** *** 75,77 **** --- 75,85 ---- return e1 && e2; } + + public int hashCode() { + int result = 17; + result = 37 * result + mappedClass.hashCode(); + result = 37 * result + id.hashCode(); + return result; + } + } |