6 - Object PErsistence, Relationships, and Queries Flashcards

1
Q

What are the main goals and challenges of Object Persistence?

A

Objects whose lifetime exceeds the execution of a an individual program

Goals:

  • Abstract application from data sources (MIDW goal of abstraction)
    • Data model, query mechanism, API, schema
    • DB seen as infrastructure provided by MDW

Challenges

  • Impedance mismatch (e.g. relational)
    • Structure, relationships, behavior, access paradigm (navigational vs. declarative)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is the standard JDBC model sufficient for Object Persistence with a ORDBMS? What is missing?

A

Provides mapping between Java objects and DB Schema, automatically used in get/set object().

Problems:

  • No transparency of DB: still requires schema knowledge, DB access, and SQL queries
  • References not handled property

Ideal requirements:

  • application code only interacts with objects (create, destroy, modify, invoke methods)
    • corresponding DB actions performed implicitly by infrastructure (INSERT, SELECT, UPDATE, …)
  • mapping from objects to DB performed in deployment phase, classes, IDs, references, relationships
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the inherent performance problems of objects-persistence?

A

Not only mapping overhead, but also deficiencies in the programming model: navigational access, no direct support for JOIN
- many configuration and tuning tweaks required

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an overview of the aspects of Object persistence and the challenges to realise them:

A

Orthogonal persistence: provide persistence to all data, independent of type (but programmer chooses which objects to persist).

Transitive persistence (by reachability): whole tree of referenced objects is automatically persisted with the root.

Persistence independence (transparent): code that handles persisted and transient object is almost the same:

  • Client-side: no impact on interaction with objects (additional actions to persist may occur)
    • automatic/ implicit interactions with data stores performed by infrastructure
  • Server-side: no special code to implement persistence

