Author: pnedonosko
Date: 2009-12-11 04:13:48 -0500 (Fri, 11 Dec 2009)
New Revision: 1000
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/ValueData.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
Log:
EXOJCR-274 rework of BLOBs processing on save
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/ValueData.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/ValueData.java 2009-12-11
09:05:22 UTC (rev 999)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/ValueData.java 2009-12-11
09:13:48 UTC (rev 1000)
@@ -65,7 +65,7 @@
byte[] getAsByteArray() throws IllegalStateException, IOException;
/**
- * Renders this value data as stream of bytes NOTE: client is responsible for closing
this stream,
+ * Renders this value data as stream of bytes. <br/>NOTE: client is responsible
for closing this stream,
* else IllegalStateException occurs in close().
*
* @return InputStream, this value data as stream of bytes
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java 2009-12-11
09:05:22 UTC (rev 999)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java 2009-12-11
09:13:48 UTC (rev 1000)
@@ -54,16 +54,49 @@
this.stream = stream;
}
+ /**
+ * Return original data stream or null. <br/>
+ * For transport from non-spooled TransientValueData to persistent layer.<br/>
+ * WARN: after the stream will be consumed it will not contains data anymore.
+ *
+ * @return InputStream data stream or null
+ * @throws IOException if error occurs
+ */
public InputStream getStream() throws IOException
{
+ // if (stream != null)
+ // {
+ // return stream;
+ // }
+ // else if (tempFile != null)
+ // {
+ // return new FileInputStream(tempFile);
+ // }
+ // else
+ // {
+ // return super.getAsStream();
+ // }
+
return stream;
}
- public File getTempFile() throws IOException
+ /**
+ * Return temp file or null. For transport from spooled TransientValueData to
persistent layer. <br/>
+ * WARN: after the save the temp file will be removed. So, temp file actual only
during the save from transient state.
+ *
+ * @return File temporary file or null
+ */
+ public File getTempFile()
{
return tempFile;
}
+ /**
+ * Sets persistent file. Will reset (null) temp file and stream. This method should be
called only from
+ * persistent layer (Value storage).
+ *
+ * @param file File
+ */
public void setPersistedFile(File file)
{
this.file = file;
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java 2009-12-11
09:05:22 UTC (rev 999)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java 2009-12-11
09:13:48 UTC (rev 1000)
@@ -132,30 +132,43 @@
else
{
// stream Value
- File tempFile;
- if ((tempFile = ((StreamPersistedValueData)value).getTempFile()) != null)
+ StreamPersistedValueData streamed = (StreamPersistedValueData)value;
+ if (streamed.isPersisted())
{
- // it's spooled Value, try move its file to VS
- if (!tempFile.renameTo(file))
+ // already persisted in another Value, copy it to this Value
+ // TODO should not occurs!
+ LOG.warn("File based persisted ValueData on save: " +
streamed.getFile().getAbsolutePath() + " -> "
+ + file.getAbsoluteFile());
+ copyClose(streamed.getAsStream(), new FileOutputStream(file));
+ }
+ else
+ {
+ File tempFile;
+ if ((tempFile = streamed.getTempFile()) != null)
{
- // not succeeded - copy bytes
- if (LOG.isDebugEnabled())
+ // it's spooled Value, try move its file to VS
+ if (!tempFile.renameTo(file))
{
- LOG
- .debug("Value spool file move (rename) to Values Storage is not
succeeded. Trying bytes copy. Spool file: "
- + tempFile.getAbsolutePath() + ". Destination: " +
file.getAbsolutePath());
+ // not succeeded - copy bytes
+ if (LOG.isDebugEnabled())
+ {
+ LOG
+ .debug("Value spool file move (rename) to Values Storage is
not succeeded. Trying bytes copy. Spool file: "
+ + tempFile.getAbsolutePath() + ". Destination: " +
file.getAbsolutePath());
+ }
+
+ copyClose(new FileInputStream(tempFile), new FileOutputStream(file));
}
-
- copyClose(new FileInputStream(tempFile), new FileOutputStream(file));
}
+ else
+ {
+ // not spooled, use InputStream
+ copyClose(streamed.getStream(), new FileOutputStream(file));
+ }
+
+ // map this transient Value to file in VS
+ streamed.setPersistedFile(file);
}
- else
- {
- // not spooled, use InputStream
- copyClose(((StreamPersistedValueData)value).getStream(), new
FileOutputStream(file));
- }
- // map this transient Value to file in VS
- ((StreamPersistedValueData)value).setPersistedFile(file);
}
}
@@ -178,11 +191,23 @@
}
else
{
- InputStream in = ((StreamPersistedValueData)value).getStream();
- if (in == null)
+ InputStream in;
+ StreamPersistedValueData streamed = (StreamPersistedValueData)value;
+ if (streamed.isPersisted())
{
- in = ((StreamPersistedValueData)value).getAsStream();
+ // already persisted in another Value, copy it to this Value
+ // TODO should not occurs!
+ LOG.warn("File based persisted ValueData on save: " +
streamed.getFile().getAbsolutePath() + " -> CAS");
+ in = streamed.getAsStream();
}
+ else
+ {
+ in = streamed.getStream();
+ if (in == null)
+ {
+ in = new FileInputStream(streamed.getTempFile());
+ }
+ }
try
{