Britt Park 8818e8daba Merged all the AVM mapping files into one medium file. I find it easier to follow.
Purged the pointless FileContentFactory class.  If everything else were working file reading
and writing would now work.  Various other cleanups and some richer internal documentation.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2904 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2006-05-16 22:55:37 +00:00

165 lines
5.3 KiB
Java

/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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 limitations under the
* License.
*/
package org.alfresco.repo.avm;
import org.alfresco.repo.avm.hibernate.BasicAttributesBean;
import org.alfresco.repo.avm.hibernate.BasicAttributesBeanImpl;
import org.alfresco.repo.avm.hibernate.ContentBean;
import org.alfresco.repo.avm.hibernate.ContentBeanImpl;
import org.alfresco.repo.avm.hibernate.PlainFileNodeBean;
import org.alfresco.repo.avm.hibernate.PlainFileNodeBeanImpl;
/**
* @author britt
*
*/
public class PlainFileNode extends FileNode
{
/**
* The data bean.
*/
private PlainFileNodeBean fData;
/**
* Construct one from its data bean.
* @param data The data bean.
*/
public PlainFileNode(PlainFileNodeBean data)
{
fData = data;
setDataBean(data);
}
/**
* Make one from just a repository.
* @param repos A Repository.
*/
public PlainFileNode(Repository repos)
{
ContentBean content = new ContentBeanImpl(repos.getSuperRepository().issueContentID());
long time = System.currentTimeMillis();
BasicAttributesBean attrs = new BasicAttributesBeanImpl("britt",
"britt",
"britt",
time,
time,
time);
repos.getSuperRepository().getSession().save(attrs);
fData = new PlainFileNodeBeanImpl(repos.getSuperRepository().issueID(),
-1,
-1,
null,
null,
null,
repos.getDataBean(),
attrs,
content);
content.setRefCount(1);
// Transitive persistence should take care of content.
repos.getSuperRepository().getSession().save(fData);
setDataBean(fData);
}
/**
* Copy on write constructor.
* @param other The node we are being copied from.
* @param repos The Repository.
*/
public PlainFileNode(PlainFileNode other,
Repository repos)
{
long time = System.currentTimeMillis();
BasicAttributesBean attrs = new BasicAttributesBeanImpl(other.getDataBean().getBasicAttributes());
attrs.setCreateDate(time);
attrs.setModDate(time);
attrs.setAccessDate(time);
repos.getSuperRepository().getSession().save(attrs);
fData = new PlainFileNodeBeanImpl(repos.getSuperRepository().issueID(),
-1,
-1,
null,
null,
null,
repos.getDataBean(),
attrs,
other.fData.getContent());
repos.getSuperRepository().getSession().save(fData);
fData.getContent().setRefCount(fData.getContent().getRefCount() + 1);
setDataBean(fData);
}
/**
* Handle setting repository after a COW.
* @param parent The possibly new parent directory.
*/
public void handlePostCopy(DirectoryNode parent)
{
if (parent != null)
{
setRepository(parent.getRepository());
}
}
/**
* Copy on write logic.
* @param lPath The lookup path.
*/
public AVMNode possiblyCopy(Lookup lPath)
{
if (!shouldBeCopied())
{
return null;
}
PlainFileNode newMe = new PlainFileNode(this, getRepository());
newMe.setAncestor(this);
newMe.setBranchID(lPath.getHighestBranch());
return newMe;
}
/**
* Get the type of this node.
* @return The type.
*/
public AVMNodeType getType()
{
return AVMNodeType.PLAIN_FILE;
}
/**
* Get content for reading.
*/
public FileContent getContentForRead(int version)
{
return new FileContent(fData.getContent());
}
/**
* Get content for writing.
* @param repo The Repository.
*/
public FileContent getContentForWrite(Repository repo)
{
if (fData.getContent().getRefCount() > 1)
{
fData.setContent(new ContentBeanImpl(repo.getSuperRepository().issueContentID()));
// Need to copy the underlying file data.
}
return new FileContent(fData.getContent());
}
}