Carbonado (Java)

Carbonado (Java)

Infobox_Software

name = Carbonado
developer = Amazon Technologies Inc.
latest_release_version = 1.1.3
latest_release_date = release date|2008|05|29
operating_system = Cross-platform (JVM)
latest preview version = 1.2-BETA1
latest preview date = release date|2008|05|29
platform = Java Virtual Machine
programming_language = Java
genre = Object-Relational mapping
license = Apache License 2.0
website = http://carbonado.sourceforge.net/

Carbonado is an open source relational database mapping framework, written in Java. Rather than following a typical O/R mapping approach, the relational model is preserved, while still being object-oriented. Not being tied to specific features of SQL or JDBC, Carbonado also supports non-SQL database products such as Berkeley DB. In doing so, relational features such as queries and indexes are supported, without the overhead of SQL.

History

Carbonado was originally developed for internal use by Amazon.com, as a revision to an earlier framework. It was released as an Apache licensed open-source project in October 2006. [http://www.allthingsdistributed.com/2006/10/carbonado.html]

Entity definitions

Relational entities are known as "Storables" in Carbonado, and they are defined by an interface or abstract class. Annotations are required to specify features which cannot defined by Java interface alone. Every Storable must have an annotation describing the primary key of the entity.

@PrimaryKey("entityId") public interface MyEntity extends Storable { long getEntityId(); void setEntityId(long id); String getMessage(); void setMessage(String message); }

Carbonado Storables are not pure POJOs, and they must always implement the Storable interface. By doing do, they gain access to various methods built into it. A Storable definition may also contain business logic, following the active record pattern.

The actual implementation of the Storable is generated at runtime by Carbonado itself. The standard object methods of toString, equals and hashCode are also generated. This greatly simplifies the process of defining new entities, since no boilerplate code needs to be written.

The process of loading a Storable by key starts by calling a factory method to create an uninitialized instance:

Repository repo = ... Storage storage = repo.storageFor(MyEntity.class); MyEntity entity = storage.prepare();

Next, the key properties are set and load is called:

entity.setEntityId(id); entity.load();

Repository usage

A "Repository" is a gateway to the underlying database. A few core implementations are available, which include:

*JDBC access
*Berkeley DB
*Berkeley DB Java Edition
*An in memory database

In addition, composite Repositories exist which support simple replication and logging.

All Repositories are created using a builder pattern. Each type of builder supports options specific to the Repository type. When a Repository instance is built, it only adheres to the standard interface. Access to specific features is provided by a "Capability" interface.

BDBRepositoryBuilder builder = new BDBRepositoryBuilder(); builder.setName(name); builder.setEnvironmentHome(envHome); builder.setTransactionWriteNoSync(true); Repository repo = builder.build();

Query execution

Carbonado queries are defined by a simple filter expression and an order-by specification. Compared to SQL, the filter closely resembles a "where" clause. Filters can include joined properties and they may also include sub filters. This simple example queries for entities with a given message:

Storage storage = repo.storageFor(MyEntity.class); Query query = storage.query("message = ?").with(message); List matches = query.fetch().toList();

Transactions

Transactions are created from a Repository instance, and they define a thread-local scope. Multiple persist operations are automatically grouped together, and commit must be called to complete the transaction.

Transaction txn = repo.enterTransaction(); try { MyEntity entity = storage.prepare(); entity.setEntityId(1); entity.setMessage("hello"); entity.insert(); entity = storage.prepare(); entity.setEntityId(2); entity.setMessage("world"); entity.insert(); txn.commit(); } finally { txn.exit(); }

This design approach shows how Carbonado is not like an O/R mapping framework. Such frameworks typically hide the concept of transactions entirely, often by using sessions which track changes. In Carbonado, all actions are direct.

External links

* [http://carbonado.sourceforge.net/ Carbonado Home Page]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Carbonado (disambiguation) — Carbonado may refer to:* Carbonado, a natural polycrystalline diamond * Carbonado, Washington, a town in Washington state * Carbonado (Java), a relational database mapping framework …   Wikipedia

  • Diamond — This article is about the mineral. For the gemstone, see Diamond (gemstone). For other uses, including the shape ◊, see Diamond (disambiguation) …   Wikipedia

  • Berkeley DB — Original author(s) Margo Seltzer and Keith Bostic of Sleepycat Software Developer(s) Sleepycat Software, later Oracle Corporation Stable release 5.2.28 / June 10, 2011; 5 months ago …   Wikipedia

  • Diamante — Para otros usos de este término, véase Diamante (desambiguación). Diamante General Categoría Minerales elementos (no metales) Clase …   Wikipedia Español

  • List of object-relational mapping software — This is a list of well known object relational mapping software. This list is neither up to date nor all inclusive.Java*Carbonado, open source framework, backed by Berkeley DB or JDBC *Cayenne, apache, open source for java *Ebean, open source ORM …   Wikipedia

  • Motor de persistencia — Saltar a navegación, búsqueda En la actualidad existen distintos motores de persistencia. Estos motores facilitan el mapeo objeto relacional de atributos entre una base de datos relacional tradicional y suplen la funcionalidad de una base de… …   Wikipedia Español

  • Anexo:Motores de persistencia — Esta es una lista alfabética de los principales motores de mapeo objeto relacional, indicando si son libres o comerciales. Contenido 1 ColdFusion 2 Common Lisp 3 Java 4 JavaScript …   Wikipedia Español

  • Internet Movie Database — IMDb redirects here. For the in memory database management system, see In memory database. Internet Movie Database (IMDb) IMDb homepage on February 20, 2011 …   Wikipedia

  • Mobipocket — Mobipocket.com Type Public Industry Software Founded 2000 Headquarters Paris Key people Thierry Brethes, Founder; Nathalie Ting, Founder; Martin Görner, CEO …   Wikipedia

  • Berkeley DB — Saltar a navegación, búsqueda Berkeley DB Desarrollador Oracle Corporation (diseñado por Universidad de Berkeley) Sitio web Infor …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”