objectpersistencemanager.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 517 行 · 第 1/2 页
JAVA
517 行
/** * {@inheritDoc} */ public synchronized NodeReferences load(NodeReferencesId id) throws NoSuchItemStateException, ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String refsFilePath = buildNodeReferencesFilePath(id); try { if (!itemStateFS.isFile(refsFilePath)) { throw new NoSuchItemStateException(id.toString()); } } catch (FileSystemException fse) { String msg = "failed to load references: " + id; log.debug(msg); throw new ItemStateException(msg, fse); } try { BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(refsFilePath)); try { NodeReferences refs = new NodeReferences(id); Serializer.deserialize(refs, in); return refs; } finally { in.close(); } } catch (Exception e) { String msg = "failed to load references: " + id; log.debug(msg); throw new ItemStateException(msg, e); } } /** * {@inheritDoc} */ protected void store(NodeState state) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String nodeFilePath = buildNodeFilePath(state.getNodeId()); FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath); try { nodeFile.makeParentDirs(); BufferedOutputStream out = new BufferedOutputStream(nodeFile.getOutputStream()); try { // serialize node state Serializer.serialize(state, out); } finally { out.close(); } } catch (Exception e) { String msg = "failed to write node state: " + state.getNodeId(); log.debug(msg); throw new ItemStateException(msg, e); } } /** * {@inheritDoc} */ protected void store(PropertyState state) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String propFilePath = buildPropFilePath(state.getPropertyId()); FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath); try { propFile.makeParentDirs(); BufferedOutputStream out = new BufferedOutputStream(propFile.getOutputStream()); try { // serialize property state Serializer.serialize(state, out, blobStore); } finally { out.close(); } } catch (Exception e) { String msg = "failed to store property state: " + state.getParentId() + "/" + state.getName(); log.debug(msg); throw new ItemStateException(msg, e); } } /** * {@inheritDoc} */ protected void store(NodeReferences refs) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String refsFilePath = buildNodeReferencesFilePath(refs.getId()); FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath); try { refsFile.makeParentDirs(); OutputStream out = new BufferedOutputStream(refsFile.getOutputStream()); try { Serializer.serialize(refs, out); } finally { out.close(); } } catch (Exception e) { String msg = "failed to store references: " + refs.getId(); log.debug(msg); throw new ItemStateException(msg, e); } } /** * {@inheritDoc} */ protected void destroy(NodeState state) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String nodeFilePath = buildNodeFilePath(state.getNodeId()); FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath); try { if (nodeFile.exists()) { // delete resource and prune empty parent folders nodeFile.delete(true); } } catch (FileSystemException fse) { String msg = "failed to delete node state: " + state.getNodeId(); log.debug(msg); throw new ItemStateException(msg, fse); } } /** * {@inheritDoc} */ protected void destroy(PropertyState state) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } // delete binary values (stored as files) InternalValue[] values = state.getValues(); if (values != null) { for (int i = 0; i < values.length; i++) { InternalValue val = values[i]; if (val != null) { if (val.getType() == PropertyType.BINARY) { BLOBFileValue blobVal = (BLOBFileValue) val.internalValue(); // delete blob file and prune empty parent folders blobVal.delete(true); } } } } // delete property file String propFilePath = buildPropFilePath(state.getPropertyId()); FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath); try { if (propFile.exists()) { // delete resource and prune empty parent folders propFile.delete(true); } } catch (FileSystemException fse) { String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName(); log.debug(msg); throw new ItemStateException(msg, fse); } } /** * {@inheritDoc} */ protected void destroy(NodeReferences refs) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } String refsFilePath = buildNodeReferencesFilePath(refs.getId()); FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath); try { if (refsFile.exists()) { // delete resource and prune empty parent folders refsFile.delete(true); } } catch (FileSystemException fse) { String msg = "failed to delete node references: " + refs.getId(); log.debug(msg); throw new ItemStateException(msg, fse); } } /** * {@inheritDoc} */ public synchronized boolean exists(PropertyId id) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } try { String propFilePath = buildPropFilePath(id); FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath); return propFile.exists(); } catch (FileSystemException fse) { String msg = "failed to check existence of item state: " + id; log.debug(msg); throw new ItemStateException(msg, fse); } } /** * {@inheritDoc} */ public synchronized boolean exists(NodeId id) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } try { String nodeFilePath = buildNodeFilePath(id); FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath); return nodeFile.exists(); } catch (FileSystemException fse) { String msg = "failed to check existence of item state: " + id; log.error(msg, fse); throw new ItemStateException(msg, fse); } } /** * {@inheritDoc} */ public synchronized boolean exists(NodeReferencesId id) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } try { String refsFilePath = buildNodeReferencesFilePath(id); FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath); return refsFile.exists(); } catch (FileSystemException fse) { String msg = "failed to check existence of references: " + id; log.debug(msg); throw new ItemStateException(msg, fse); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?