For faster navigation, this Iframe is preloading the Wikiwand page for Carbonado (Java).

Carbonado (Java)

Carbonado
開発元 Amazon.com
最新版
1.3.1 / 2015年3月7日 (9年前) (2015-03-07)
リポジトリ ウィキデータを編集
プログラミング
言語
Java
対応OS Cross-platform (JVM)
プラットフォーム Java Virtual Machine
種別 Object-Relational mapping
ライセンス Apache License 2.0
公式サイト github.com/Carbonado/Carbonado
テンプレートを表示

Carbonado はJavaで書かれたオープンソースの関連データベースマッピングフレームワーク。 典型的なオブジェクト関係マッピング手法に従うのではなく、依然としてオブジェクト指向である一方で、関係モデルは保存される。SQLやJDBCの特定の機能に縛られていないCarbonadoは、Berkeley DBなどの非SQLデータベース製品もサポートしている。これにより、SQLのオーバーヘッドなしで、クエリやインデックスなどの関連機能がサポートされる。

歴史

[編集]

Carbonadoは元々Amazon.comが以前のフレームワークの改定として内部使用目的で開発したものである。Apacheのライセンスを受けたオープンソースプロジェクトとしてリリースされた[1]

エンティティ定義

[編集]

関連エンティティはCarbonadoでは「Storables」として知られており、インターフェイスまたは抽象クラスによって定義される。 アノテーションは、Javaインタフェースだけでは定義できない機能を指定する必要がある。 全てのStorableには、エンティティの主キーを説明するアノテーションが必要である。

 @PrimaryKey("entityId")
 public interface MyEntity extends Storable {
     long getEntityId();
     void setEntityId(long id);

     String getMessage();
     void setMessage(String message);
 }

Carbonado Storablesは純粋なPOJOではなく、常にStorableスーパークラスを拡張する必要がある。 そうすることによって、彼らはそれに組み込まれている様々な方法にアクセスすることができる。 格納可能な定義には、アクティブなレコードパターンに従ってビジネスロジックを含めることもできる。

Storableの実際の実装は、実行時にCarbonado自身によって生成される。 toString、equals、およびhashCodeの標準オブジェクトメソッドも生成される。 これにより、定型コードを記述する必要がないため、新しいエンティティを定義するプロセスが大幅に簡素化される。 Storable byキーをロードするプロセスは、ファクトリメソッドを呼び出して初期化されていないインスタンスを作成することから始まる。

キーによってStorable をロードするプロセスは、ファクトリメソッドを呼び出して初期化されていないインスタンスを作成することから始まる。

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

次に、キーのプロパティが設定され、loadが呼び出される。

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

リポジトリ使用

[編集]

リポジトリは、基になるデータベースへのゲートウェイである。 いくつかのコア実装が利用可能。

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

さらに、単純なレプリケーションとロギングをサポートする複合リポジトリも存在する。

すべてのリポジトリは、ビルダー・パターンを使用して作成される。 ビルダーの各タイプは、リポジトリ・タイプに固有のオプションをサポートする。 リポジトリインスタンスが構築されると、標準インタフェースのみに準拠する。 特定の機能へのアクセスは、Capabilityインターフェイスによって提供される。

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

クエリ実行

[編集]

Carbonadoクエリは、単純なフィルタ式と順序付け仕様によって定義される。 SQLと比較すると、フィルタはwhere句によく似ている。 フィルタには結合プロパティを含めることができ、サブフィルタを含めることも可能。 以下の単純なクエリ例では特定のメッセージを持つエンティティを照会する。

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

トランザクション

[編集]

トランザクションはリポジトリインスタンスから作成され、スレッド局所記憶スコープを定義する。 複数の永続操作が自動的にグループ化され、コミットを呼び出してトランザクションを完了する必要がある。

 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();
 }

この設計アプローチは、Carbonadoが関連データベースマッピングフレームワークと似ていないことを示している。 このようなフレームワークは通常、多くの場合変更を追跡するセッションを使用することによってトランザクションの概念を完全に隠すが、Carbonadoでは、全てのアクションは直接的である。

参考文献

[編集]
  1. ^ Carbonado”. All Things Distributed (2006年10月26日). 2010年12月25日閲覧。

外部リンク

[編集]
{{bottomLinkPreText}} {{bottomLinkText}}
Carbonado (Java)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?