You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [8/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/m...
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,35 +12,33 @@
*/
package org.apache.openjpa.lib.meta;
+import java.io.*;
+import java.util.*;
+import javax.xml.transform.*;
+import javax.xml.transform.sax.*;
+import javax.xml.transform.stream.*;
import org.apache.openjpa.lib.log.*;
import org.apache.openjpa.lib.util.*;
import org.apache.openjpa.lib.xml.*;
-
import org.xml.sax.*;
import org.xml.sax.ext.*;
import org.xml.sax.helpers.*;
-import java.io.*;
-
-import java.util.*;
-
-import javax.xml.transform.*;
-import javax.xml.transform.sax.*;
-import javax.xml.transform.stream.*;
-
-
/**
- * <p>Abstract base type for serlializers that transfer groups of objects
- * to XML. Includes a way of serializing objects back to the XML files
- * they were parsed from.</p>
- *
- * <p>Serializers are not thread safe.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Abstract base type for serlializers that transfer groups of objects
+ * to XML. Includes a way of serializing objects back to the XML files
+ * they were parsed from.
+ * Serializers are not thread safe.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
- private static final Localizer _loc = Localizer.forPackage(XMLMetaDataSerializer.class);
- private static final SAXTransformerFactory _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+ private static final Localizer _loc = Localizer.forPackage
+ (XMLMetaDataSerializer.class);
+ private static final SAXTransformerFactory _factory =
+ (SAXTransformerFactory) TransformerFactory.newInstance();
+
private Log _log = null;
// current serialization state
@@ -53,15 +48,15 @@
private File _backup = null;
/**
- * The log to write to.
- */
+ * The log to write to.
+ */
public Log getLog() {
return _log;
}
/**
- * The log to write to.
- */
+ * The log to write to.
+ */
public void setLog(Log log) {
_log = log;
}
@@ -72,47 +67,36 @@
public void serialize(Map output, int flags) throws IOException {
Map files = getFileMap();
-
- if (files == null) {
+ if (files == null)
return;
- }
// for each file, serialize objects
Map.Entry entry;
-
for (Iterator itr = files.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
-
File file = (File) entry.getKey();
Collection fileObjs = (Collection) entry.getValue();
- if ((_log != null) && _log.isInfoEnabled()) {
+ if (_log != null && _log.isInfoEnabled())
_log.info(_loc.get("ser-file", file));
- }
try {
TransformerHandler trans = _factory.newTransformerHandler();
Writer writer;
-
if (output == null) {
_backup = prepareWrite(file);
writer = new FileWriter(file);
- } else {
+ } else
writer = new StringWriter();
- }
Writer xml = writer;
-
- if ((flags & PRETTY) > 0) {
+ if ((flags & PRETTY) > 0)
xml = new XMLWriter(writer);
- }
-
trans.setResult(new StreamResult(xml));
serialize(fileObjs, trans, flags);
- if (output != null) {
+ if (output != null)
output.put(file, ((StringWriter) writer).toString());
- }
} catch (SAXException se) {
throw new IOException(se.toString());
} catch (TransformerConfigurationException tce) {
@@ -122,60 +106,48 @@
}
/**
- * Prepare to write to the given file. Back up the file and make sure the
- * path to it is created.
+ * Prepare to write to the given file. Back up the file and make sure the
+ * path to it is created.
*/
protected File prepareWrite(File file) throws IOException {
File backup = Files.backup(file, false);
-
if (backup == null) {
File parent = file.getParentFile();
-
- if ((parent != null) && !parent.exists()) {
+ if (parent != null && !parent.exists())
parent.mkdirs();
- }
}
-
return backup;
}
/**
- * Returns a {@link Map} with keys of the {@link File} to be
- * written to, and values of a {@link Collection} of
- * {@link SourceTracker} instances.
+ * Returns a {@link Map} with keys of the {@link File} to be
+ * written to, and values of a {@link Collection} of
+ * {@link SourceTracker} instances.
*/
protected Map getFileMap() {
Collection objs = getObjects();
-
- if ((objs == null) || objs.isEmpty()) {
+ if (objs == null || objs.isEmpty())
return null;
- }
// create a map of files to lists of objects
Map files = new HashMap();
File file;
Collection fileObjs;
Object obj;
-
for (Iterator itr = objs.iterator(); itr.hasNext();) {
obj = itr.next();
file = getSourceFile(obj);
-
if (file == null) {
- if ((_log != null) && _log.isTraceEnabled()) {
+ if (_log != null && _log.isTraceEnabled())
_log.trace(_loc.get("no-file", obj));
- }
-
continue;
}
fileObjs = (Collection) files.get(file);
-
if (fileObjs == null) {
fileObjs = new LinkedList();
files.put(file, fileObjs);
}
-
fileObjs.add(obj);
}
@@ -183,44 +155,39 @@
}
/**
- * Return the source file for the given instance. By default, checks
- * to see if the instance implements {@link SourceTracker}.
+ * Return the source file for the given instance. By default, checks
+ * to see if the instance implements {@link SourceTracker}.
*/
protected File getSourceFile(Object obj) {
- if (obj instanceof SourceTracker) {
- return ((SourceTracker) obj).getSourceFile();
- }
-
+ if (obj instanceof SourceTracker)
+ return((SourceTracker) obj).getSourceFile();
return null;
}
public void serialize(File file, int flags) throws IOException {
- if (_log != null) {
+ if (_log != null)
_log.info(_loc.get("ser-file", file));
- }
_backup = prepareWrite(file);
-
FileWriter out = new FileWriter(file.getCanonicalPath(),
- (flags & APPEND) > 0);
+ (flags & APPEND) > 0);
serialize(out, flags);
out.close();
}
public void serialize(Writer out, int flags) throws IOException {
try {
- if ((flags & PRETTY) > 0) {
+ if ((flags & PRETTY) > 0)
serialize(new StreamResult(new XMLWriter(out)), flags);
- } else {
+ else
serialize(new StreamResult(out), flags);
- }
} catch (SAXException se) {
throw new IOException(se.toString());
}
}
/**
- * Serialize the current set of objects to the given result.
+ * Serialize the current set of objects to the given result.
*/
public void serialize(Result result, int flags) throws SAXException {
try {
@@ -233,54 +200,52 @@
}
/**
- * Serilize the current set of objects to a series of SAX events on the
- * given handler.
+ * Serilize the current set of objects to a series of SAX events on the
+ * given handler.
*/
- public void serialize(ContentHandler handler, int flags)
- throws SAXException {
+ public void serialize(ContentHandler handler, int flags) throws SAXException {
serialize(getObjects(), handler, flags);
}
/**
- * Serialize the given collection of objects to the given handler.
+ * Serialize the given collection of objects to the given handler.
*/
private void serialize(Collection objs, ContentHandler handler, int flags)
throws SAXException {
- if ((_log != null) && _log.isTraceEnabled()) {
+ if (_log != null && _log.isTraceEnabled())
_log.trace(_loc.get("ser-objs", objs));
- }
_handler = handler;
_flags = flags;
-
try {
if (!objs.isEmpty()) {
handler.startDocument();
serialize(objs);
handler.endDocument();
}
- } finally {
+ }
+ finally {
reset();
}
}
/**
- * Whether this serialization is in verbose mode.
+ * Whether this serialization is in verbose mode.
*/
protected boolean isVerbose() {
- return (_flags & VERBOSE) > 0;
+ return(_flags & VERBOSE) > 0;
}
/**
- * The backup file made for the current file being parsed.
+ * The backup file made for the current file being parsed.
*/
protected File currentBackupFile() {
return _backup;
}
/**
- * Start an element with the current attribute settings. Clears the
- * attributes as well.
+ * Start an element with the current attribute settings. Clears the
+ * attributes as well.
*/
protected void startElement(String name) throws SAXException {
_handler.startElement("", name, name, _attrs);
@@ -288,45 +253,43 @@
}
/**
- * End the current element.
+ * End the current element.
*/
protected void endElement(String name) throws SAXException {
_handler.endElement("", name, name);
}
/**
- * Add text to the current element.
+ * Add text to the current element.
*/
protected void addText(String text) throws SAXException {
_handler.characters(text.toCharArray(), 0, text.length());
}
/**
- * Add an attribute to the current group.
+ * Add an attribute to the current group.
*/
protected void addAttribute(String name, String value) {
_attrs.addAttribute("", name, name, "CDATA", value);
}
/**
- * The current attributes.
+ * The current attributes.
*/
protected Attributes getAttributes() {
return _attrs;
}
/**
- * Add a comment to the stream.
+ * Add a comment to the stream.
*/
protected void addComments(String[] comments) throws SAXException {
- if ((comments == null) || (comments.length == 0) ||
- !(_handler instanceof LexicalHandler)) {
+ if (comments == null || comments.length == 0
+ || !(_handler instanceof LexicalHandler))
return;
- }
LexicalHandler lh = (LexicalHandler) _handler;
char[] chars;
-
for (int i = 0; i < comments.length; i++) {
chars = comments[i].toCharArray();
lh.comment(chars, 0, chars.length);
@@ -334,17 +297,16 @@
}
/**
- * Write the given entity's comments. By default, tests if entity is
- * {@link Commentable}.
+ * Write the given entity's comments. By default, tests if entity is
+ * {@link Commentable}.
*/
protected void addComments(Object obj) throws SAXException {
- if (obj instanceof Commentable) {
+ if (obj instanceof Commentable)
addComments(((Commentable) obj).getComments());
- }
}
/**
- * Reset serialization state for the next document.
+ * Reset serialization state for the next document.
*/
protected void reset() {
_attrs.clear();
@@ -354,13 +316,12 @@
}
/**
- * Serialize the given set of objects.
+ * Serialize the given set of objects.
*/
- protected abstract void serialize(Collection objs)
- throws SAXException;
+ protected abstract void serialize(Collection objs) throws SAXException;
/**
- * Return the current set of objects for serialization.
+ * Return the current set of objects for serialization.
*/
protected abstract Collection getObjects();
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -16,20 +13,18 @@
package org.apache.openjpa.lib.meta;
import java.io.*;
-
import java.net.*;
-
import java.util.*;
import java.util.zip.*;
-
/**
- * <p>Iterator over all metadata resources in a given zip file.</p>
- *
- * @author Abe White
- * @nojavadoc */
-public class ZipFileMetaDataIterator implements MetaDataIterator,
- MetaDataFilter.Resource {
+ * Iterator over all metadata resources in a given zip file.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
+public class ZipFileMetaDataIterator
+ implements MetaDataIterator, MetaDataFilter.Resource {
private final ZipFile _file;
private final MetaDataFilter _filter;
private final Enumeration _entries;
@@ -38,7 +33,7 @@
private ZipEntry _last = null;
/**
- * Constructor; supply zip/jar URL and optional file filter.
+ * Constructor; supply zip/jar URL and optional file filter.
*/
public ZipFileMetaDataIterator(URL url, MetaDataFilter filter)
throws IOException {
@@ -49,7 +44,7 @@
}
/**
- * Constructor; supply zip file and optional file filter.
+ * Constructor; supply zip file and optional file filter.
*/
public ZipFileMetaDataIterator(ZipFile file, MetaDataFilter filter) {
_file = file;
@@ -59,91 +54,70 @@
}
public boolean hasNext() throws IOException {
- if (_entries == null) {
+ if (_entries == null)
return false;
- }
// search for next metadata file
- while ((_entry == null) && _entries.hasMoreElements()) {
+ while (_entry == null && _entries.hasMoreElements()) {
_entry = (ZipEntry) _entries.nextElement();
-
- if ((_filter != null) && !_filter.matches(this)) {
+ if (_filter != null && !_filter.matches(this))
_entry = null;
- }
}
-
return _entry != null;
}
public Object next() throws IOException {
- if (!hasNext()) {
+ if (!hasNext())
throw new NoSuchElementException();
- }
-
String ret = _entry.getName();
_last = _entry;
_entry = null;
-
return ret;
}
public InputStream getInputStream() throws IOException {
- if (_last == null) {
+ if (_last == null)
throw new IllegalStateException();
- }
-
return _file.getInputStream(_last);
}
public File getFile() {
- if (_last == null) {
+ if (_last == null)
throw new IllegalStateException();
- }
-
return null;
}
public void close() {
- if (_close) {
- try {
- _file.close();
- } catch (IOException ioe) {
- }
- }
+ if (_close)
+ try { _file.close(); } catch (IOException ioe) {}
}
//////////////////////////////////////////
// MetaDataFilter.Resource implementation
//////////////////////////////////////////
+
public String getName() {
return _entry.getName();
}
public byte[] getContent() throws IOException {
long size = _entry.getSize();
-
- if (size == 0) {
+ if (size == 0)
return new byte[0];
- }
InputStream in = _file.getInputStream(_entry);
byte[] content;
-
if (size < 0) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
-
- for (int r; (r = in.read(buf)) != -1; bout.write(buf, 0, r))
- ;
-
+ for (int r; (r = in.read(buf)) != -1; bout.write(buf, 0, r));
content = bout.toByteArray();
} else {
content = new byte[(int) size];
in.read(content);
}
-
in.close();
-
return content;
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -16,18 +13,17 @@
package org.apache.openjpa.lib.meta;
import java.io.*;
-
import java.util.*;
import java.util.zip.*;
-
/**
- * <p>Iterator over all metadata resources in a given zip input stream.</p>
- *
- * @author Abe White
- * @nojavadoc */
-public class ZipStreamMetaDataIterator implements MetaDataIterator,
- MetaDataFilter.Resource {
+ * Iterator over all metadata resources in a given zip input stream.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
+public class ZipStreamMetaDataIterator
+ implements MetaDataIterator, MetaDataFilter.Resource {
private final ZipInputStream _stream;
private final MetaDataFilter _filter;
private ZipEntry _entry = null;
@@ -35,7 +31,7 @@
private byte[] _buf = null;
/**
- * Constructor; supply zip stream and optional metadata filter.
+ * Constructor; supply zip stream and optional metadata filter.
*/
public ZipStreamMetaDataIterator(ZipInputStream stream,
MetaDataFilter filter) {
@@ -44,58 +40,44 @@
}
public boolean hasNext() throws IOException {
- if (_stream == null) {
+ if (_stream == null)
return false;
- }
-
- if (_entry != null) {
+ if (_entry != null)
return true;
- }
// close last rsrc
- if ((_buf == null) && (_last != null)) {
+ if (_buf == null && _last != null)
_stream.closeEntry();
- }
-
_last = null;
_buf = null;
// search for next file
ZipEntry entry;
-
- while ((_entry == null) && ((entry = _stream.getNextEntry()) != null)) {
+ while (_entry == null && (entry = _stream.getNextEntry()) != null) {
_entry = entry;
-
- if ((_filter != null) && !_filter.matches(this)) {
+ if (_filter != null && !_filter.matches(this)) {
_entry = null;
_stream.closeEntry();
}
}
-
return _entry != null;
}
public Object next() throws IOException {
- if (!hasNext()) {
+ if (!hasNext())
throw new NoSuchElementException();
- }
-
String ret = _entry.getName();
_last = _entry;
_entry = null;
-
return ret;
}
public InputStream getInputStream() {
- if (_last == null) {
+ if (_last == null)
throw new IllegalStateException();
- }
- if (_buf != null) {
+ if (_buf != null)
return new ByteArrayInputStream(_buf);
- }
-
return new NoCloseInputStream();
}
@@ -104,15 +86,13 @@
}
public void close() {
- try {
- _stream.close();
- } catch (IOException ioe) {
- }
+ try { _stream.close(); } catch (IOException ioe) {}
}
//////////////////////////////////////////
// MetaDataFilter.Resource implementation
//////////////////////////////////////////
+
public String getName() {
return _entry.getName();
}
@@ -121,28 +101,22 @@
// buffer content so that future calls to getInputStream can read
// the same data
int size = (int) _entry.getSize();
-
if (size < 0) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
-
- for (int r; (r = _stream.read(buf)) != -1; bout.write(buf, 0, r))
- ;
-
+ for (int r; (r = _stream.read(buf)) != -1; bout.write(buf, 0, r));
_buf = bout.toByteArray();
} else {
_buf = new byte[size];
_stream.read(_buf);
}
-
_stream.closeEntry();
-
return _buf;
}
/**
- * Non-closing input stream used to make sure the underlying zip
- * stream is not closed.
+ * Non-closing input stream used to make sure the underlying zip
+ * stream is not closed.
*/
private class NoCloseInputStream extends InputStream {
public int available() throws IOException {
@@ -161,3 +135,4 @@
}
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,18 +12,18 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.openjpa.lib.util.*;
-
import java.util.*;
-
+import org.apache.openjpa.lib.util.*;
/**
- * <p>Abstract read-only list iterator.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Abstract read-only list iterator.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
abstract class AbstractListIterator implements ListIterator {
- private static final Localizer _loc = Localizer.forPackage(AbstractListIterator.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (AbstractListIterator.class);
public void add(Object o) {
throw new UnsupportedOperationException(_loc.get("read-only"));
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,114 +12,84 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.commons.lang.*;
-
import java.util.*;
-
+import org.apache.commons.lang.*;
/**
- * <p>Abstract base class for random-access result lists. Unlike the
- * {@link AbstractList}, this class doesn't rely on the
- * {@link Collection#size} method.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Abstract base class for random-access result lists. Unlike the
+ * {@link AbstractList}, this class doesn't rely on the
+ * {@link Collection#size} method.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public abstract class AbstractNonSequentialResultList extends AbstractResultList {
protected static final Object PAST_END = new Object();
/**
- * Implement this method and {@link #size}. Return {@link #PAST_END}
- * if the index is out of bounds.
- */
+ * Implement this method and {@link #size}. Return {@link #PAST_END}
+ * if the index is out of bounds.
+ */
protected abstract Object getInternal(int index);
public boolean contains(Object o) {
assertOpen();
-
Object obj;
-
for (int i = 0; true; i++) {
obj = getInternal(i);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
break;
- }
-
- if (ObjectUtils.equals(o, obj)) {
+ if (ObjectUtils.equals(o, obj))
return true;
- }
}
-
return false;
}
public boolean containsAll(Collection c) {
assertOpen();
-
for (Iterator itr = c.iterator(); itr.hasNext();)
- if (!contains(itr.next())) {
+ if (!contains(itr.next()))
return false;
- }
-
return true;
}
public Object get(int index) {
assertOpen();
-
Object obj = getInternal(index);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
throw new NoSuchElementException();
- }
-
return obj;
}
public int indexOf(Object o) {
assertOpen();
-
Object obj;
-
for (int i = 0; true; i++) {
obj = getInternal(i);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
break;
- }
-
- if (ObjectUtils.equals(o, obj)) {
+ if (ObjectUtils.equals(o, obj))
return i;
- }
}
-
return -1;
}
public int lastIndexOf(Object o) {
assertOpen();
-
int index = -1;
Object obj;
-
for (int i = 0; true; i++) {
obj = getInternal(i);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
break;
- }
-
- if (ObjectUtils.equals(o, obj)) {
+ if (ObjectUtils.equals(o, obj))
index = i;
- }
}
-
return index;
}
public boolean isEmpty() {
assertOpen();
-
return getInternal(0) == PAST_END;
}
@@ -140,39 +107,27 @@
public Object[] toArray() {
assertOpen();
-
ArrayList list = new ArrayList();
Object obj;
-
for (int i = 0; true; i++) {
obj = getInternal(i);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
break;
- }
-
list.add(obj);
}
-
return list.toArray();
}
public Object[] toArray(Object[] a) {
assertOpen();
-
ArrayList list = new ArrayList();
Object obj;
-
for (int i = 0; true; i++) {
obj = getInternal(i);
-
- if (obj == PAST_END) {
+ if (obj == PAST_END)
break;
- }
-
list.add(obj);
}
-
return list.toArray(a);
}
@@ -194,7 +149,6 @@
public boolean hasNext() {
_next = getInternal(_idx);
-
return _next != PAST_END;
}
@@ -203,20 +157,15 @@
}
public Object previous() {
- if (_idx == 0) {
+ if (_idx == 0)
throw new NoSuchElementException();
- }
-
return getInternal(--_idx);
}
public Object next() {
- if (!hasNext()) {
+ if (!hasNext())
throw new NoSuchElementException();
- }
-
_idx++;
-
return _next;
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,18 +12,18 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.openjpa.lib.util.*;
-
import java.util.*;
-
+import org.apache.openjpa.lib.util.*;
/**
- * <p>Abstract base class for read-only result lists.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Abstract base class for read-only result lists.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public abstract class AbstractResultList implements ResultList {
- private static final Localizer _loc = Localizer.forPackage(AbstractResultList.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (AbstractResultList.class);
public void add(int index, Object element) {
throw new UnsupportedOperationException(_loc.get("read-only"));
@@ -78,8 +75,7 @@
}
protected void assertOpen() {
- if (isClosed()) {
+ if (isClosed())
throw new NoSuchElementException(_loc.get("closed"));
- }
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,82 +12,65 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.commons.lang.*;
-
import java.util.*;
-
+import org.apache.commons.lang.*;
/**
- * <p>Abstract base class for sequential result lists. Unlike the
- * {@link AbstractSequentialList}, this class doesn't rely on the
- * {@link Collection#size} method.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Abstract base class for sequential result lists. Unlike the
+ * {@link AbstractSequentialList}, this class doesn't rely on the
+ * {@link Collection#size} method.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public abstract class AbstractSequentialResultList extends AbstractResultList {
/**
- * Implement this method and {@link #size}.
- */
+ * Implement this method and {@link #size}.
+ */
protected abstract ListIterator itr(int index);
public boolean contains(Object o) {
assertOpen();
-
for (Iterator itr = itr(0); itr.hasNext();)
- if (ObjectUtils.equals(o, itr.next())) {
+ if (ObjectUtils.equals(o, itr.next()))
return true;
- }
-
return false;
}
public boolean containsAll(Collection c) {
assertOpen();
-
for (Iterator itr = c.iterator(); itr.hasNext();)
- if (!contains(itr.next())) {
+ if (!contains(itr.next()))
return false;
- }
-
return true;
}
public Object get(int index) {
assertOpen();
-
return itr(index).next();
}
public int indexOf(Object o) {
assertOpen();
-
int index = 0;
-
for (Iterator itr = itr(0); itr.hasNext(); index++)
- if (ObjectUtils.equals(o, itr.next())) {
+ if (ObjectUtils.equals(o, itr.next()))
return index;
- }
-
return -1;
}
public int lastIndexOf(Object o) {
assertOpen();
-
int index = -1;
int i = 0;
-
for (Iterator itr = itr(0); itr.hasNext(); i++)
- if (ObjectUtils.equals(o, itr.next())) {
+ if (ObjectUtils.equals(o, itr.next()))
index = i;
- }
-
return index;
}
public boolean isEmpty() {
assertOpen();
-
return !itr(0).hasNext();
}
@@ -108,23 +88,17 @@
public Object[] toArray() {
assertOpen();
-
ArrayList list = new ArrayList();
-
for (Iterator itr = itr(0); itr.hasNext();)
list.add(itr.next());
-
return list.toArray();
}
public Object[] toArray(Object[] a) {
assertOpen();
-
ArrayList list = new ArrayList();
-
for (Iterator itr = itr(0); itr.hasNext();)
list.add(itr.next());
-
return list.toArray(a);
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/EagerResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/EagerResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/EagerResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/EagerResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -17,30 +14,27 @@
import java.util.*;
-
/**
- * Simple, non-lazy ResultList implementation
- *
- * @author Patrick Linskey
- * @nojavadoc */
+ * Simple, non-lazy ResultList implementation
+ *
+ * @author Patrick Linskey
+ * @nojavadoc
+ */
public class EagerResultList extends ListResultList implements ResultList {
public EagerResultList(ResultObjectProvider rop) {
super(new ArrayList());
-
try {
rop.open();
-
while (rop.next())
getDelegate().add(rop.getResultObject());
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
rop.handleCheckedException(e);
- } finally {
- try {
- rop.close();
- } catch (Exception e) {
- }
+ }
+ finally {
+ try { rop.close(); } catch (Exception e) {}
}
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -16,20 +13,20 @@
package org.apache.openjpa.lib.rop;
import java.io.*;
-
import java.util.*;
-
/**
- * <p>Lazy forward-only result list.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Lazy forward-only result list.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class LazyForwardResultList extends AbstractSequentialResultList
implements ResultList {
private static final int OPEN = 0;
private static final int CLOSED = 1;
private static final int FREED = 2;
+
private ResultObjectProvider _rop = null;
private final List _list = new ArrayList();
private int _state = OPEN;
@@ -37,7 +34,6 @@
public LazyForwardResultList(ResultObjectProvider rop) {
_rop = rop;
-
try {
_rop.open();
} catch (RuntimeException re) {
@@ -68,35 +64,26 @@
assertOpen();
// optimization for getting sequntially
- if (index == _list.size()) {
+ if (index == _list.size())
addNext();
- }
-
- if (index < _list.size()) {
+ if (index < _list.size())
return _list.get(index);
- }
return super.get(index);
}
protected ListIterator itr(int index) {
- return (_state != OPEN) ? _list.listIterator(index) : new Itr(index);
+ return(_state != OPEN) ? _list.listIterator(index) : new Itr(index);
}
public int size() {
assertOpen();
-
- if (_size != -1) {
+ if (_size != -1)
return _size;
- }
-
- if (_state != OPEN) {
+ if (_state != OPEN)
return _list.size();
- }
-
try {
_size = _rop.size();
-
return _size;
} catch (RuntimeException re) {
close();
@@ -104,7 +91,6 @@
} catch (Exception e) {
close();
_rop.handleCheckedException(e);
-
return -1;
}
}
@@ -113,12 +99,9 @@
try {
if (!_rop.next()) {
free();
-
return false;
}
-
_list.add(_rop.getResultObject());
-
return true;
} catch (RuntimeException re) {
close();
@@ -126,34 +109,27 @@
} catch (Exception e) {
close();
_rop.handleCheckedException(e);
-
return false;
}
}
private void free() {
if (_state == OPEN) {
- try {
- _rop.close();
- } catch (Exception e) {
- }
-
+ try { _rop.close(); } catch (Exception e) {}
_state = FREED;
}
}
public Object writeReplace() throws ObjectStreamException {
// fully traverse results
- if (_state == OPEN) {
+ if (_state == OPEN)
for (Iterator itr = itr(_list.size()); itr.hasNext();)
itr.next();
- }
-
return _list;
}
public int hashCode() {
- // superclass tries to traverses entire list for hashcode
+ // superclass tries to traverses entire list for hashcode
return System.identityHashCode(this);
}
@@ -167,7 +143,6 @@
public Itr(int index) {
_idx = Math.min(index, _list.size());
-
while (_idx < index)
next();
}
@@ -181,14 +156,10 @@
}
public boolean hasNext() {
- if (_list.size() > _idx) {
+ if (_list.size() > _idx)
return true;
- }
-
- if (_state != OPEN) {
+ if (_state != OPEN)
return false;
- }
-
return addNext();
}
@@ -197,18 +168,14 @@
}
public Object previous() {
- if (_idx == 0) {
+ if (_idx == 0)
throw new NoSuchElementException();
- }
-
return _list.get(--_idx);
}
public Object next() {
- if (!hasNext()) {
+ if (!hasNext())
throw new NoSuchElementException();
- }
-
return _list.get(_idx++);
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -17,25 +14,25 @@
import java.util.*;
-
/**
- * <p>A basic {@link ResultList} implementation that wraps a normal list.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * A basic {@link ResultList} implementation that wraps a normal list.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class ListResultList extends AbstractResultList {
private final List _list;
private boolean _closed = false;
/**
- * Constructor. Supply delegate.
+ * Constructor. Supply delegate.
*/
public ListResultList(List list) {
_list = list;
}
/**
- * Return the wrapped list.
+ * Return the wrapped list.
*/
public List getDelegate() {
return _list;
@@ -55,43 +52,36 @@
public boolean contains(Object o) {
assertOpen();
-
return _list.contains(o);
}
public boolean containsAll(Collection c) {
assertOpen();
-
return _list.containsAll(c);
}
public Object get(int index) {
assertOpen();
-
return _list.get(index);
}
public int indexOf(Object o) {
assertOpen();
-
return _list.indexOf(o);
}
public int lastIndexOf(Object o) {
assertOpen();
-
return _list.lastIndexOf(o);
}
public int size() {
assertOpen();
-
return _list.size();
}
public boolean isEmpty() {
assertOpen();
-
return _list.isEmpty();
}
@@ -109,13 +99,11 @@
public Object[] toArray() {
assertOpen();
-
return _list.toArray();
}
public Object[] toArray(Object[] a) {
assertOpen();
-
return _list.toArray(a);
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,24 +12,21 @@
*/
package org.apache.openjpa.lib.rop;
+import java.util.*;
import org.apache.commons.lang.exception.*;
-
import org.apache.openjpa.lib.util.*;
-import java.util.*;
-
-
/**
- * <p>A result object provider wrapped around a normal list.</p>
- *
- * @author Abe White
+ * A result object provider wrapped around a normal list.
+ *
+ * @author Abe White
*/
public class ListResultObjectProvider implements ResultObjectProvider {
private final List _list;
private int _idx = -1;
/**
- * Constructor. Supply delegate.
+ * Constructor. Supply delegate.
*/
public ListResultObjectProvider(List list) {
_list = list;
@@ -58,12 +52,10 @@
}
public boolean absolute(int pos) throws Exception {
- if ((pos >= 0) && (pos < _list.size())) {
+ if (pos >= 0 && pos < _list.size()) {
_idx = pos;
-
return true;
}
-
return false;
}
@@ -76,12 +68,8 @@
}
public void close() throws Exception {
- if (_list instanceof Closeable) {
- try {
- ((Closeable) _list).close();
- } catch (Exception e) {
- }
- }
+ if (_list instanceof Closeable)
+ try { ((Closeable) _list).close(); } catch (Exception e) {}
}
public void handleCheckedException(Exception e) {
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,24 +12,23 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.commons.lang.exception.*;
-
import java.util.*;
-
+import org.apache.commons.lang.exception.*;
/**
- * <p>A result object provider that merges multiple result object provider
- * delegates. Support exists for maintaining ordering of the internally held
- * results, provided that each of the individual results is itself ordered.</p>
- *
- * @author Abe White
- * @author Marc Prud'hommeaux
+ * A result object provider that merges multiple result object provider
+ * delegates. Support exists for maintaining ordering of the internally held
+ * results, provided that each of the individual results is itself ordered.
+ *
+ * @author Abe White
+ * @author Marc Prud'hommeaux
*/
public class MergedResultObjectProvider implements ResultObjectProvider {
private static final byte UNOPENED = 0;
private static final byte OPENED = 1;
private static final byte VALUE = 2;
private static final byte DONE = 3;
+
private final ResultObjectProvider[] _rops;
private final Comparator _comp;
private final byte[] _status;
@@ -42,14 +38,14 @@
private int _size = -1;
/**
- * Constructor. Provide delegates.
+ * Constructor. Provide delegates.
*/
public MergedResultObjectProvider(ResultObjectProvider[] rops) {
this(rops, null);
}
/**
- * Constructor. Provide delegates and optional comparator.
+ * Constructor. Provide delegates and optional comparator.
*/
public MergedResultObjectProvider(ResultObjectProvider[] rops,
Comparator comp) {
@@ -67,7 +63,6 @@
public void open() throws Exception {
// if we have a comparator, then open all; else open first
int len = (_comp != null) ? _rops.length : 1;
-
for (int i = 0; i < len; i++) {
_rops[i].open();
_status[i] = OPENED;
@@ -79,9 +74,8 @@
}
public int size() throws Exception {
- if (_size != -1) {
+ if (_size != -1)
return _size;
- }
// have to open all to get sizes
for (int i = 0; i < _status.length; i++) {
@@ -93,139 +87,106 @@
int total = 0;
int size;
-
for (int i = 0; i < _rops.length; i++) {
size = _rops[i].size();
-
if (size == Integer.MAX_VALUE) {
total = size;
-
break;
}
-
total += size;
}
-
_size = total;
-
return _size;
}
public void reset() throws Exception {
for (int i = 0; i < _rops.length; i++)
- if (_status[i] != UNOPENED) {
+ if (_status[i] != UNOPENED)
_rops[i].reset();
- }
-
clear();
}
public void close() throws Exception {
Exception err = null;
-
for (int i = 0; i < _rops.length; i++) {
try {
- if (_status[i] != UNOPENED) {
+ if (_status[i] != UNOPENED)
_rops[i].close();
- }
} catch (Exception e) {
- if (err == null) {
+ if (err == null)
err = e;
- }
}
}
clear();
-
- if (err != null) {
+ if (err != null)
throw err;
- }
}
private void clear() {
_cur = null;
-
for (int i = 0; i < _rops.length; i++) {
_status[i] = OPENED;
-
- if (_values != null) {
+ if (_values != null)
_values[i] = null;
- }
-
- if (_orderValues != null) {
+ if (_orderValues != null)
_orderValues[i] = null;
- }
}
}
public void handleCheckedException(Exception e) {
- if (_rops.length == 0) {
+ if (_rops.length == 0)
throw new NestableRuntimeException(e);
- }
-
_rops[0].handleCheckedException(e);
}
public boolean next() throws Exception {
// initialize all rops with the latest values
boolean hasValue = false;
-
for (int i = 0; i < _status.length; i++) {
switch (_status[i]) {
case UNOPENED:
// this will only ever be the case if we aren't ordering
_rops[i].open();
_status[i] = OPENED;
-
- // no break
+ // no break
case OPENED:
-
// if this rop has a value, cache it; if we're not ordering,
// then that's the value to return
if (_rops[i].next()) {
if (_comp == null) {
_cur = _rops[i].getResultObject();
-
return true;
} else {
hasValue = true;
_status[i] = VALUE;
_values[i] = _rops[i].getResultObject();
- _orderValues[i] = getOrderingValue(_values[i], i,
- _rops[i]);
+ _orderValues[i] = getOrderingValue(_values[i],
+ i, _rops[i]);
}
- } else {
+ } else
_status[i] = DONE;
- }
-
break;
-
case VALUE:
// we only use this state when ordering
hasValue = true;
-
break;
}
}
// if we get to this point without a comparator, it means none
// of our rops have any more values
- if ((_comp == null) || !hasValue) {
+ if (_comp == null || !hasValue)
return false;
- }
// for all the rops with values, find the 'least' one according to
// the comparator
int least = -1;
Object orderVal = null;
-
for (int i = 0; i < _orderValues.length; i++) {
- if (_status[i] != VALUE) {
+ if (_status[i] != VALUE)
continue;
- }
-
- if ((least == -1) ||
- (_comp.compare(_orderValues[i], orderVal) < 0)) {
+ if (least == -1 || _comp.compare(_orderValues[i], orderVal) < 0) {
least = i;
orderVal = _orderValues[i];
}
@@ -238,7 +199,6 @@
_values[least] = null;
_orderValues[least] = null;
_status[least] = OPENED;
-
return true;
}
@@ -247,14 +207,13 @@
}
/**
- * Return the value to use for ordering on the given result value. Returns
- * the result value by default.
- *
- * @param val the result value
- * @param idx the index of the result object provider in the array
- * given on construction that produced the result value
- * @param rop the result object provider that produced the result
- * value
+ * Return the value to use for ordering on the given result value. Returns
+ * the result value by default.
+ *
+ * @param val the result value
+ * @param idx the index of the result object provider in the array
+ * given on construction that produced the result value
+ * @param rop the result object provider that produced the result value
*/
protected Object getOrderingValue(Object val, int idx,
ResultObjectProvider rop) {
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RandomAccessResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RandomAccessResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RandomAccessResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RandomAccessResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,20 +12,18 @@
*/
package org.apache.openjpa.lib.rop;
-import serp.util.*;
-
import java.io.*;
-
import java.util.*;
-
+import serp.util.*;
/**
- * <p>Random-access result list implementation. It maintains a map
- * of the items that we have already instantiated.</p>
- *
- * @author Marc Prud'hommeaux
- * @author Abe White
- * @nojavadoc */
+ * Random-access result list implementation. It maintains a map
+ * of the items that we have already instantiated.
+ *
+ * @author Marc Prud'hommeaux
+ * @author Abe White
+ * @nojavadoc
+ */
public class RandomAccessResultList extends AbstractNonSequentialResultList {
private static final int OPEN = 0;
private static final int FREED = 1;
@@ -62,8 +57,8 @@
}
/**
- * Override this method to control what kind of map is used for
- * the instantiated rows.
+ * Override this method to control what kind of map is used for
+ * the instantiated rows.
*/
protected Map newRowMap() {
return new HashMap();
@@ -86,52 +81,41 @@
protected Object getInternal(int index) {
if (_full != null) {
- if (index >= _full.length) {
+ if (index >= _full.length)
return PAST_END;
- }
-
return _full[index];
}
Integer i = Numbers.valueOf(index);
Object ret = _rows.get(i);
-
if (ret != null) {
- if (ret instanceof Null) {
+ if (ret instanceof Null)
return null;
- }
-
return ret;
}
ret = instantiateRow(i);
-
- return (ret == null) ? PAST_END : ret;
+ return(ret == null) ? PAST_END : ret;
}
/**
- * Instantiate the row object at the specified index.
+ * Instantiate the row object at the specified index.
*/
private Object instantiateRow(Integer i) {
_requests++;
-
try {
- if (!_rop.absolute(i.intValue())) {
+ if (!_rop.absolute(i.intValue()))
return PAST_END;
- }
Object ob = _rop.getResultObject();
-
- if (ob == null) {
+ if (ob == null)
ob = new Null();
- }
// cache the result
_rows.put(i, ob);
// check to see if our map is full
checkComplete();
-
return ob;
} catch (RuntimeException re) {
close();
@@ -139,29 +123,25 @@
} catch (Exception e) {
close();
_rop.handleCheckedException(e);
-
return null;
}
}
/**
- * Check to see if the soft map is the same size as all the
- * rows in the Result: if so, we copy over the values to a
- * hard reference HashSet and close the Result object associated with
- * this endeavour.
+ * Check to see if the soft map is the same size as all the
+ * rows in the Result: if so, we copy over the values to a
+ * hard reference HashSet and close the Result object associated with
+ * this endeavour.
*/
private void checkComplete() {
// only check if we've actually gotten the size for some reason already
- if ((_size == -1) || (_rows.size() != _size)) {
+ if (_size == -1 || _rows.size() != _size)
return;
- }
Object[] full = new Object[_size];
int count = 0;
Integer key;
-
- for (Iterator itr = _rows.keySet().iterator(); itr.hasNext();
- count++) {
+ for (Iterator itr = _rows.keySet().iterator(); itr.hasNext(); count++) {
key = (Integer) itr.next();
full[key.intValue()] = _rows.get(key);
}
@@ -177,18 +157,12 @@
public int size() {
assertOpen();
-
- if (_size != -1) {
+ if (_size != -1)
return _size;
- }
-
- if (_full != null) {
+ if (_full != null)
return _full.length;
- }
-
try {
_size = _rop.size();
-
return _size;
} catch (RuntimeException re) {
close();
@@ -196,44 +170,36 @@
} catch (Exception e) {
close();
_rop.handleCheckedException(e);
-
return -1;
}
}
private void free() {
if (_state == OPEN) {
- try {
- _rop.close();
- } catch (Exception e) {
- }
-
+ try { _rop.close(); } catch (Exception e) {}
_rows = null;
_state = FREED;
}
}
public Object writeReplace() throws ObjectStreamException {
- if (_full != null) {
+ if (_full != null)
return new ListResultList(Arrays.asList(_full));
- }
-
ArrayList list = new ArrayList();
-
for (Iterator itr = iterator(); itr.hasNext();)
list.add(itr.next());
-
return list;
}
public String toString() {
- return getClass().getName() + "; identity: " +
- System.identityHashCode(this) + "; cached: " + _rows.size() +
- "; requests: " + _requests;
+ return getClass().getName()
+ + "; identity: " + System.identityHashCode(this)
+ + "; cached: " + _rows.size()
+ + "; requests: " + _requests;
}
public int hashCode() {
- // superclass tries to traverses entire list for hashcode
+ // superclass tries to traverses entire list for hashcode
return System.identityHashCode(this);
}
@@ -243,11 +209,12 @@
}
/**
- * Used to represent nulls in the result list. Can't use a singleton
- * pattern, because then there will always be a hard ref to all the
- * nulls, and they'll never get GC'd; this is bad in the unlikely
- * event of a huge result set with lots of nulls.
+ * Used to represent nulls in the result list. Can't use a singleton
+ * pattern, because then there will always be a hard ref to all the
+ * nulls, and they'll never get GC'd; this is bad in the unlikely
+ * event of a huge result set with lots of nulls.
*/
private static class Null {
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,50 +12,47 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.openjpa.lib.util.*;
-
import java.util.*;
-
+import org.apache.openjpa.lib.util.*;
/**
- * <p>Prevents a view of a given range of indices from the delegate
- * result object provider.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * Prevents a view of a given range of indices from the delegate
+ * result object provider.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class RangeResultObjectProvider implements ResultObjectProvider {
- private static final Localizer _loc = Localizer.forPackage(RangeResultObjectProvider.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (RangeResultObjectProvider.class);
+
private final ResultObjectProvider _delegate;
private final int _startIdx;
private final int _endIdx;
private int _idx = -1;
/**
- * Constructor. Because this is a wrapper around some delegate,
- * and result object providers work with int indexes, neither the start
- * or end index can be greater than Integer.MAX_VALUE (with the exception
- * of Long.MAX_VALUE, which is used to indicate no limit).
- *
- * @param delegate the result object provider to delegate to
- * @param startIdx 0-based inclusive start index of the range
- * to present; must be < Integer.MAX_VALUE
- * @param endIdx 0-based exclusive end index of the range to
- * present; must be < Integer.MAX_VALUE, or
- * Long.MAX_VALUE for no limit
- */
+ * Constructor. Because this is a wrapper around some delegate,
+ * and result object providers work with int indexes, neither the start
+ * or end index can be greater than Integer.MAX_VALUE(with the exception
+ * of Long.MAX_VALUE, which is used to indicate no limit).
+ *
+ * @param delegate the result object provider to delegate to
+ * @param startIdx 0-based inclusive start index of the range
+ * to present; must be < Integer.MAX_VALUE
+ * @param endIdx 0-based exclusive end index of the range to
+ * present; must be < Integer.MAX_VALUE, or Long.MAX_VALUE for no limit
+ */
public RangeResultObjectProvider(ResultObjectProvider delegate,
long startIdx, long endIdx) {
// use Integer.MAX_VALUE for no limit internally
- if (endIdx == Long.MAX_VALUE) {
+ if (endIdx == Long.MAX_VALUE)
endIdx = Integer.MAX_VALUE;
- }
_delegate = delegate;
-
- if ((startIdx > Integer.MAX_VALUE) || (endIdx > Integer.MAX_VALUE)) {
+ if (startIdx > Integer.MAX_VALUE || endIdx > Integer.MAX_VALUE)
throw new IllegalArgumentException(_loc.get("range-too-high",
- String.valueOf(startIdx), String.valueOf(endIdx)));
- }
+ String.valueOf(startIdx), String.valueOf(endIdx)));
_startIdx = (int) startIdx;
_endIdx = (int) endIdx;
@@ -73,61 +67,46 @@
}
public Object getResultObject() throws Exception {
- if ((_idx < _startIdx) || (_idx >= _endIdx)) {
+ if (_idx < _startIdx || _idx >= _endIdx)
throw new NoSuchElementException(String.valueOf(_idx));
- }
-
return _delegate.getResultObject();
}
public boolean next() throws Exception {
// advance up to just behind _startIdx if we haven't already
- while (_idx < (_startIdx - 1)) {
+ while (_idx < _startIdx - 1) {
if (_delegate.supportsRandomAccess()) {
_idx = _startIdx - 1;
-
- if (!_delegate.absolute(_startIdx - 1)) {
+ if (!_delegate.absolute(_startIdx - 1))
return false;
- }
} else {
_idx++;
-
- if (!_delegate.next()) {
+ if (!_delegate.next())
return false;
- }
}
}
// make sure we're not falling off the end of the range
- if (_idx >= (_endIdx - 1)) {
+ if (_idx >= _endIdx - 1)
return false;
- }
_idx++;
-
return _delegate.next();
}
public boolean absolute(int pos) throws Exception {
_idx = pos + _startIdx;
-
- if (_idx >= _endIdx) {
+ if (_idx >= _endIdx)
return false;
- }
-
return _delegate.absolute(_idx);
}
public int size() throws Exception {
int size = _delegate.size();
-
- if (size == Integer.MAX_VALUE) {
+ if (size == Integer.MAX_VALUE)
return size;
- }
-
size = Math.min(_endIdx, size) - _startIdx;
-
- return (size < 0) ? 0 : size;
+ return(size < 0) ? 0 : size;
}
public void reset() throws Exception {
@@ -143,3 +122,4 @@
_delegate.handleCheckedException(e);
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultList.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultList.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,48 +12,42 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.openjpa.lib.util.*;
-import org.apache.openjpa.lib.util.Closeable;
-
import java.io.*;
-
import java.util.*;
import java.util.NoSuchElementException; // for javadoc; bug #4330419
-
+import org.apache.openjpa.lib.util.*;
+import org.apache.openjpa.lib.util.Closeable;
/**
- * <p>List interface that represents a potentially lazy ResultList
- * instantiation.</p>
- *
- * <p>A ResultList will typically be instantiated from a factory, and
- * will use a ResultObjectProvider for obtaining individual object
- * data representations.</p>
- *
- * <p>Depending on the support for scrolling inputs,
- * the list that is returned may use lazy instantiation of the
- * objects, and thus allow very large result sets to be obtained and
- * manipulated.</p>
- *
- * <p>Note that wrapping a ResultList in another Collection will
- * always instantiate the entire set of elements contained in the
- * ResultList. This may not always be desireable, since the list may
- * be very large.</p>
- *
- * @author Marc Prud'hommeaux
+ * List interface that represents a potentially lazy ResultList instantiation.
+ * A ResultList will typically be instantiated from a factory, and
+ * will use a ResultObjectProvider for obtaining individual object
+ * data representations.
+ * Depending on the support for scrolling inputs,
+ * the list that is returned may use lazy instantiation of the
+ * objects, and thus allow very large result sets to be obtained and
+ * manipulated.
+ * Note that wrapping a ResultList in another Collection will
+ * always instantiate the entire set of elements contained in the
+ * ResultList. This may not always be desireable, since the list may
+ * be very large.
+ *
+ * @author Marc Prud'hommeaux
*/
public interface ResultList extends List, Serializable, Closeable {
/**
- * Returns true if the provider backing this list is open.
+ * Returns true if the provider backing this list is open.
*/
public boolean isProviderOpen();
/**
- * Close the list.
+ * Close the list.
*/
public void close();
/**
- * Returns true if the list has been closed.
+ * Returns true if the list has been closed.
*/
public boolean isClosed();
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,19 +12,20 @@
*/
package org.apache.openjpa.lib.rop;
-import org.apache.openjpa.lib.util.*;
-
import java.util.*;
-
+import org.apache.openjpa.lib.util.*;
/**
- * Wrapper iterator that will return false for <code>hasNext()</code> if
- * the owning ResultList has been closed.
- *
- * @author Marc Prud'hommeaux
- * @nojavadoc */
+ * Wrapper iterator that will return false for <code>hasNext()</code> if
+ * the owning ResultList has been closed.
+ *
+ * @author Marc Prud'hommeaux
+ * @nojavadoc
+ */
public class ResultListIterator extends AbstractListIterator {
- private static final Localizer _loc = Localizer.forPackage(ResultListIterator.class);
+ private static final Localizer _loc = Localizer.forPackage(
+ ResultListIterator.class);
+
private final ListIterator _li;
private final ResultList _rl;
@@ -41,10 +39,8 @@
}
public boolean hasNext() {
- if (_rl.isClosed()) {
+ if (_rl.isClosed())
return false;
- }
-
return _li.hasNext();
}
@@ -53,10 +49,8 @@
}
public Object next() {
- if (_rl.isClosed()) {
+ if (_rl.isClosed())
throw new NoSuchElementException(_loc.get("closed"));
- }
-
return _li.next();
}
@@ -72,3 +66,4 @@
return _li.previousIndex();
}
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultObjectProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultObjectProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -17,79 +14,75 @@
import org.apache.openjpa.lib.util.*;
-
/**
- * <p>Interface that allows lazy/custom instantiation of input
- * objects.</p>
- *
- * <p>{@link ResultList} objects do not necessarily load in data all
- * at once. Instead, they may lazily load objects as necessary. So,
- * the lifespan of a {@link ResultObjectProvider} instance is
- * related to how the application deals with processing the
- * {@link ResultList} created with a given
- * {@link ResultObjectProvider} instance.</p>
- *
- * @author Marc Prud'hommeaux
- * @author Patrick Linskey
- * @author Abe White
+ * Interface that allows lazy/custom instantiation of input objects.
+ * {@link ResultList} objects do not necessarily load in data all
+ * at once. Instead, they may lazily load objects as necessary. So,
+ * the lifespan of a {@link ResultObjectProvider} instance is
+ * related to how the application deals with processing the
+ * {@link ResultList} created with a given
+ * {@link ResultObjectProvider} instance.
+ *
+ * @author Marc Prud'hommeaux
+ * @author Patrick Linskey
+ * @author Abe White
*/
public interface ResultObjectProvider extends Closeable {
/**
- * Return true if this provider supports random access.
+ * Return true if this provider supports random access.
*/
public boolean supportsRandomAccess();
/**
- * Open the result. This will be called before
- * {@link #next}, {@link #absolute}, or {@link #size}.
+ * Open the result. This will be called before
+ * {@link #next}, {@link #absolute}, or {@link #size}.
*/
public void open() throws Exception;
/**
- * Instantiate the current result object. This method will only be
- * called after {@link #next} or {@link #absolute}.
+ * Instantiate the current result object. This method will only be
+ * called after {@link #next} or {@link #absolute}.
*/
public Object getResultObject() throws Exception;
/**
- * Advance the input to the next position. Return <code>true</code> if
- * there is more data; otherwise <code>false</code>.
+ * Advance the input to the next position. Return <code>true</code> if
+ * there is more data; otherwise <code>false</code>.
*/
public boolean next() throws Exception;
/**
- * Move to the given 0-based position. This method is
- * only called for providers that support random access.
- * Return <code>true</code> if there is data at this position;
- * otherwise <code>false</code>. This may be invoked in place of
- * {@link #next}.
+ * Move to the given 0-based position. This method is
+ * only called for providers that support random access.
+ * Return <code>true</code> if there is data at this position;
+ * otherwise <code>false</code>. This may be invoked in place of
+ * {@link #next}.
*/
public boolean absolute(int pos) throws Exception;
/**
- * Return the number of items in the input, or {@link Integer#MAX_VALUE}
- * if the size in unknown.
+ * Return the number of items in the input, or {@link Integer#MAX_VALUE}
+ * if the size in unknown.
*/
public int size() throws Exception;
/**
- * Reset this provider. This is an optional operation. If supported,
- * it should move the position of the provider to before the first
- * element. Non-random-access providers may be able to support this
- * method by re-acquiring all resources as if the result were
- * just opened.
+ * Reset this provider. This is an optional operation. If supported,
+ * it should move the position of the provider to before the first
+ * element. Non-random-access providers may be able to support this
+ * method by re-acquiring all resources as if the result were just opened.
*/
public void reset() throws Exception;
/**
- * Free the resources associated with this provider.
+ * Free the resources associated with this provider.
*/
public void close() throws Exception;
/**
- * Any checked exceptions that are thrown will be passed to this method.
- * The provider should re-throw the exception as an appropriate unchecked
- * exception.
+ * Any checked exceptions that are thrown will be passed to this method.
+ * The provider should re-throw the exception as an appropriate unchecked
+ * exception.
*/
public void handleCheckedException(Exception e);
}