diff --git a/pom.xml b/pom.xml
index efa30a704..d6b9c1b1c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -218,7 +218,7 @@
single-table-inheritance
dynamic-proxy
gateway
- slob
+ serialized-lob
server-session
virtual-proxy
diff --git a/serialized-lob/README.md b/serialized-lob/README.md
new file mode 100644
index 000000000..c1386a369
--- /dev/null
+++ b/serialized-lob/README.md
@@ -0,0 +1,138 @@
+---
+title: Serialized LOB
+category: Data access
+language: en
+tag:
+ - Data access
+ - Data processing
+ - Persistence
+---
+
+## Also known as
+
+* Serialized Large Object
+* Serialized BLOB
+* Serialized CLOB
+
+## Intent
+
+To manage and store large objects (LOBs) like files, images, or large strings in a database efficiently using serialization.
+
+## Explanation
+
+Real-world example
+
+> Consider a social media platform where users can upload and share images and videos. Instead of storing these large multimedia files on a separate file server, the platform uses the Serialized LOB design pattern to store the files directly in the database. Each uploaded image or video is serialized into a binary large object (BLOB) and stored within the user's record. This approach ensures that the multimedia files are managed within the same transactional context as other user data, providing consistency and simplifying data access and retrieval.
+
+In plain words
+
+> The Serialized LOB design pattern manages the storage of large objects, such as files or multimedia, by serializing and storing them directly within a database.
+
+**Programmatic Example**
+
+The Serialized Large Object (LOB) design pattern is a way to handle large objects in a database. It involves serializing an object graph into a single large object (a BLOB or CLOB, for Binary Large Object or Character Large Object, respectively) and storing it in the database. When the object graph needs to be retrieved, it is read from the database and deserialized back into the original object graph.
+
+Here's a programmatic example of the Serialized LOB design pattern:
+
+```java
+public abstract class LobSerializer implements AutoCloseable {
+ // ... omitted for brevity
+ public abstract Object serialize(Forest toSerialize) throws Exception;
+ public abstract Forest deSerialize(Object toDeserialize) throws Exception;
+ // ... omitted for brevity
+}
+```
+
+The `LobSerializer` class is an abstract class that provides the structure for serializing and deserializing objects. It has two abstract methods: `serialize` and `deSerialize`. These methods are implemented by the subclasses `ClobSerializer` and `BlobSerializer`.
+
+```java
+public class ClobSerializer extends LobSerializer {
+ // ... omitted for brevity
+ @Override
+ public Object serialize(Forest forest) throws ParserConfigurationException, TransformerException {
+ // ... omitted for brevity
+ }
+
+ @Override
+ public Forest deSerialize(Object toDeserialize)
+ throws ParserConfigurationException, IOException, SAXException {
+ // ... omitted for brevity
+ }
+}
+```
+
+The `ClobSerializer` class provides an implementation for serializing and deserializing objects into XML strings. The `serialize` method converts a `Forest` object into an XML string, and the `deSerialize` method converts an XML string back into a `Forest` object.
+
+```java
+public class BlobSerializer extends LobSerializer {
+ // ... omitted for brevity
+ @Override
+ public Object serialize(Forest toSerialize) throws IOException {
+ // ... omitted for brevity
+ }
+
+ @Override
+ public Forest deSerialize(Object toDeserialize) throws IOException, ClassNotFoundException {
+ // ... omitted for brevity
+ }
+}
+```
+
+The `BlobSerializer` class provides an implementation for serializing and deserializing objects into binary data. The `serialize` method converts a `Forest` object into binary data, and the `deSerialize` method converts binary data back into a `Forest` object.
+
+```java
+// The App class uses the LobSerializer to serialize and deserialize a Forest object.
+public class App {
+ // ... omitted for brevity
+ public static void main(String[] args) throws SQLException {
+ Forest forest = createForest();
+ LobSerializer serializer = createLobSerializer(args);
+ executeSerializer(forest, serializer);
+ }
+ // ... omitted for brevity
+}
+```
+
+The `App` class uses the `LobSerializer` to serialize and deserialize a `Forest` object. The `main` method creates a `Forest` object, creates a `LobSerializer` (either a `ClobSerializer` or a `BlobSerializer`), and then uses the `LobSerializer` to serialize and deserialize the `Forest` object.
+
+## Class diagram
+
+
+
+## Applicability
+
+* Use when you need to store large objects in a database and want to optimize data access and storage.
+* Ideal for applications that deal with large binary or character data such as multimedia files, logs, or documents.
+
+## Known Uses
+
+* Storing and retrieving images or multimedia files in a database.
+* Managing large text documents or logs in enterprise applications.
+* Handling binary data in applications that require efficient data retrieval and storage.
+
+## Consequences
+
+Benefits:
+
+* Simplifies the handling of large objects by leveraging Java serialization.
+* Reduces the need for external file storage systems.
+* Ensures consistency by storing LOBs within the same transactional context as other data.
+
+Trade-offs:
+
+* Increases database size due to the storage of serialized data.
+* Potential performance overhead during serialization and deserialization.
+* Requires careful management of serialization format to maintain backward compatibility.
+
+## Related Patterns
+
+* [DAO (Data Access Object)](https://java-design-patterns.com/patterns/dao/): Often used in conjunction with Serialized LOB to encapsulate data access logic.
+* Active Record: Can use Serialized LOB for managing large data within the same record.
+* [Repository](https://java-design-patterns.com/patterns/repository/): Uses Serialized LOB to handle complex queries and data manipulation involving large objects.
+
+## Credits
+
+* [Effective Java](https://amzn.to/4cGk2Jz)
+* [Java Persistence with Hibernate](https://amzn.to/44tP1ox)
+* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
+* [Serialized LOB - Martin Fowler](https://martinfowler.com/eaaCatalog/serializedLOB.html) by Martin Fowler
diff --git a/slob/etc/slob.urm.puml b/serialized-lob/etc/serialized-lob.urm.puml
similarity index 100%
rename from slob/etc/slob.urm.puml
rename to serialized-lob/etc/serialized-lob.urm.puml
diff --git a/slob/etc/slob.urm.png b/serialized-lob/etc/slob.urm.png
similarity index 100%
rename from slob/etc/slob.urm.png
rename to serialized-lob/etc/slob.urm.png
diff --git a/serialized-lob/etc/slob.urm.puml b/serialized-lob/etc/slob.urm.puml
new file mode 100644
index 000000000..3e0c4c2e3
--- /dev/null
+++ b/serialized-lob/etc/slob.urm.puml
@@ -0,0 +1,122 @@
+@startuml
+package com.iluwatar.slob.lob {
+ class Animal {
+ - animalsEaten : Set
+ - name : String
+ - plantsEaten : Set
+ + Animal()
+ + Animal(name : String, plantsEaten : Set, animalsEaten : Set)
+ # canEqual(other : Object) : boolean
+ + createObjectFromXml(node : Node)
+ + equals(o : Object) : boolean
+ + getAnimalsEaten() : Set
+ + getName() : String
+ + getPlantsEaten() : Set
+ + hashCode() : int
+ # iterateXmlForAnimalAndPlants(childNodes : NodeList, animalsEaten : Set, plantsEaten : Set) {static}
+ + setAnimalsEaten(animalsEaten : Set)
+ + setName(name : String)
+ + setPlantsEaten(plantsEaten : Set)
+ + toString() : String
+ + toXmlElement(xmlDoc : Document) : Element
+ }
+ class Forest {
+ - animals : Set
+ - name : String
+ - plants : Set
+ + Forest()
+ + Forest(name : String, animals : Set, plants : Set)
+ # canEqual(other : Object) : boolean
+ + createObjectFromXml(document : Document)
+ + equals(o : Object) : boolean
+ + getAnimals() : Set
+ + getName() : String
+ + getPlants() : Set
+ - getXmlDoc() : Document
+ + hashCode() : int
+ + setAnimals(animals : Set)
+ + setName(name : String)
+ + setPlants(plants : Set)
+ + toString() : String
+ + toXmlElement() : Element
+ }
+ class Plant {
+ - name : String
+ - type : String
+ + Plant()
+ + Plant(name : String, type : String)
+ # canEqual(other : Object) : boolean
+ + createObjectFromXml(node : Node)
+ + equals(o : Object) : boolean
+ + getName() : String
+ + getType() : String
+ + hashCode() : int
+ + setName(name : String)
+ + setType(type : String)
+ + toString() : String
+ + toXmlElement(xmlDoc : Document) : Element
+ }
+}
+package com.iluwatar.slob.serializers {
+ class BlobSerializer {
+ + TYPE_OF_DATA_FOR_DB : String {static}
+ + BlobSerializer()
+ + deSerialize(toDeserialize : Object) : Forest
+ + serialize(toSerialize : Forest) : Object
+ }
+ class ClobSerializer {
+ + TYPE_OF_DATA_FOR_DB : String {static}
+ + ClobSerializer()
+ + deSerialize(toDeserialize : Object) : Forest
+ - elementToXmlString(node : Element) : String {static}
+ + serialize(forest : Forest) : Object
+ }
+ abstract class LobSerializer {
+ - databaseService : DatabaseService
+ # LobSerializer(dataTypeDb : String)
+ + close()
+ + deSerialize(Object) : Forest {abstract}
+ + loadFromDb(id : int, columnName : String) : Object
+ + persistToDb(id : int, name : String, object : Object) : int
+ + serialize(Forest) : Object {abstract}
+ }
+}
+package com.iluwatar.slob.dbservice {
+ class DatabaseService {
+ + BINARY_DATA : String {static}
+ + CREATE_BINARY_SCHEMA_DDL : String {static}
+ + CREATE_TEXT_SCHEMA_DDL : String {static}
+ - DB_URL : String {static}
+ + DELETE_SCHEMA_SQL : String {static}
+ - INSERT : String {static}
+ - LOGGER : Logger {static}
+ - SELECT : String {static}
+ - dataSource : DataSource {static}
+ + dataTypeDb : String
+ + DatabaseService(dataTypeDb : String)
+ - createDataSource() : DataSource {static}
+ + insert(id : int, name : String, data : Object)
+ + select(id : long, columnsName : String) : Object
+ + shutDownService()
+ + startupService()
+ }
+}
+package com.iluwatar.slob {
+ class App {
+ + CLOB : String {static}
+ - LOGGER : Logger {static}
+ + App()
+ - createForest() : Forest {static}
+ - createLobSerializer(args : String[]) : LobSerializer {static}
+ - executeSerializer(forest : Forest, lobSerializer : LobSerializer) {static}
+ + main(args : String[]) {static}
+ }
+}
+Animal --> "-plantsEaten" Plant
+LobSerializer --> "-databaseService" DatabaseService
+Forest --> "-animals" Animal
+Forest --> "-plants" Plant
+Animal --> "-animalsEaten" Animal
+BlobSerializer --|> LobSerializer
+ClobSerializer --|> LobSerializer
+@enduml
\ No newline at end of file
diff --git a/slob/etc/slob.urm.uml b/serialized-lob/etc/slob.urm.uml
similarity index 100%
rename from slob/etc/slob.urm.uml
rename to serialized-lob/etc/slob.urm.uml
diff --git a/slob/pom.xml b/serialized-lob/pom.xml
similarity index 98%
rename from slob/pom.xml
rename to serialized-lob/pom.xml
index 4fc040ccf..95faa97d3 100644
--- a/slob/pom.xml
+++ b/serialized-lob/pom.xml
@@ -29,7 +29,7 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- slob
+ serialized-lob
4.0.0
java-design-patterns
diff --git a/slob/src/main/java/com/iluwatar/slob/App.java b/serialized-lob/src/main/java/com/iluwatar/slob/App.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/App.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/App.java
diff --git a/slob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java b/serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java
diff --git a/slob/src/main/java/com/iluwatar/slob/lob/Animal.java b/serialized-lob/src/main/java/com/iluwatar/slob/lob/Animal.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/lob/Animal.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/lob/Animal.java
diff --git a/slob/src/main/java/com/iluwatar/slob/lob/Forest.java b/serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/lob/Forest.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java
diff --git a/slob/src/main/java/com/iluwatar/slob/lob/Plant.java b/serialized-lob/src/main/java/com/iluwatar/slob/lob/Plant.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/lob/Plant.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/lob/Plant.java
diff --git a/slob/src/main/java/com/iluwatar/slob/serializers/BlobSerializer.java b/serialized-lob/src/main/java/com/iluwatar/slob/serializers/BlobSerializer.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/serializers/BlobSerializer.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/serializers/BlobSerializer.java
diff --git a/slob/src/main/java/com/iluwatar/slob/serializers/ClobSerializer.java b/serialized-lob/src/main/java/com/iluwatar/slob/serializers/ClobSerializer.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/serializers/ClobSerializer.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/serializers/ClobSerializer.java
diff --git a/slob/src/main/java/com/iluwatar/slob/serializers/LobSerializer.java b/serialized-lob/src/main/java/com/iluwatar/slob/serializers/LobSerializer.java
similarity index 100%
rename from slob/src/main/java/com/iluwatar/slob/serializers/LobSerializer.java
rename to serialized-lob/src/main/java/com/iluwatar/slob/serializers/LobSerializer.java
diff --git a/slob/src/test/java/com/iluwatar/slob/AppTest.java b/serialized-lob/src/test/java/com/iluwatar/slob/AppTest.java
similarity index 100%
rename from slob/src/test/java/com/iluwatar/slob/AppTest.java
rename to serialized-lob/src/test/java/com/iluwatar/slob/AppTest.java
diff --git a/slob/README.md b/slob/README.md
deleted file mode 100644
index 13ef6cb63..000000000
--- a/slob/README.md
+++ /dev/null
@@ -1,354 +0,0 @@
----
-title: Serialized LOB
-category: Structural
-language: en
-tag:
- - Data access
----
-
-## Intent
-
-* Object models often contain complicated graphs of small objects. Much of the information in these
- structures isn’t in the objects but in the links between them.
-* Objects don’t have to be persisted as table rows related to each other.
-* Another form of persistence is serialization, where a whole graph of objects is written out as a
- single large object (LOB) in a table.
-
-## Explanation
-
-**In plain words**
-
-> The Forest here represents the object graph.
-> A forest contains animals and plants. As is in real life the forest object contains plants and
-> animals where some animals eat other animals and some eat only plants.
-> * These relationships are maintained in the Forest Object.
-> * There are 2 types of Serializers available ClobSerializer and BlobSerializer.
-> * ClobSerializer uses character or textual based serialization, here the Object graph is converted
-> * to XML and then stored as text in DB.
-> * BlobSerializer uses binary data for serialization, here the Object graph is converted to Byte
-> * Array and then stored as a blob in DB.
-
-**Programmatic Example**
-
-* Here is the `Animal` class. It represents the Animal object in the Forest. It contains the name of
- the animals in the forest and details of what they eat from the forest plants/animals or both.
-
-```java
-/**
- * Creates an object Forest which contains animals and plants as its constituents. Animals may eat
- * plants or other animals in the forest.
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class Forest implements Serializable {
-
- private String name;
- private final Set animals = new HashSet<>();
- private final Set plants = new HashSet<>();
-
- /**
- * Provides the representation of Forest in XML form.
- *
- * @return XML Element
- */
- public Element toXmlElement() throws ParserConfigurationException {
- Document xmlDoc = getXmlDoc();
-
- Element forestXml = xmlDoc.createElement("Forest");
- forestXml.setAttribute("name", name);
-
- Element animalsXml = xmlDoc.createElement("Animals");
- for (Animal animal : animals) {
- Element animalXml = animal.toXmlElement(xmlDoc);
- animalsXml.appendChild(animalXml);
- }
- forestXml.appendChild(animalsXml);
-
- Element plantsXml = xmlDoc.createElement("Plants");
- for (Plant plant : plants) {
- Element plantXml = plant.toXmlElement(xmlDoc);
- plantsXml.appendChild(plantXml);
- }
- forestXml.appendChild(plantsXml);
- return forestXml;
- }
-
- /**
- * Returns XMLDoc to use for XML creation.
- *
- * @return XML DOC Object
- * @throws ParserConfigurationException {@inheritDoc}
- */
- private Document getXmlDoc() throws ParserConfigurationException {
- return DocumentBuilderFactory.newDefaultInstance().newDocumentBuilder().newDocument();
- }
-
- /**
- * Parses the Forest Object from the input XML Document.
- *
- * @param document the XML document from which the Forest is to be parsed
- */
- public void createObjectFromXml(Document document) {
- name = document.getDocumentElement().getAttribute("name");
- NodeList nodeList = document.getElementsByTagName("*");
- iterateXmlForAnimalAndPlants(nodeList, animals, plants);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("\n");
- sb.append("Forest Name = ").append(name).append("\n");
- sb.append("Animals found in the ").append(name).append(" Forest: \n");
- for (Animal animal : animals) {
- sb.append("\n--------------------------\n");
- sb.append(animal.toString());
- sb.append("\n--------------------------\n");
- }
- sb.append("\n");
- sb.append("Plants in the ").append(name).append(" Forest: \n");
- for (Plant plant : plants) {
- sb.append("\n--------------------------\n");
- sb.append(plant.toString());
- sb.append("\n--------------------------\n");
- }
- return sb.toString();
- }
-}
-```
-
-* Here is the `LobSerializer` abstract class. It provides the specification to serialize and
- deserialize the input object and persist and load that object into a DB.
-
-```java
-/**
- * A LobSerializer can be used to create an instance of a serializer which can serialize and
- * deserialize an object and persist and load that object into a DB. from their Binary
- * Representation.
- */
-public abstract class LobSerializer implements Serializable, Closeable {
-
- private final transient DatabaseService databaseService;
-
- /**
- * Constructor initializes {@link LobSerializer#databaseService}.
- *
- * @param dataTypeDb Input provides type of Data to be stored by the Data Base Service
- * @throws SQLException If any issue occurs during instantiation of DB Service or during startup.
- */
- protected LobSerializer(String dataTypeDb) throws SQLException {
- databaseService = new DatabaseService(dataTypeDb);
- databaseService.startupService();
- }
-
- /**
- * Provides the specification to Serialize the input object.
- *
- * @param toSerialize Input Object to serialize
- * @return Serialized Object
- * @throws ParserConfigurationException if any issue occurs during parsing of input object
- * @throws TransformerException if any issue occurs during Transformation
- * @throws IOException if any issues occur during reading object
- */
- public abstract Object serialize(Forest toSerialize)
- throws ParserConfigurationException, TransformerException, IOException;
-
- /**
- * Saves the object to DB with the provided ID.
- *
- * @param id key to be sent to DB service
- * @param name Object name to store in DB
- * @param object Object to store in DB
- * @return ID with which the object is stored in DB
- * @throws SQLException if any issue occurs while saving to DB
- */
- public int persistToDb(int id, String name, Object object) throws SQLException {
- databaseService.insert(id, name, object);
- return id;
- }
-
- /**
- * Loads the object from db using the ID and column name.
- *
- * @param id to query the DB
- * @param columnName column from which object is to be extracted
- * @return Object from DB
- * @throws SQLException if any issue occurs while loading from DB
- */
- public Object loadFromDb(int id, String columnName) throws SQLException {
- return databaseService.select(id, columnName);
- }
-
- /**
- * Provides the specification to Deserialize the input object.
- *
- * @param toDeserialize object to deserialize
- * @return Deserialized Object
- * @throws ParserConfigurationException If issue occurs during parsing of input object
- * @throws IOException if any issues occur during reading object
- * @throws SAXException if any issues occur during reading object for XML parsing
- */
- public abstract Forest deSerialize(Object toDeserialize)
- throws ParserConfigurationException, IOException, SAXException, ClassNotFoundException;
-
- @Override
- public void close() {
- try {
- databaseService.shutDownService();
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-}
-```
-
-* Here is the `ClobSerializer` class. It extends the `LobSerializer` abstract class and provides the
- implementation to serialize and deserialize the input object and persist and load that object into
- a DB using ClobSerializer.
-* Objects are serialized using character or textual based serialization
- using XML to represent the object graph.
-
-```java
-
-/**
- * Creates a Serializer that uses Character based serialization and deserialization of objects graph
- * to and from XML Representation.
- */
-public class ClobSerializer extends LobSerializer {
-
- public static final String TYPE_OF_DATA_FOR_DB = "TEXT";
-
- public ClobSerializer() {
- super(TYPE_OF_DATA_FOR_DB);
- }
-
- /**
- * Converts the input node to its XML String Representation.
- *
- * @param node XML Node that is to be converted to string
- * @return String representation of XML parsed from the Node
- * @throws TransformerException If any issues occur in Transformation from Node to XML
- */
- private static String elementToXmlString(Element node) throws TransformerException {
- StringWriter sw = new StringWriter();
- Transformer t = TransformerFactory.newDefaultInstance().newTransformer();
- t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
- t.setOutputProperty(OutputKeys.INDENT, "yes");
- t.transform(new DOMSource(node), new StreamResult(sw));
- return sw.toString();
- }
-
- /**
- * Serializes the input object graph to its XML Representation using DOM Elements.
- *
- * @param forest Object which is to be serialized
- * @return Serialized object
- * @throws ParserConfigurationException If any issues occur in parsing input object
- * @throws TransformerException If any issues occur in Transformation from Node to XML
- */
- @Override
- public Object serialize(Forest forest) throws ParserConfigurationException, TransformerException {
- Element xmlElement = forest.toXmlElement();
- return elementToXmlString(xmlElement);
- }
-
- /**
- * Deserializes the input XML string using DOM Parser and return its Object Graph Representation.
- *
- * @param toDeserialize Input Object to De-serialize
- * @return Deserialized Object
- * @throws ParserConfigurationException If any issues occur in parsing input object
- * @throws IOException if any issues occur during reading object
- * @throws SAXException If any issues occur in Transformation from Node to XML
- */
- @Override
- public Forest deSerialize(Object toDeserialize)
- throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newDefaultInstance()
- .newDocumentBuilder();
- var stream = new ByteArrayInputStream(toDeserialize.toString().getBytes());
- Document parsed = documentBuilder.parse(stream);
- Forest forest = new Forest();
- forest.createObjectFromXml(parsed);
- return forest;
- }
-}
-```
-
-* Here is the `SlobSerializer` class. It extends the `LobSerializer` abstract class and provides the
- implementation to serialize and deserialize the input object and persist and load that object into
- a DB using ClobSerializer.
-* Objects are serialized using binary data based serialization objects a persisted as a BINARY/BLOB
- in DB.
-
-```java
-/**
- * Creates a Serializer that uses Binary serialization and deserialization of objects graph to and
- * from their Binary Representation.
- */
-public class BlobSerializer extends LobSerializer {
-
- public static final String TYPE_OF_DATA_FOR_DB = "BINARY";
-
- public BlobSerializer() throws SQLException {
- super(TYPE_OF_DATA_FOR_DB);
- }
-
- /**
- * Serializes the input object graph to its Binary Representation using Object Stream.
- *
- * @param toSerialize Object which is to be serialized
- * @return Serialized object
- * @throws IOException {@inheritDoc}
- */
- @Override
- public Object serialize(Forest toSerialize) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(toSerialize);
- oos.close();
- return new ByteArrayInputStream(baos.toByteArray());
- }
-
- /**
- * Deserializes the input Byte Array Stream using Object Stream and return its Object Graph
- * Representation.
- *
- * @param toDeserialize Input Object to De-serialize
- * @return Deserialized Object
- * @throws ClassNotFoundException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- */
- @Override
- public Forest deSerialize(Object toDeserialize) throws IOException, ClassNotFoundException {
- InputStream bis = (InputStream) toDeserialize;
- Forest forest;
- try (ObjectInput in = new ObjectInputStream(bis)) {
- forest = (Forest) in.readObject();
- }
- return forest;
- }
-}
-```
-
-## Class diagram
-
-
-
-## Applicability
-
-* This pattern works best when you can chop out a piece of the object model and use it to represent
- the LOB.
-* Think of a LOB as a way to take a bunch of objects that aren’t likely to be queried from any SQL
- route outside the application.
-* This graph can then be hooked into the SQL schema. Serialized LOB works poorly when you have
- objects outside the LOB reference objects buried in it.
-* Serialized LOB isn’t considered as often as it might be. XML makes it much more attractive since
- it yields an easy-to-implement textual approach.
-* Its main disadvantage is that you can’t query the structure using SQL.
-* SQL extensions appear to get at XML data within a field, but that’s still not the same (or
- portable).
-
-## Credits
-
-* [Serialized LOB](https://martinfowler.com/eaaCatalog/serializedLOB.html) by Martin Fowler