Challenges: realizing all aspects requires sophisticated and complex tools
- some aspects may be partially unwanted or inflexible (performance, transitive persistence undesired…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give an overview of Design Points in a persistence programming model

A

In application server: where to separate persistent objects from transient? at distribution level (EJB old) or in prog. lanaguage

Determination of persistence: statically (by type/class -> EJB), semi-dynamic (qualifying objs can be persisted at runtime, dynamically (orthogonal persistence)

Identification of objects: implicit OID vs explicit key (primary key)

Access to object state: member variable or getter/setters

Modification of persisted state: explicit (load/store methods) or automatic (immediate, deferred) or combination

Dependencies/relationships: ref. integrity, lazy vs eager loading, pointer swizzling (map painter structure correctly)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give an overview of Persistence in CORBA

A

Persistent object, associated with a PID (diff from object ID): allows multiple PIDs for same obj.

  • Representation of objects persistent state
  • Describes data location

Persistent object manager: interface for persistence operations, interpretation of PIDs (location)

CORBA object does its own persistence (may use PDS = Persistent Data Service (implicit vs explicit))

PO interface (for explicit): store/delete, connect/disconnect (keep state current / active)

Protocols for persistence services: direct access, ODMG’93, DDO (employed in implementation of PO)

  • Too much flexibility and inherent complex (confusing…)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Give an overview of persistence in EJB

A

All and only entity beans are persistent: tight to the concept of entity

On client-side: transparent persistence - persistence operations are hidden from client (automatic)

Persistence logic separated from business logic (even if automatically generated). Callback methods from home interface)

Container-managed persistence (CMP)

  • Persistence-related code is generated automatically
  • Fields manipulated through setters (can be propagated to clients in remote interface). More flexibility = lazy loading of attributes, individual att. updates.
  • Server-side:
    1: defines abstract persistent schema (which fields must be persisted) WHAT
    2: mapping to specific DB in deployment phase: HOW (tool support: bottom-up, top-down)
  • Object state handled by container: callbacks only used to implement additional persistence logic (derived, compression, … )

Bean-managed persistence (BMP)

  • Explicit DB-access operations are defined in callback methods (complex mappings, legacy integration). Also explicit finder methods
  • No support for container-managed relationships/EJB-QL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the main problems with EJB and CORBA persistence models?

A

Persistence id defined at the level of distributed components: granularity too coarse: too much overhead for local objects.

No support for inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the goals and key ideas of JDO persistence?

A

Standard for Java-based persistence (universal for common Java object)

Orthogonal, transitive persistence of native Java objects (+ inheritance)

Abstract schema and mapping with XML

Semi-dynamic persistence (designed classes may have instance persisted)

Complete transparence fro client-side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an overview of the JDO API

A

Main component: persistence manager (PM): manages all aspects related to persistence and lifecycle of objects, as well as querying and transaction support (created by PersistenceManagerFactory)

Extent: represent all instances of a class (automatic “colletion” that give access to all pers. instances)

Query and transaction interfaces retrieved via PM

Programming Model: take normal object, pass it to PM.makePersistent(obj). Retrieve using object id or query
* after deletion, object stays in memory (just becomes transient)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does the Byte-Code-Enhancement mechanism of JDO work?

A

Inject persistence-related infrastructure code into class behavior (compiled code)

Instead of generating code with getter/setters and callbacks (EJB)

Update byte-code in class file according to JDO metadata that specifies the mapping (JDO enhancer: under the hood)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the goals of the Java Persistence API and how does it modify the EJB model?

A

EJB “reaction” to JDO: simplified prog. model, standardized or mapping, inheritance/polymorphism, enhanced query

Scope not restricted to EJB container / app. server, support for third-party persistence engines

Entity-concept (!= entity beans): plain java objects only locally accessible
- Mark objects as entities with annotation/depl. descriptor (no home/local interface, nor further impl. of generated methods)
- Object state is encapsulated: access only through methods
Full flexibility for inheritance aspect and abstract classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the restriction imposed to object in JPA in order to be persisted?

A

Entities must have (possibly compound) primary key, defined at object root, one per class hierarchy: may not be modified.

Public empty constructor, no final stuff, top-level class

Access to entity state: protected variables or getter/setter (choose one and be consistent)

Only generic collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain the JPA concept of Embeddable class

A

Represent additional nested state information (eg. Address of a person)

Only visible in context of “container” class

Persistence aspects are handled by container (State of embeddable is saved together with container)

Restrictions : only one level, not in collections, in principle no inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How is the DB-mapping performed in JPA?

A

Default mapping: class name + attributes -> table name + columns

  • can be customized in annotations or depl. descriptor
  • can be mapped to more than one table for complex structures

Mapping strategies

  • single table with discriminator column: one table for all classes in a hierarchy + type indicator column
  • horizontal partitioning: one table per class, columns for all inherited attributes -> only objects of actual type stored.
  • vertical partitioning: one table per class, columns just for newly created attributes are stored (i.e., only specific attributes). Objects of subtypes also stored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give an overview of the object lifecycle in JPA

A

Orthogonal: entity instance may be transient or persistent, decision at runtime (~ PersistenceManager in JDO)

States: new MyObject

  • New: freshly created from Java: persist (INSERT on DB)
  • Managed: entity manager controls object and holds its persistent ID
    • refresh() stays in managed: refresh state (synchronized) SELECT
    • remove DELETE
  • Removed: flagged for removal, made visible after EOT (still lives in memory)
    • perist (), go back to managed
  • Detached: detach from persistence context and continue work without DB connection (but still in transaction)
    • User becomes responsible for consistency between memory/obj and DB row
    • Merge(), go back to managed (UPDATE): changes made on cached copy are written back
17
Q

What are the main goals and the alternatives of Relationship Support in Pers. Model?

A

Complement persistent objects with relationships/references for objects networks
- relations between DB tuples prepresented also in object level

Value-based: relational approach: requires join to follow reference (or additional query)

Support references in object level: getter/setter (EJB)

Separated relationship concept: independent of object interface (CORBA)

18
Q

Give an overview of the relationship support in the major persistence models

A

CORBA: relationship service: manages object dependices separate from interface and state. Rels. are separate objects: powerful, flexible, dynamic, but too complex, coarse-grained: good for integration.

EJB: part of abstract schema (CMP): getters/setters generated, relationship mange by container: no support for transitive persistence (rel. only between entity beans, which are already persistence)

JDO: transitive persistence: all objects rachable by reference are automatically persisted

JPA: relations = persistent obj. attributes

  • support for bi-directional, but not mainteined automatically (owner side “wins” relationship)
  • selective transitive persistence: CASCADE capabilities
19
Q

What are the implication of deleting an object in transitive persistence models?

A

Drawback of transitive approach: implicit definition of persistence

Reverse semantics for deletion: cascade semantics, garbage collection: but later reference using primary key will fail

Cascading delete rules: developer adjust semantics for individual objects: couples to referential integrity constraints at DB level.

20
Q

What are the goals of query support in Persistent Objects?

A

Navigation is useful and meaningful for OO, but very poor performance and restrictive to retrieve collections

Support for an object query language (abstracted from data source query language - SQL). Requires a mapping to a data store queries

21
Q

Give an overview of Query Support in different persistent frameworks

A

CORBA: query service, set oriented, supports SQL and own OQL

  • can be delegated to query evaluator (e.g. DMBS)
  • based only on remote interface, no conceptual mapping from query language concepts (Data model)

EJB: for CMP entity beans, sQL-alike, uses abstract pers. schema, used in impl. of finder methods.
- SELECT DISTINCT OBJECT (o), IN (o.attr) and dot syntax to follow references

JPA: extension of EJB-QL to entities: dynamic queries, class hierarchies, join, projection, etc.

  • but restricted to one persistence unit (single data store mapping) no crossing units
  • referencing support: fetches referenced objects under the cover for later access (e.g. in a join)

JDO: filters on collection iterators (stays close to java model): no SQL/set-based/declarative approach

  • Iterate over specific class and extends, adding filters as bod. expression (in a string)
  • Read-only, just return objects (no join, project) dynamic querying, casts, dot navigation, sort order
  • Variable declarations to hold references to be reused in query
22
Q

What are the main aspects to be considered when realizing automatic persistence?

A

Loading strategy:

  • lazy: easy to implement, increased communication
  • eager: complex queries required, unnecessary objects are retrieved
  • combination: relationships designated as lazy or eager, may be generalized to large attributes

Write strategy (update propagation)

  • Immediate: write every modification right after (Easy to implement, but too many DB interactions)
  • Deffered: record updates and apply them all at end of transaction (more complex, consistency problems: updates not made visible instantly)

Concurrency: control strategy

  • Pessimistic: use locking at DB level (DB takes care of everything)
  • Optimistic: maintain copies for concurrent apps, checks for conflicts at the end (allow potential conflicting changes)
    • Usually not handled by DB, but by persis. framework
    • JPA example: DB guarantees not provided, solve with version attribute in object. Detect and prevent lost updates, but no inconsistent reads
23
Q

Give an overview of transaction support in Persistence Frameworks

A

JDO: transaction at object level

  • either delegated to data store (DB) or set to be optimistic (synchronized with DB only when commit)
  • Orthogonal transactions: to any persistent/transient objects

Access to persisted objects is always in the scope of a transactions

  • upon rollback: persistent state is normally rolled back, but state in memory may not
  • detached state: are offline modifications always refreshed? NO -> manually. Potential lost updates…