*/\r
@OneToMany(cascade = CascadeType.ALL, mappedBy = "header")\r
@OrderBy("version")\r
- private List<FileBody> bodies;\r
+ private List<FileBody> bodies = new ArrayList<FileBody>();\r
\r
/**\r
* The current (most recent) body of this file. The single one if not\r
if (body.getHeader() != null)\r
throw new IllegalArgumentException("Trying to add a FileBody that already belongs to a FileHeader.");\r
\r
+ // Set child in parent\r
+ getBodies().add(body);\r
// Set parent in child\r
body.setHeader(this);\r
\r
throw new RuntimeException(e);\r
}\r
}\r
+\r
+ /**\r
+ * Return the total space occupied by this file in storage\r
+ * (i.e. the total size of all bodies)\r
+ * @return long\r
+ */\r
+ public long getTotalSize() {\r
+ long total = 0;\r
+ for (FileBody body: getBodies())\r
+ total += body.getFileSize();\r
+ return total;\r
+ }\r
}\r
\r