Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Tuplizer in NHibernate

I came across a post that mentioned Tuplizer in NHibernate, can anybody provide a good definition or reference for Tuplizer?

like image 927
Emad Alashi Avatar asked Dec 24 '08 12:12

Emad Alashi


3 Answers

From ITuplizer's source code:

A tuplizer defines the contract for things which know how to manage a particular representation of a piece of data, given that representation's EntityMode (the entity-mode essentially defining which representation).

If that given piece of data is thought of as a data structure, then a tuplizer is the thing which knows how to:

  • create such a data structure appropriately
  • extract values from and inject values into such a data structure

For example, a given piece of data might be represented as a POCO class. Here, it's representation and entity-mode is POCO. Well a tuplizer for POCO entity-modes would know how to:

  • create the data structure by calling the POCO's constructor
  • extract and inject values through getters/setter, or by direct field access, etc

That same piece of data might also be represented as a DOM structure, using the tuplizer associated with the XML entity-mode, which would generate instances of XmlElement as the data structure and know how to access the values as either nested XmlElements or as XmlAttributes.

In the words of Fabio Maulo:

The tuplizer defines how to transform a Property-Value to its persistent representation, and viceversa a Column-Value to its in-memory representation, and the EntityMode defines which tuplizer is in use.

Some things you can do with custom tuplizers:

  • Remote lazy loading (the article uses Java Hibernate but the general concepts apply to NHibernate as well)
  • Seamlessly mapping/persisting interfaces instead of POCOs
  • Mapping/persisting F# records (from the FunctionalNHibernate project)
like image 105
Mauricio Scheffer Avatar answered Nov 17 '22 10:11

Mauricio Scheffer


Well, it might help to understand what a tuple is, first:

http://en.wikipedia.org/wiki/Tuple

Python is most notable for having first class support for Tuples, though some other languages do as well (F#)

http://diveintopython3.ep.io/native-datatypes.html#tuples

and of course!

https://stackoverflow.com/search?q=tuples

like image 1
Jeff Atwood Avatar answered Nov 17 '22 10:11

Jeff Atwood


org.hibernate.tuple.Tuplizer, and its sub-interfaces, are responsible for managing a particular representation of a piece of data given that representation's org.hibernate.EntityMode. If a given piece of data is thought of as a data structure, then a tuplizer is the thing that knows how to create such a data structure and how to extract values from and inject values into such a data structure. For example, for the POJO entity mode, the corresponding tuplizer knows how create the POJO through its constructor. It also knows how to access the POJO properties using the defined property accessors. There are two high-level types of Tuplizers, represented by the org.hibernate.tuple.entity.EntityTuplizer and org.hibernate.tuple.component.ComponentTuplizer interfaces. EntityTuplizers are responsible for managing the above mentioned contracts in regards to entities, while ComponentTuplizers do the same for components.

like image 1
Rajesh Kumar Avatar answered Nov 17 '22 08:11

Rajesh Kumar