Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz980658 move blob content field out of HRawDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jul 23, 2013
1 parent 076b807 commit 2627b8b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 37 deletions.
9 changes: 0 additions & 9 deletions zanata-model/src/main/java/org/zanata/model/HRawDocument.java
Expand Up @@ -21,12 +21,10 @@
package org.zanata.model;

import java.io.Serializable;
import java.sql.Blob;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.OneToOne;

import lombok.Getter;
Expand All @@ -53,7 +51,6 @@ public class HRawDocument extends ModelEntityBase implements Serializable
// TODO none of these should allow null
private String contentHash;
private String contentLocation;
private Blob content;
private DocumentType type;
private String uploadedBy;

Expand All @@ -80,12 +77,6 @@ public String getContentHash()
return contentHash;
}

@Lob
public Blob getContent()
{
return content;
}

@Enumerated(EnumType.STRING)
public DocumentType getType()
{
Expand Down
67 changes: 39 additions & 28 deletions zanata-war/src/main/java/org/zanata/file/BlobPersistService.java
Expand Up @@ -66,40 +66,51 @@ public HDocumentUploadPart newUploadPartFromStream(InputStream partContentStream

public void persistRawDocumentContentFromFile(HRawDocument rawDocument, File rawFile)
{
FileInputStream tempFileStream;
try
{
tempFileStream = new FileInputStream(rawFile);
}
catch (FileNotFoundException e)
{
// TODO damason: throw more appropriate exception and handle in caller
log.error("Failed to open stream from temp source file", e);
throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
"Error saving uploaded document on server, download in original format may fail.\n",
e);
}
LobHelper lobHelper = documentDAO.getLobHelper();
Blob fileContents = lobHelper.createBlob(tempFileStream, (int) rawFile.length());
rawDocument.setContent(fileContents);
throw new RuntimeException("Migration of contents in progress, unable to persist file contents");

// FIXME temporary id assignment during blob migration - needs to be unique but only while
// migration is in progress.
String temporaryLocation = "document:" + rawDocument.getDocument().getId().toString();
rawDocument.setContentLocation(temporaryLocation);
// oldPersistRawDocumentContentFromFile(rawDocument, rawFile);
}

// private void oldPersistRawDocumentContentFromFile(HRawDocument rawDocument, File rawFile)
// {
// FileInputStream tempFileStream;
// try
// {
// tempFileStream = new FileInputStream(rawFile);
// }
// catch (FileNotFoundException e)
// {
// // TODO damason: throw more appropriate exception and handle in caller
// log.error("Failed to open stream from temp source file", e);
// throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
// "Error saving uploaded document on server, download in original format may fail.\n",
// e);
// }
// LobHelper lobHelper = documentDAO.getLobHelper();
// Blob fileContents = lobHelper.createBlob(tempFileStream, (int) rawFile.length());
//
// rawDocument.setContent(fileContents);
//
// // FIXME temporary id assignment during blob migration - needs to be unique but only while
// // migration is in progress.
// String temporaryLocation = "document:" + rawDocument.getDocument().getId().toString();
// rawDocument.setContentLocation(temporaryLocation);
// }

@Override
public InputStream getRawDocumentContentAsStream(HRawDocument document)
{
try
{
return document.getContent().getBinaryStream();
}
catch (SQLException e)
{
throw new RawDocumentContentAccessException(e);
}
throw new RawDocumentContentAccessException(
"Migration of contents in progress, unable to retrieve file contents");

// try
// {
// return document.getContent().getBinaryStream();
// }
// catch (SQLException e)
// {
// throw new RawDocumentContentAccessException(e);
// }
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions zanata-war/src/main/resources/db/changelogs/db.changelog-3.1.xml
Expand Up @@ -82,5 +82,30 @@
<addNotNullConstraint tableName="HRawDocument" columnName="contentLocation" columnDataType="longtext" />
</changeSet>

<changeSet author="damason@redhat.com" id="3">
<comment>Add temporary table for blobs during migration</comment>
<createTable tableName="HRawDocumentContent">
<column name="contentLocation" type="longtext">
<constraints nullable="false" />
</column>
<column name="content" type="longblob">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>

<changeSet author="damason@redhat.com" id="4">
<comment>Copy raw document content to HRawDocumentContent</comment>
<sql>
insert into HRawDocumentContent (contentLocation, content)
select contentLocation, content from HRawDocument
</sql>
</changeSet>

<changeSet author="damason@redhat.com" id="5">
<comment>Remove obsolete HRawDocument.content column</comment>
<dropColumn tableName="HRawDocument" columnName="content" />
</changeSet>


</databaseChangeLog>

0 comments on commit 2627b8b

Please sign in to comment.