|
From: <one...@us...> - 2003-02-09 06:28:47
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cfg
In directory sc8-pr-cvs1:/tmp/cvs-serv20713/hibernate/cfg
Modified Files:
Binder.java Configuration.java
Log Message:
standardised on dom4j
fixed bugs in collection caching (sometimes an exception occurred)
allowed null discriminators
set autocommit to true in SchemaUpdate
collections now deserialize correctly
Index: Binder.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cfg/Binder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Binder.java 2 Feb 2003 00:29:06 -0000 1.5
--- Binder.java 9 Feb 2003 06:28:14 -0000 1.6
***************
*** 50,57 ****
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
! import org.w3c.dom.Document;
! import org.w3c.dom.NamedNodeMap;
! import org.w3c.dom.Node;
! import org.w3c.dom.NodeList;
class Binder {
--- 50,56 ----
import org.apache.commons.logging.Log;
[...1328 lines suppressed...]
Binder.bindArray(node, array, prefix, mappings);
--- 1027,1031 ----
};
private static final CollectionType ARRAY = new CollectionType("array") {
! public Collection create(Element node, String prefix, PersistentClass owner, Mappings mappings) throws MappingException {
Array array = new Array(owner);
Binder.bindArray(node, array, prefix, mappings);
***************
*** 1078,1082 ****
};
private static final CollectionType PRIMITIVE_ARRAY = new CollectionType("primitive-array") {
! public Collection create(Node node, String prefix, PersistentClass owner, Mappings mappings) throws MappingException {
PrimitiveArray array = new PrimitiveArray(owner);
Binder.bindArray(node, array, prefix, mappings);
--- 1034,1038 ----
};
private static final CollectionType PRIMITIVE_ARRAY = new CollectionType("primitive-array") {
! public Collection create(Element node, String prefix, PersistentClass owner, Mappings mappings) throws MappingException {
PrimitiveArray array = new PrimitiveArray(owner);
Binder.bindArray(node, array, prefix, mappings);
Index: Configuration.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cfg/Configuration.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** Configuration.java 3 Feb 2003 12:11:36 -0000 1.14
--- Configuration.java 9 Feb 2003 06:28:14 -0000 1.15
***************
*** 12,22 ****
import java.io.InputStream;
import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
--- 12,22 ----
import java.io.InputStream;
import java.io.Serializable;
+ import java.io.StringReader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+ import org.dom4j.Attribute;
+ import org.dom4j.Element;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
***************
*** 129,133 ****
log.info("Mapping file: " + xmlFile);
try {
! add( XMLHelper.parseFile(xmlFile) );
}
catch (Exception e) {
--- 129,133 ----
log.info("Mapping file: " + xmlFile);
try {
! add( XMLHelper.createSAXReader(xmlFile).read(xmlFile) );
}
catch (Exception e) {
***************
*** 145,149 ****
if ( log.isDebugEnabled() ) log.debug("Mapping XML:\n" + xml);
try {
! add( XMLHelper.parseString(xml) );
}
catch (Exception e) {
--- 145,149 ----
if ( log.isDebugEnabled() ) log.debug("Mapping XML:\n" + xml);
try {
! add( XMLHelper.createSAXReader("XML String").read( new StringReader(xml) ) );
}
catch (Exception e) {
***************
*** 161,165 ****
if ( log.isDebugEnabled() ) log.debug("Mapping XML:\n" + doc);
try {
! add(doc);
}
catch (Exception e) {
--- 161,165 ----
if ( log.isDebugEnabled() ) log.debug("Mapping XML:\n" + doc);
try {
! add( XMLHelper.createDOMReader().read(doc) );
}
catch (Exception e) {
***************
*** 170,174 ****
}
! private void add(Document doc) throws Exception {
try {
Binder.bindRoot( doc, createMappings() );
--- 170,174 ----
}
! private void add(org.dom4j.Document doc) throws Exception {
try {
Binder.bindRoot( doc, createMappings() );
***************
*** 194,198 ****
public Configuration addInputStream(InputStream xmlInputStream) throws MappingException {
try {
! add( XMLHelper.parseInputSource( new InputSource(xmlInputStream) ) );
return this;
}
--- 194,198 ----
public Configuration addInputStream(InputStream xmlInputStream) throws MappingException {
try {
! add( XMLHelper.createSAXReader("XML InputStream").read( new InputSource(xmlInputStream) ) );
return this;
}
***************
*** 602,616 ****
}
! private void addProperties(Node parent) {
! NodeList children = parent.getChildNodes();
! for ( int i=0; i<children.getLength(); i++ ) {
! Node node = children.item(i);
! if ( node.getNodeName().equals("property") ) {
! String name = node.getAttributes().getNamedItem("name").getNodeValue();
! String value = node.getFirstChild().getNodeValue();
! log.debug(name + "=" + value);
! properties.setProperty(name, value);
! if ( !name.startsWith("hibernate") ) properties.setProperty("hibernate." + name, value);
! }
}
Environment.verifyProperties(properties);
--- 602,614 ----
}
! private void addProperties(Element parent) {
! Iterator iter = parent.elementIterator("property");
! while ( iter.hasNext() ) {
! Element node = (Element) iter.next();
! String name = node.attributeValue("name");
! String value = node.getText();
! log.debug(name + "=" + value);
! properties.setProperty(name, value);
! if ( !name.startsWith("hibernate") ) properties.setProperty("hibernate." + name, value);
}
Environment.verifyProperties(properties);
***************
*** 653,659 ****
InputStream stream = getConfigurationInputStream(resource);
! Document doc;
try {
! doc = XMLHelper.parseInputSource( new InputSource(stream) );
}
catch (Exception e) {
--- 651,657 ----
InputStream stream = getConfigurationInputStream(resource);
! org.dom4j.Document doc;
try {
! doc = XMLHelper.createSAXReader(resource).read( new InputSource(stream) );
}
catch (Exception e) {
***************
*** 662,699 ****
}
! Node sfNode = doc.getDocumentElement().getElementsByTagName("session-factory").item(0);
! String name = sfNode.getAttributes().getNamedItem("name").getNodeValue();
properties.setProperty(Environment.SESSION_FACTORY_NAME, name);
addProperties(sfNode);
! NodeList mapElements = sfNode.getChildNodes();
! for ( int j=0; j<mapElements.getLength(); j++ ) {
! Node mapElement = mapElements.item(j);
! NamedNodeMap atts = mapElement.getAttributes();
! if ( "mapping".equals( mapElement.getNodeName() ) ) {
! Node rsrc = atts.getNamedItem("resource");
! Node file = atts.getNamedItem("file");
! Node jar = atts.getNamedItem("jar");
if (rsrc!=null) {
log.debug(name + "<-" + rsrc);
try {
! addResource( rsrc.getNodeValue(), Thread.currentThread().getContextClassLoader() );
}
catch (MappingException me) {
! addResource( rsrc.getNodeValue(), Environment.class.getClassLoader() );
}
}
else if ( jar!=null ) {
log.debug(name + "<-" + jar);
! addJar( jar.getNodeValue() );
}
else {
if (file==null) throw new MappingException("<mapping> element in configuration specifies no attributes");
log.debug(name + "<-" + file);
! addFile( file.getNodeValue() );
}
}
! else if ( "jcs-class-cache".equals( mapElement.getNodeName() ) ) {
! String className = atts.getNamedItem("class").getNodeValue();
final Class clazz;
try {
--- 660,697 ----
}
! Element sfNode = doc.getRootElement().element("session-factory");
! String name = sfNode.attributeValue("name");
properties.setProperty(Environment.SESSION_FACTORY_NAME, name);
addProperties(sfNode);
! Iterator elements = sfNode.elementIterator();
! while ( elements.hasNext() ) {
! Element mapElement = (Element) elements.next();
! String elemname = mapElement.getName();
! if ( "mapping".equals(elemname) ) {
! Attribute rsrc = mapElement.attribute("resource");
! Attribute file = mapElement.attribute("file");
! Attribute jar = mapElement.attribute("jar");
if (rsrc!=null) {
log.debug(name + "<-" + rsrc);
try {
! addResource( rsrc.getValue(), Thread.currentThread().getContextClassLoader() );
}
catch (MappingException me) {
! addResource( rsrc.getValue(), Environment.class.getClassLoader() );
}
}
else if ( jar!=null ) {
log.debug(name + "<-" + jar);
! addJar( jar.getValue() );
}
else {
if (file==null) throw new MappingException("<mapping> element in configuration specifies no attributes");
log.debug(name + "<-" + file);
! addFile( file.getValue() );
}
}
! else if ( "jcs-class-cache".equals(elemname) ) {
! String className = mapElement.attributeValue("class");
final Class clazz;
try {
***************
*** 710,725 ****
throw new MappingException("You may only specify a cache for root <class> mappings");
}
! Node regionNode = atts.getNamedItem("region");
String region = className;
! if (regionNode!=null) region = regionNode.getNodeValue();
! pc.setCache( createJCSCache( atts.getNamedItem("usage").getNodeValue(), region, pc ) );
}
! else if ( "jcs-collection-cache".equals( mapElement.getNodeName() ) ) {
! String role = atts.getNamedItem("collection").getNodeValue();
Collection c = (Collection) getCollectionMapping(role);
! Node regionNode = atts.getNamedItem("region");
String region = role;
! if (regionNode!=null) region = regionNode.getNodeValue();
! c.setCache( createJCSCache( atts.getNamedItem("usage").getNodeValue(), region, c.getOwner() ) );
}
}
--- 708,723 ----
throw new MappingException("You may only specify a cache for root <class> mappings");
}
! Attribute regionNode = mapElement.attribute("region");
String region = className;
! if (regionNode!=null) region = regionNode.getValue();
! pc.setCache( createJCSCache( mapElement.attributeValue("usage"), region, pc ) );
}
! else if ( "jcs-collection-cache".equals(elemname) ) {
! String role = mapElement.attributeValue("collection");
Collection c = (Collection) getCollectionMapping(role);
! Attribute regionNode = mapElement.attribute("region");
String region = role;
! if (regionNode!=null) region = regionNode.getValue();
! c.setCache( createJCSCache( mapElement.attributeValue("usage"), region, c.getOwner() ) );
}
}
|