Fast deserialization/reserialization is critical for databases. The key is to deserialize only what you need and to keep the serialized data for items that have not been changed for reserialization after an update.
Hibernate is a popular Java ORM tool that allows mapping of Java objects to database tables. It handles common persistence tasks like caching, lazy loading, and dirty checking automatically. Hibernate objects are simple POJOs that follow some conventions for mapping. The SessionFactory manages object-relational mappings and connections to the database, while Sessions represent a single-threaded conversation between the application and database.
This document discusses dependency injection and inversion of control containers. It explains that dependency injection means passing instance variables into a class rather than having the class create its own dependencies. This improves testability and loose coupling between classes. Inversion of control containers can manage dependencies and make dependency injection easier by automatically resolving dependencies. The document provides examples of configuring dependencies using an inversion of control container to handle instantiating classes and their dependencies.
- get() throws an ObjectNotFoundException if no data is found, while load() returns a proxy object without hitting the database
- When accessing properties of the proxy object returned by load(), it will trigger a SELECT to the database and throw an ObjectNotFoundException if no data exists
- get() immediately hits the database to check for data, while load() defers the database hit until property access if a proxy is returned
- It is generally better to use get() when you expect data to exist, and check for its return value being null, rather than using load()
Hibernate, created by Gavin King, known as the best and dominated object/relational persistence (ORM) tool for Java developers (Now is support .NET). It provides many elegant and innovative ways to simplifies the relational database handling task in Java.
Hibernate is great at a lot of things, but its something that needs to be used appropriately. In this tutorials, it providing many step by step examples and explanations on using Hibernate3
The document provides an overview of Java Persistence API (JPA) terminology and concepts. It defines key JPA terms like entity, persistence unit, entity manager, and persistence context. It describes entity characteristics and the different types of entity managers, persistence contexts, and transaction managers supported by JPA. The document also covers JPQL, query parameters, named queries, inheritance, collections, caching and more advanced JPA features.
The document discusses best practices for using the Java Persistence API (JPA). It covers:
- The entity manager and persistence context manage entities within a scope like a transaction.
- Entities transition between managed, detached, and removed states that impact database synchronization.
- Queries retrieve and manage entities from the persistence context and database.
- Transactions and locking strategies like optimistic and pessimistic concurrency control how changes are made.
- Extended and transaction scoped persistence contexts determine entity lifetime and caching.
- The second level cache can improve performance by caching entities across contexts.
JPA is a specification that defines a standard for object/relational persistence and object queries with Java. It allows developers to work with objects in Java code while the JPA implementation handles persistence to a relational database. Key aspects include entity objects that represent data, the EntityManager for CRUD operations, and JPQL for object-oriented queries. JPA supports both container-managed and resource-local transactions.
Hibernate is a popular Java ORM tool that allows mapping of Java objects to database tables. It handles common persistence tasks like caching, lazy loading, and dirty checking automatically. Hibernate objects are simple POJOs that follow some conventions for mapping. The SessionFactory manages object-relational mappings and connections to the database, while Sessions represent a single-threaded conversation between the application and database.
This document discusses dependency injection and inversion of control containers. It explains that dependency injection means passing instance variables into a class rather than having the class create its own dependencies. This improves testability and loose coupling between classes. Inversion of control containers can manage dependencies and make dependency injection easier by automatically resolving dependencies. The document provides examples of configuring dependencies using an inversion of control container to handle instantiating classes and their dependencies.
- get() throws an ObjectNotFoundException if no data is found, while load() returns a proxy object without hitting the database
- When accessing properties of the proxy object returned by load(), it will trigger a SELECT to the database and throw an ObjectNotFoundException if no data exists
- get() immediately hits the database to check for data, while load() defers the database hit until property access if a proxy is returned
- It is generally better to use get() when you expect data to exist, and check for its return value being null, rather than using load()
Hibernate, created by Gavin King, known as the best and dominated object/relational persistence (ORM) tool for Java developers (Now is support .NET). It provides many elegant and innovative ways to simplifies the relational database handling task in Java.
Hibernate is great at a lot of things, but its something that needs to be used appropriately. In this tutorials, it providing many step by step examples and explanations on using Hibernate3
The document provides an overview of Java Persistence API (JPA) terminology and concepts. It defines key JPA terms like entity, persistence unit, entity manager, and persistence context. It describes entity characteristics and the different types of entity managers, persistence contexts, and transaction managers supported by JPA. The document also covers JPQL, query parameters, named queries, inheritance, collections, caching and more advanced JPA features.
The document discusses best practices for using the Java Persistence API (JPA). It covers:
- The entity manager and persistence context manage entities within a scope like a transaction.
- Entities transition between managed, detached, and removed states that impact database synchronization.
- Queries retrieve and manage entities from the persistence context and database.
- Transactions and locking strategies like optimistic and pessimistic concurrency control how changes are made.
- Extended and transaction scoped persistence contexts determine entity lifetime and caching.
- The second level cache can improve performance by caching entities across contexts.
JPA is a specification that defines a standard for object/relational persistence and object queries with Java. It allows developers to work with objects in Java code while the JPA implementation handles persistence to a relational database. Key aspects include entity objects that represent data, the EntityManager for CRUD operations, and JPQL for object-oriented queries. JPA supports both container-managed and resource-local transactions.
The document discusses object-relational mapping and Hibernate. It describes common object-relational mismatches including problems of granularity, subtypes, associations, and data navigation. It then provides an overview of Hibernate and JPA, how to start a Hibernate project, POJOs, Hibernate APIs, configuration, annotations, identifier generators, dynamic SQL generation, immutable entities, property access strategies, generated property values, default property values, entities vs value types, and mapping of collection properties.
This document provides an overview of Hibernate, an object-relational mapping tool. It explains that Hibernate maps database tables to Java classes and vice versa, allowing developers to work with objects rather than SQL. Key benefits include better application architecture through separation of concerns, reduced time spent on standard database operations, and access to advanced features like caching and transactions. The document also provides an example of how to define mappings between a Java class and database table and use Hibernate to save an object to the database.
https://www.learntek.org/blog/serialization-in-java/
Learntek is global online training provider on Big Data Analytics, Hadoop, Machine Learning, Deep Learning, IOT, AI, Cloud Technology, DEVOPS, Digital Marketing and other IT and Management courses.
This document describes how to build an organizational structure tree using Java EE and PrimeFaces for display in a cloud computing environment without data warehousing. It provides code for:
1) Creating a database table to store the organizational structure
2) Developing a JEE entity class and EJB to represent and access the data
3) Building a managed bean that constructs the tree model from the EJB data
4) Displaying the tree on a web page using PrimeFaces
The tree can then be used to organize and display reporting and other hierarchical data from different private cloud systems without needing data warehousing. Future publications will cover integrating trees from different private clouds.
The document provides an overview of data access with Hibernate persistent objects and persistence contexts. It discusses object state transitions and the different states an object can have (transient, persistent, detached). It also covers the Hibernate session and how it manages object identity within its scope. The summary discusses implementing equals() and hashCode() for detached objects using a business key to handle object equality outside the session scope.
1) The document proposes modularizing the data model specifications of the ObjectLens in VisualWorks/Smalltalk by storing mapping definitions in domain classes rather than a single monolithic specification.
2) The mappings defined in each class would be used to construct the overall data model specification, reducing maintenance problems when the class hierarchy changes.
3) A code generator is used to migrate existing monolithic specifications to the new modular format, generate mapping methods, and support modeling tools.
This document provides an overview of different data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network connections. It also includes examples and workshops for using each data storage type with key points on shared preferences, internal and external storage paths, SQLiteOpenHelper, CRUD operations, and displaying data in a ListView.
Phantom types allow using the type system to enforce correctness by distinguishing types that are never instantiated at runtime. The summary describes how phantom types can be used to define a Form trait where the type parameter distinguishes validated and unvalidated form data, ensuring validation is performed before accessing validated data. This provides static type safety without runtime overhead from phantom types, which are never instantiated.
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyDATAVERSITY
This document discusses leveraging NoSQL technologies for performance. It provides an overview of a benchmark that compares ORM and NoSQL databases. The benchmark tests different data modeling structures and operations like CRUD. The results show that the NoSQL database MongoDB outperformed ORM databases on tests involving complex object graphs, concurrency, and querying. The document concludes that NoSQL approaches can provide better performance than ORM by avoiding joins and complex serialization mappings.
The document summarizes performance improvements in .NET 7, including JIT on-stack replacement for methods with loops, faster reflection invocation, improved string searching performance, native AOT compilation removing the JIT, faster JSON serialization using caching, and ongoing .NET research at Microsoft. The presentation was given by Mirco Vanini at a .NET conference in 2023.
Mitigating Java Deserialization attacks from within the JVM (improved version)Apostolos Giannakidis
This deck contains a few improvements based on received feedback, such as the addition of links and reworded some points for clarity.
A talk about the existing ways to mitigate Java deserialization attacks from the JVM. The talk was presented at the BSides Luxembourg conference on October 2017.
It describes the use of Instrumentation Agents and Serialization Filtering and their limitations.
It also talks about Runtime Virtualization and Runtime privilege de-escalation.
At the talk there was also a PoC demo that demonstrated how an Instrumentation Agent could be tampered from a file upload vulnerability at the application level.
greenDAO is an ORM (object relational mapping) library that uses code generation to provide a higher level API for SQLite databases on Android. It generates Java classes from an entity model that allows reading and writing objects to the database instead of using raw SQL. This improves productivity by handling common database tasks like queries and transactions. The generated code avoids reflection for better performance compared to annotation-based ORMs. The library focuses on optimization through techniques like custom cursors, entity caching, and bulk operations to achieve high performance suitable for Android.
Spring Data Requery is alternatives of Spring Data JPA
Requery is lightweight ORM for DBMS (MySQL, PostgreSQL, H2, SQLite, Oracle, SQL Server)
Spring Data Requery provide Query By Native Query, Query By Example and Query By Property like Spring Data JPA
Spring Data Requery is better performance than JPA
This document discusses the evolution of Java EE from J2EE and how Java EE 5 makes enterprise application development easier. Some key ways it does this include introducing annotations for declarative programming, simplifying packaging rules, and introducing new APIs and frameworks like EJB 3.0, JPA, JAX-WS 2.0, and JSF 1.2. The document also covers features of Java EE 5 like dependency injection and how annotations are used throughout the platform.
The document discusses the RIBs (Router, Interactor, Builder) architecture pattern used at Uber for Android development. It outlines some of the issues with traditional MVP/MVVM patterns like lack of encapsulation and compile-time safety. RIBs aims to address these by defining strict responsibilities for each component and using a builder to configure dependencies. Each screen is defined as an independent RIB that can be composed together hierarchically. The architecture is meant to be modular, scalable and compile-time safe while removing the need for multiple activities.
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)Igalia
This document summarizes Andy Wingo's talk at JSConf 2012 about his work on the JavaScriptCore engine. It discusses the different tiers of just-in-time compilation in JSC, including the low-level interpreter (LLInt), baseline JIT, and optimizing DFG JIT. It also covers techniques like lazy compilation, inline caching, and value profiling that JSC uses to improve performance. Finally, it mentions parallel garbage collection and how the engine is ported to different platforms.
This document provides an overview of CDI (Contexts and Dependency Injection) and some portable CDI extensions, including Apache DeltaSpike. It discusses key CDI concepts like dependency injection, interceptors, events, and scopes. It introduces Apache OpenWebBeans as a fast and stable CDI container implementation. It then demonstrates how DeltaSpike extends CDI with additional features like transaction management, qualifiers, specialized configuration, and alternatives. The document encourages involvement to help shape the future of Apache DeltaSpike.
The document discusses several design patterns used in the Gnizr architecture, including the Data Access Object (DAO) pattern, Inversion of Control (IoC), Singleton, and Interceptor patterns. It provides examples of how each pattern is implemented in Gnizr, such as how DAO classes abstract access to the database and how the Spring framework enables IoC through dependency injection configured via XML. It also covers how WebWork actions, results, and interceptors are used in Gnizr.
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
This document discusses how to become an expert Android developer using Android Jetpack. It recommends using Android Jetpack, which is a collection of components and libraries that make it easier to build Android apps. It describes some key components of Jetpack like architecture components like ViewModel and LiveData for lifecycle-aware data management. It also discusses other topics like navigation, testing, and architecture patterns that are important for Android development. The document encourages learning through online courses and emphasizes the importance of continuous learning and skills development for IT careers and the digital industry.
The document discusses object-relational mapping and Hibernate. It describes common object-relational mismatches including problems of granularity, subtypes, associations, and data navigation. It then provides an overview of Hibernate and JPA, how to start a Hibernate project, POJOs, Hibernate APIs, configuration, annotations, identifier generators, dynamic SQL generation, immutable entities, property access strategies, generated property values, default property values, entities vs value types, and mapping of collection properties.
This document provides an overview of Hibernate, an object-relational mapping tool. It explains that Hibernate maps database tables to Java classes and vice versa, allowing developers to work with objects rather than SQL. Key benefits include better application architecture through separation of concerns, reduced time spent on standard database operations, and access to advanced features like caching and transactions. The document also provides an example of how to define mappings between a Java class and database table and use Hibernate to save an object to the database.
https://www.learntek.org/blog/serialization-in-java/
Learntek is global online training provider on Big Data Analytics, Hadoop, Machine Learning, Deep Learning, IOT, AI, Cloud Technology, DEVOPS, Digital Marketing and other IT and Management courses.
This document describes how to build an organizational structure tree using Java EE and PrimeFaces for display in a cloud computing environment without data warehousing. It provides code for:
1) Creating a database table to store the organizational structure
2) Developing a JEE entity class and EJB to represent and access the data
3) Building a managed bean that constructs the tree model from the EJB data
4) Displaying the tree on a web page using PrimeFaces
The tree can then be used to organize and display reporting and other hierarchical data from different private cloud systems without needing data warehousing. Future publications will cover integrating trees from different private clouds.
The document provides an overview of data access with Hibernate persistent objects and persistence contexts. It discusses object state transitions and the different states an object can have (transient, persistent, detached). It also covers the Hibernate session and how it manages object identity within its scope. The summary discusses implementing equals() and hashCode() for detached objects using a business key to handle object equality outside the session scope.
1) The document proposes modularizing the data model specifications of the ObjectLens in VisualWorks/Smalltalk by storing mapping definitions in domain classes rather than a single monolithic specification.
2) The mappings defined in each class would be used to construct the overall data model specification, reducing maintenance problems when the class hierarchy changes.
3) A code generator is used to migrate existing monolithic specifications to the new modular format, generate mapping methods, and support modeling tools.
This document provides an overview of different data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network connections. It also includes examples and workshops for using each data storage type with key points on shared preferences, internal and external storage paths, SQLiteOpenHelper, CRUD operations, and displaying data in a ListView.
Phantom types allow using the type system to enforce correctness by distinguishing types that are never instantiated at runtime. The summary describes how phantom types can be used to define a Form trait where the type parameter distinguishes validated and unvalidated form data, ensuring validation is performed before accessing validated data. This provides static type safety without runtime overhead from phantom types, which are never instantiated.
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyDATAVERSITY
This document discusses leveraging NoSQL technologies for performance. It provides an overview of a benchmark that compares ORM and NoSQL databases. The benchmark tests different data modeling structures and operations like CRUD. The results show that the NoSQL database MongoDB outperformed ORM databases on tests involving complex object graphs, concurrency, and querying. The document concludes that NoSQL approaches can provide better performance than ORM by avoiding joins and complex serialization mappings.
The document summarizes performance improvements in .NET 7, including JIT on-stack replacement for methods with loops, faster reflection invocation, improved string searching performance, native AOT compilation removing the JIT, faster JSON serialization using caching, and ongoing .NET research at Microsoft. The presentation was given by Mirco Vanini at a .NET conference in 2023.
Mitigating Java Deserialization attacks from within the JVM (improved version)Apostolos Giannakidis
This deck contains a few improvements based on received feedback, such as the addition of links and reworded some points for clarity.
A talk about the existing ways to mitigate Java deserialization attacks from the JVM. The talk was presented at the BSides Luxembourg conference on October 2017.
It describes the use of Instrumentation Agents and Serialization Filtering and their limitations.
It also talks about Runtime Virtualization and Runtime privilege de-escalation.
At the talk there was also a PoC demo that demonstrated how an Instrumentation Agent could be tampered from a file upload vulnerability at the application level.
greenDAO is an ORM (object relational mapping) library that uses code generation to provide a higher level API for SQLite databases on Android. It generates Java classes from an entity model that allows reading and writing objects to the database instead of using raw SQL. This improves productivity by handling common database tasks like queries and transactions. The generated code avoids reflection for better performance compared to annotation-based ORMs. The library focuses on optimization through techniques like custom cursors, entity caching, and bulk operations to achieve high performance suitable for Android.
Spring Data Requery is alternatives of Spring Data JPA
Requery is lightweight ORM for DBMS (MySQL, PostgreSQL, H2, SQLite, Oracle, SQL Server)
Spring Data Requery provide Query By Native Query, Query By Example and Query By Property like Spring Data JPA
Spring Data Requery is better performance than JPA
This document discusses the evolution of Java EE from J2EE and how Java EE 5 makes enterprise application development easier. Some key ways it does this include introducing annotations for declarative programming, simplifying packaging rules, and introducing new APIs and frameworks like EJB 3.0, JPA, JAX-WS 2.0, and JSF 1.2. The document also covers features of Java EE 5 like dependency injection and how annotations are used throughout the platform.
The document discusses the RIBs (Router, Interactor, Builder) architecture pattern used at Uber for Android development. It outlines some of the issues with traditional MVP/MVVM patterns like lack of encapsulation and compile-time safety. RIBs aims to address these by defining strict responsibilities for each component and using a builder to configure dependencies. Each screen is defined as an independent RIB that can be composed together hierarchically. The architecture is meant to be modular, scalable and compile-time safe while removing the need for multiple activities.
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)Igalia
This document summarizes Andy Wingo's talk at JSConf 2012 about his work on the JavaScriptCore engine. It discusses the different tiers of just-in-time compilation in JSC, including the low-level interpreter (LLInt), baseline JIT, and optimizing DFG JIT. It also covers techniques like lazy compilation, inline caching, and value profiling that JSC uses to improve performance. Finally, it mentions parallel garbage collection and how the engine is ported to different platforms.
This document provides an overview of CDI (Contexts and Dependency Injection) and some portable CDI extensions, including Apache DeltaSpike. It discusses key CDI concepts like dependency injection, interceptors, events, and scopes. It introduces Apache OpenWebBeans as a fast and stable CDI container implementation. It then demonstrates how DeltaSpike extends CDI with additional features like transaction management, qualifiers, specialized configuration, and alternatives. The document encourages involvement to help shape the future of Apache DeltaSpike.
The document discusses several design patterns used in the Gnizr architecture, including the Data Access Object (DAO) pattern, Inversion of Control (IoC), Singleton, and Interceptor patterns. It provides examples of how each pattern is implemented in Gnizr, such as how DAO classes abstract access to the database and how the Spring framework enables IoC through dependency injection configured via XML. It also covers how WebWork actions, results, and interceptors are used in Gnizr.
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
This document discusses how to become an expert Android developer using Android Jetpack. It recommends using Android Jetpack, which is a collection of components and libraries that make it easier to build Android apps. It describes some key components of Jetpack like architecture components like ViewModel and LiveData for lifecycle-aware data management. It also discusses other topics like navigation, testing, and architecture patterns that are important for Android development. The document encourages learning through online courses and emphasizes the importance of continuous learning and skills development for IT careers and the digital industry.
In this session you will learn:
Introduction to Hibernate
Hibernate Architecture
The Persistence Lifecycle
Getting Started with Hibernate
Relationships and Associations
Advanced Mapping Concepts
Hibernate Queries
Hibernate Transactions
Hibernate Extensions
Hibernate Cache
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Introduction
Architecture
The Persistence Lifecycle
Getting Started
Relationships and Associations
Advanced Mapping Concepts
Hibernate Queries
Hibernate Transactions
Hibernate Extensions
Hibernate Cache
For more information, visit this link: https://www.mindsmapped.com/courses/software-development/online-java-training-for-beginners/
See the improved version: https://www.slideshare.net/ApostolosGiannakidis/mitigating-java-deserialization-attacks-from-within-the-jvm-improved-version
A talk about the existing ways to mitigate Java deserialization attacks from the JVM. The talk was presented at the BSides Luxembourg conference on October 2017.
It describes the use of Instrumentation Agents and Serialization Filtering and their limitations.
It also talks about Runtime Virtualization and Runtime privilege de-escalation.
At the talk there was also a PoC demo that demonstrated how an Instrumentation Agent could be tampered from a file upload vulnerability at the application level.
The document discusses Hibernate, an object-relational mapping tool that transforms data between object representation and relational databases. It describes Hibernate's architecture, important definitions like SessionFactory and Session, configuration options including programmatic and XML configuration, mapping declarations, and persistent classes.
Handling an SQLite database in Android implies challenges like a lot of boilerplate code, database operations on the main thread, queries checked at runtime and especially unmaintainable code. At Google I/O 2017, the Android team launched Room, an SQLite object mapper, that provides a set of components and features that will solve all these challenges and will help us, the developers, to have a better experience when using a database in our app.
The presentation will include examples about how to use the main components from Room (@Entity, @Dao, @Database), how to handle the relations between the entities, how to use the (observable) queries and not run database operations on the main thread. Also, we will discover more details about the migration support, compile time query verification and what’s happening behind the scenes.
Data access patterns and technologies are discussed. The Data Access Object (DAO) pattern separates data access from business logic. Spring JDBC and myBatis provide APIs for SQL queries and object mapping. Object-relational mapping (ORM) tools like Hibernate reduce code by mapping objects to relational databases but can reduce performance. JDBC template provides basic data access while frameworks offer additional features.
Similar to Incremental Java Deserialization/Reserialization (20)
2. The Problem
● Data is stored on disk as byte arrays, which
may be quite large.
● These arrays must be deserialized before the
data can be updated and then reserialized.
● There are various techniques for deserialization
and reserialization but they are all quite slow as
all the data is deserialized and then
reserialized.
3. Incremental Deserialization and
Reserialization
JID Benchmark results for deserializing, updating and then
reserializing large collections.
Entries List Insertion Map Update
1,000 .014 ms .027 ms
10.000 .035 ms .056 ms
100,000 .24 ms .48 ms
1,000,000 2.9 ms 6.9 ms
High performance is achieved by deserializing only
the data that is needed and reserializing only the
data that has been updated.
4. Types of Serialization
● Many applications use ● Hard-coded serialization
reflection-based directly converst data
serialization. from/to arrays of bytes.
● Reflection-based ● This is harder to
serialization is the implement, but runs
easiest to use, but also faster.
the slowest. ● But mixing applicaiton
● There are three main logic with serialization
types: native logic detracts from the
serialization, XML-based clarity of the code.
and Jason.
5. JID is Complex
● Every JID object must track the serialized data
that has not been outdated and any data that
has been deserialized, along with notifying its
container when there is a change.
● Serializable data structures are trees of JID
objects that are mostly instances of pre-defined
classes.
● Application classes contain no serialization
logic, but subclass a JID vector of homogenious
JID types.
6. Factories
● Registered factory objects are needed to instantiate
and initialize JID objects.
● Each registered facory object represents a different
JID type and has a unique name.
● All factory objects are instances of subclasses of the
JidFactory class.
● Factory objects used to instantiate application JID
objects are instances of subclasses of AppJidFactory.
● These factory objects provide the type names of the
registered factory objects needed to create the tuple
elements of the application objects.
7. User Class
public class User extends AppJid {
private StringJid getNameJid() throws Exception {
return (StringJid) _iGet(0);}
private IntegerJid getAgeJid() throws Exception {
return (IntegerJid) _iGet(1);}
public String getName() throws Exception {
return getNameJid().getValue();}
public void setName(String name) throws Exception {
getNameJid().setValue(name);}
public int getAge() throws Exception {
return getAgeJid().getValue();}
public void setAge(int age) throws Exception {
getAgeJid().setValue(age);}
}
8. UserFactoryClass
public class UserFactory extends AppJidFactory {
final public static UserFactory fac = new UserFactory();
public UserFactory() {
super("User",
JidFactories.STRING_JID_TYPE,
JidFactories.INTEGER_JID_TYPE);
}
protected User instantiateActor()
throws Exception {
return new User();
}
}
9. User Test Environment
public class Apps {
public static void main(String[] args) throws Exception {
JAFactory factory = new JAFactory();
(new JidFactories()).initialize(factory);
factory.registerActorFactory(UserFactory.fac);
.
.
.
}
}
10. Serializing
RootJid rootJid0 = (RootJid)
factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid0.setValue("User");
User user0 = (User) rootJid0.getValue();
user0.setName("Fred");
user0.setAge(38);
int serializedLength0 = rootJid0.getSerializedLength();
byte[] serializedData0 = new byte[serializedLength0];
rootJid0.save(serializedData0, 0);
11. Deserialization
RootJid rootJid1 = (RootJid)
factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid1.load(serializedData0, 0, serializedLength0);
User user1 = (User) rootJid1.getValue();
if (!"Fred".equals(user1.getName()))
throw new Exception("unexpected result");
if (38 != user1.getAge())
throw new Exception("unexpected result");