Skip to main content

Carbonado (Java)









Carbonado (Java)


From Wikipedia, the free encyclopedia

Jump to navigation
Jump to search













































Carbonado
Developer(s) Amazon.com
Stable release
1.2.3
/ March 4, 2012 (2012-03-04)

Repository
  • github.com/carbonado/carbonado
Edit this at Wikidata
Written in Java
Operating system
Cross-platform (JVM)
Platform Java Virtual Machine
Type Object-Relational mapping
License
Apache License 2.0
Website github.com/Carbonado/Carbonado

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.




Contents






  • 1 History


  • 2 Entity definitions


  • 3 Repository usage


  • 4 Query execution


  • 5 Transactions


  • 6 Notes


  • 7 External links





History[edit]


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.[1]



Entity definitions[edit]


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 be 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 extend the Storable superclass. By doing so,
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<MyEntity> 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[edit]


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[edit]


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<MyEntity> storage = repo.storageFor(MyEntity.class);
Query<MyEntity> query = storage.query("message = ?").with(message);
List<MyEntity> matches = query.fetch().toList();


Transactions[edit]


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.



Notes[edit]




  1. ^ Vogels, Werner (26 October 2006). "Carbonado". All Things Distributed. Retrieved 25 December 2010..mw-parser-output cite.citation{font-style:inherit}.mw-parser-output .citation q{quotes:"""""""'""'"}.mw-parser-output .citation .cs1-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration{color:#555}.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration span{border-bottom:1px dotted;cursor:help}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/12px-Wikisource-logo.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output code.cs1-code{color:inherit;background:inherit;border:inherit;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;font-size:100%}.mw-parser-output .cs1-visible-error{font-size:100%}.mw-parser-output .cs1-maint{display:none;color:#33aa33;margin-left:0.3em}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-right{padding-right:0.2em}



External links[edit]


  • Carbonado Home Page












Retrieved from "https://en.wikipedia.org/w/index.php?title=Carbonado_(Java)&oldid=869591072"





Navigation menu

























(window.RLQ=window.RLQ||).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.248","walltime":"0.353","ppvisitednodes":{"value":809,"limit":1000000},"ppgeneratednodes":{"value":0,"limit":1500000},"postexpandincludesize":{"value":51571,"limit":2097152},"templateargumentsize":{"value":1350,"limit":2097152},"expansiondepth":{"value":25,"limit":40},"expensivefunctioncount":{"value":2,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":9569,"limit":5000000},"entityaccesscount":{"value":1,"limit":400},"timingprofile":["100.00% 283.901 1 -total"," 57.93% 164.459 2 Template:Infobox"," 51.87% 147.257 1 Template:Infobox_software"," 24.62% 69.886 1 Template:Cite_web"," 14.32% 40.660 1 Template:About"," 12.94% 36.746 1 Template:Infobox_software/simple"," 10.54% 29.914 2 Template:Wikidata"," 6.93% 19.682 1 Template:Amazon"," 6.78% 19.251 3 Template:Navbox"," 6.17% 17.520 1 Template:Plainlist"]},"scribunto":{"limitreport-timeusage":{"value":"0.116","limit":"10.000"},"limitreport-memusage":{"value":2944259,"limit":52428800}},"cachereport":{"origin":"mw1256","timestamp":"20190122165204","ttl":1900800,"transientcontent":false}}});mw.config.set({"wgBackendResponseTime":103,"wgHostname":"mw1245"});});

Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values