net.java.ao.EntityManagerのJavadoc

ActiveObjectのnet.java.aoEntityManagerクラスのJavadocの日本語訳です。原文は、https://activeobjects.dev.java.net/api/net/java/ao/EntityManager.htmlです。
引き続き他のクラスのJavadocも訳します。

以下、日本語訳

net.java.ao 
Class EntityManager
java.lang.Object
	net.java.ao.EntityManager
直系の既知のサブクラス - Direct Known Subclasses:
	SearchableEntityManager


public class EntityManager
extends Object

ActiveObjects API全体の中で中心に位置する制御クラスです。EntityManagerはすべてのRawEntityオブジェクトを作成する役割を持ち、さらに、エンティティ、変更可能なテーブル名コンバータおよデータベース抽象層の間を取り持つ層でもあります。EntityManagerはAPIを使用するための出発地点です。

The root control class for the entire ActiveObjects API. EntityManager is the source of all RawEntity objects, as well as the dispatch layer between the entities, the pluggable table name converters, and the database abstraction layers. This is the entry point for any use of the API.

EntityManagerは、単一のデータベースに一つのインスタンスを対応させて使うように作られています。そのため、EntityManagerは、シングルトンインスタンスやスタティックなファクトリメソッドを持たずに、普通のコンストラクタを持っています。スタティックなインスタンスの管理は、APIを使う開発者に委ねられています。

EntityManager is designed to be used in an instance fashion with each instance corresponding to a single database. Thus, rather than a singleton instance or a static factory method, EntityManager does have a proper constructor. Any static instance management is left up to the developer using the API.

追記ですが、ActiveObjectではオプションですべてのSQLの問い合わせを実行前にログ出力させることができます。この問い合わせのログ出力のために、Java Logging APIのLoggerインスタンスをnet.java.aoパッケージに向けて使います。EntityManagerのスタティック初期化子により、ログ出力はデフォルトで無効にされます。そのため、SQL文をログ出力したい場合、EnittyManagerクラスを一度使用してから、LoggerレベルをLeveL.FINEに設定する必要があります。つまり、コンストラクタが呼ばれた後で、ログレベルを設定する必要があります。

As a side note, ActiveObjects can optionally log all SQL queries prior to their execution. This query logging is done with the Java Logging API using the Logger instance for the net.java.ao package. This logging is disabled by default by the EntityManager static initializer. Thus, if it is desirable to log the SQL statements, the Logger level must be set to Level.FINE after the EntityManager class is first used. This usually means setting the log level after the constructer has been called.

作成者 - Author:
	Daniel Spiewak


コンストラクタの概要 - Constructor Summary

EntityManager(DatabaseProvider provider) DatabaseProviderを指定して、EntityManagerのインスタンスを作成します。
En tityManager(DatabaseProvider provider, boolean weaklyCache) DatabaseProciderを指定して、EntityManagerのインスタンスを作成します。
EntityManager(String uri, String username, String password) JDBC URIから自動的にDatabaseProviderのインスタンスを見つけて、EntityManagerのインスタンスを作成します。

メソッドの概要 - Method Summary

int count(Class<? extends RawEntity> type) 指定した型のエンティティを数えます。
int count(Class<? extends RawEntity> type, Query query) 指定した型のエンティティのうち、指定したQueryインスタンスにあてはまるものを数えます。
int count(Class<? extends RawEntity> type, String criteria, Object... parameters) 指定した型のエンティティのうち、指定した条件とパラメータにあてはまるものを数えます。
,K> T create(Class type, DBParam... params) 指定した型のエンティティを作成します。
,K> T create(Class type, Map params) 指定された型のエンティティを作成し、INSERTを行います。
void delete(RawEntity<?>... entities) 指定したエンティティをデータベースから削除します。
,K> T[] find(Class type) 指定した型のエンティティをすべて返します。
,K> T[] find(Class type, Query query) 指定したQueryに当てはまるエンティティをすべて選択します。
,K> T[] find(Class type, String criteria, Object... parameters) 指定した型のエンティティのうち、条件に当てはまるものをすべて選択するための便利なメソッドです。
,K> T[] find(Class type, String field, Query query) 指定したQueryにあてはまるエンティティをすべて選択します。
,K> T[] findWithSQL(Class type, String keyField, String sql, Object... parameters) SQLを実行してキーフィールドを取得し、取得した行ごとに指定した型のインスタンスを作成します。
void flush(RawEntity<?>... entities) 指定したエンティティ中のキャッシュされている値と関連のエントリをすべて解放します。
void flushAll() EntityManagerインスタンスがキャッシュしているエンティティ中の値をすべて解放します。
,K> T[] get(Class type, K... keys) 指定した型のエンティティうち可変長引数で指定した主キーを持つものを、配列として返します。
,K> T get(Class type, K key) 単一の主キー指定した場合に指定した型のエンティティを、配列としてではなく、単一のエンティティとして返すようにオーバーロードした便利なメソッドです。
protected ,K> T getAndInstantiate(Class type, K key) 指定した型のエンティティのインスタンスを主キーを指定して作成します。
Cache getCache()
FieldNameConverter getFieldNameConverter() エンティティのメソッドの名前を変換するために使用するFieldNameConverterインスタンスを取得します。
PolymorphicTypeMapper getPolymorphicTypeMapper() ポリモーフィックな型のフラグ値を変換するために使用するPolymorphicTypeMapperインスタンスを取得します。
DatabaseProvider getProvider() すべてのデータベース操作で、このEntityManagerが使用するデータベースプロバイダを取得します。
TableNameConverter getTableNameConverter() エンティティの型の名前を変換するために使用するTableNameConverterを取得します。
void migrate(Class<? extends RawEntity<?>>... entities) エンティティのスキーマを簡単に作成できるメソッドです。
void setCache(Cache cache)
void setFieldNameConverter(FieldNameConverter fieldNameConverter) エンティティのメソッドの名前を変換するために使用するFieldNameConverterインスタンスを取得します。
void setPolymorphicTypeMapper(PolymorphicTypeMapper typeMapper) ポリモーフィックな型のフラグ値を変換するために使用するPolymorphicTypeMapperインスタンスを設定します。
void setTableNameConverter(TableNameConverter tableNameConverter) エンティティのメソッドの名前を変換するために使用するTableNameConverterインスタンスを指定します。

コンストラクタの詳細 - Constructor Detail

EntityManager
public EntityManager(DatabaseProvider provider)

DatabaseProviderを指定して、EntityManagerのインスタンスを作成します。このコンストラクタは、エンティティのキャッシュを初期化し、デフォルトのTableNameConverter(複数化を行わないCamelCaseTableConverter)とFieldNameConverter(CamelFieldNameConverter)作成します。このコンストラクタで設定したプロバイダインスタンスは変更できません。(このコンストラクタを使った場合)デフォルトでは、エンティティは強くキャッシュされます。つまり、エンティティインスタンスへの参照が保持され、エンティティはガーベジコレクションの対象になりません。

Creates a new instance of EntityManager using the specified DatabaseProvider. This constructor intializes the entity cache, as well as creates the default TableNameConverter (the default is CamelCaseTableNameConverter, which is non-pluralized) and the default FieldNameConverter (CamelCaseFieldNameConverter). The provider instance is immutable once set using this constructor. By default (using this constructor), all entities are strongly cached, meaning references are held to the instances, preventing garbage collection.

引数 - Parameters:
	provider - データベース操作に使用するDatabaseProvider - The DatabaseProvider to use in all database operations.
関連項目 - See Also:
	EntityManager(DatabaseProvider, boolean)


EntityManager
public EntityManager(DatabaseProvider provider,
                     boolean weaklyCache)

DatabaseProciderを指定して、EntityManagerのインスタンスを作成します。このコンストラクタは、指定されたboolean値に基づき、エンティティのキャッシュとプロキシのキャッシュを初期化します。trueの場合、エンティティは弱くキャッシュされます。つまり、エンティティインスタンスへの参照が保持されず、エンティティはガーベジコレクションの対象になります。falseの場合、エンティティは強くキャッシュされます。つまり、エンティティインスタンスへの参照が保持され、エンティティはガーベジコレクションの対象にならず、論理的に完全なキャッシュになります。メモリが問題になる場合、trueにしてください。そうでない場合、効率を最大にするためにfalseにしてください(強く推奨)。

Creates a new instance of EntityManager using the specified DatabaseProvider. This constructor initializes the entity and proxy caches based on the given boolean value. If true, the entities will be weakly cached, not maintaining a reference allowing for garbage collection. If false, then strong caching will be used, preventing garbage collection and ensuring the cache is logically complete. If you are concerned about memory, specify true. Otherwise, for maximum performance use false (highly recomended).

引数 - Parameters:
	provider -データベース操作に使用するDatabaseProvider -  The DatabaseProvider to use in all database operations.
	weaklyCache - エンティティキャッシュにWeakreferenceを使用するかどうか。falseの場合、SoftReferenceを使用します。 - Whether or not to use WeakReference in the entity cache. If false, then SoftReference will be used.


EntityManager
public EntityManager(String uri,
                     String username,
                     String password)

JDBC URIから自動的にDatabaseProviderのインスタンスを見つけて、EntityManagerのインスタンスを作成します。(サポート対象の接続プーリングライブラリがクラスパス上にある場合)デフォルトでは、DatabaseProviderのインスタンスはプールされます。

Creates a new instance of EntityManager by auto-magically finding a DatabaseProvider instance for the specified JDBC URI, username and password. The auto-magically determined instance is pooled by default (if a supported connection pooling library is available on the classpath).

DatabaseProviderを自動的に見つける処理は、このメソッド中ではなく、DatabaseProvider.getInstance(String, String, String)の中にあります。したがって、必要であれば、EntityManagerを使わずにDatabaseProviderインスタンスを取得することができます。

The actual auto-magical parsing code isn't contained within this method, but in DatabaseProvider.getInstance(String, String, String). This way, it is possible to use the parsing logic to get a DatabaseProvider instance separate from EntityManager if necessary.

引数 - Parameters:
	uri - データベース接続に使用するJDBC URI - The JDBC URI to use for the database connection.
	username - データベース接続の認証に使用するユーザ名 - The username to use in authenticating the database connection.
	password - データベース接続の認証に使用するパスワード - The password to use in authenticating the database connection.
関連項目 - See Also:
	EntityManager(DatabaseProvider), DatabaseProvider.getInstance(String, String, String)

メソッドの詳細 - Method Detail

migrate
public void migrate(Class>... entities)
             throws SQLException

エンティティのスキーマを簡単に作成できるメソッドです。現在の設定(テーブル/フィールド名コンバータとデータベースプロバイダ)を使ってスキーマを作成します。

Convenience method to create the schema for the specified entities using the current settings (table/field name converter and database provider).

例外 - Throws:
	SQLException
関連項目 - See Also:
	SchemaGenerator.migrate(DatabaseProvider, TableNameConverter, FieldNameConverter, Class...)


flushAll
public void flushAll()

EntityManagerインスタンスがキャッシュしているエンティティ中の値をすべて解放します。このメソッドを呼び出しても、このクラスが管理するインスタンスキャッシュからエンティティが削除されることはありません。代わりに、エンティティ内部のフィールド値が(主キーの値を除いて)単純に削除されます。このメソッドは、AOの管理外の複雑なプロセスによりデータベースの値が変更される場合に使用します。変更された行が正確にわかる場合、代わりにflush(RawEntity...)メソッドを使用すべきです。

Flushes all value caches contained within entities controlled by this EntityManager instance. This does not actually remove the entities from the instance cache maintained within this class. Rather, it simply dumps all of the field values cached within the entities themselves (with the exception of the primary key value). This should be used in the case of a complex process outside AO control which may have changed values in the database. If it is at all possible to determine precisely which rows have been changed, the flush(RawEntity...) method should be used instead.


flush
public void flush(RawEntity... entities)

指定したエンティティ中のキャッシュされている値と関連のエントリをすべて解放します。AO管理外のプロセスによって指定された行の値が変更された場合に呼び出します。このメソッドを呼び出しても、インスタンスキャッシュからエンティティインスタンスが削除されることはありません。代わりに、エンティティ内部のキャッシュされている(主キーを除いた)全ての値が単純に削除されます。

Flushes the value caches of the specified entities along with all of the relevant relations cache entries. This should be called after a process outside of AO control may have modified the values in the specified rows. This does not actually remove the entity instances themselves from the instance cache. Rather, it just flushes all of their internally cached values (with the exception of the primary key).


get
public ,K> T[] get(Class type,
                                          K... keys)

指定した型のエンティティうち可変長引数で指定した主キーを持つものを、配列として返します。すでにメモリ内に対応する(指定した型とキーの)エンティティへの参照がある場合、新たなインスタンスを作成せずにメモリ内の参照を返します。

Returns an array of entities of the specified type corresponding to the varargs primary keys. If an in-memory reference already exists to a corresponding entity (of the specified type and key), it is returned rather than creating a new instance.

オブジェクトに対応するキーがデータベースに存在するかどうかの確認は行いません。このメソッドはJavaのメモリの状態だけしか変更しません。データベースアクセスは行われません。結果として、このメソッドは非常に高速です。裏を返せば、データベースに存在しない行を参照するエンティティを保持していることがあります。

No checks are performed to ensure that the key actually exists in the database for the specified object. Thus, this method is solely a Java memory state modifying method. There is no database access involved. The upshot of this is that the method is very very fast. The flip side of course is that one could conceivably maintain entities which reference non-existant database rows.

引数 - Parameters:
	type - 取得するエンティティの型 - The type of the entities to retrieve.
	keys - 取得するエンティティの主キー。キーの型は、エンティティがRawEntityの継承時に指定しているジェネリックな型パラメータと同じでなければなりません(Entityを継承している場合は、Integerかintです)。そのため、キーの配列はコンパイル時に型チェックされます。 - The primary keys corresponding to the entities to retrieve. All keys must be typed according to the generic type parameter of the entity's RawEntity inheritence (if inheriting from Entity, this is Integer or int). Thus, the keys array is type-checked at compile time.
戻り値 - Returns:
	指定した主キーを持つエンティティの配列 - An array of entities of the given type corresponding with the specified primary keys.


getAndInstantiate
protected ,K> T getAndInstantiate(Class type,
                                                         K key)

指定した型のエンティティのインスタンスを主キーを指定して作成します。キャッシュ中にインスタンスがない場合、get(Class, Object...)はこのメソッドを使用してエンティティを作成します。ActiveObjectsはキャッシュがすでに行われているものと想定しているため、このメソッドで改めてキャッシュを行うことはありません。

Creates a new instance of the entity of the specified type corresponding to the given primary key. This is used by get(Class, Object...) to create the entity if the instance is not found already in the cache. This method should not be repurposed to perform any caching, since ActiveObjects already assumes that the caching has been performed.

引数 - Parameters:
	type - 作成するエンティティの型 - The type of the entity to create.
	key - 要求するエンティティのインスタンスの主キー - The primary key corresponding to the entity instance required.
戻り値 - Returns:
	エンティティのインスタンス - An entity instance of the specified type and primary key.


get
public ,K> T get(Class type,
                                        K key)

単一の主キー指定した場合に指定した型のエンティティを、配列としてではなく、単一のエンティティとして返すようにオーバーロードした便利なメソッドです。このメソッドはオーバーロードしたgetメソッドをただ呼び出すだけの、シンタックスシュガーみたいな関数です。

Cleverly overloaded method to return a single entity of the specified type rather than an array in the case where only one ID is passed. This method meerly delegates the call to the overloaded get method and functions as syntactical sugar.

引数 - Parameters:
	type - 取得するエンティティインスタンスの型 - The type of the entity instance to retrieve.
	key - 取得するエンティティの主キー - The primary key corresponding to the entity to be retrieved.
戻り値 - Returns:
	主キーに対応するエンティティのインスタンス - An entity instance of the given type corresponding to the specified primary key.
関連項目 - See Also:
	get(Class, Object...)


create
public ,K> T create(Class type,
                                           DBParam... params)
                              throws SQLException

指定した型のエンティティを作成します。オプションで初期化パラメータを指定できます。このメソッドはエンティティ型に対応するテーブルに行を挿入して、その行に対応するエンティティインスタンスを返します。

Creates a new entity of the specified type with the optionally specified initial parameters. This method actually inserts a row into the table represented by the entity type and returns the entity instance which corresponds to that row.

デフォルト値がなく、値の自動生成も行わない非nullフィールドを含むエンティティを作成するために、DBParamオブジェクトのパラメータが用意されています。それらのフィールドに値を指定せずに行を挿入すると、当然ながら失敗するので、DBParamが必要になります。DBParamは行のどのフィールドの値でも設定できるので、場合によってはコードをより小さくする目的にも使用できます。

The DBParam object parameters are designed to allow the creation of entities which have non-null fields which have no defalut or auto-generated value. Insertion of a row without such field values would of course fail, thus the need for db params. The db params can also be used to set the values for any field in the row, leading to more compact code under certain circumstances.

トランザクションを使用しない場合、このメソッドは呼び出すたびにすぐにコミットします。そのため、大量のエンティティを作成する場合には注意が必要です。とはいえ、大量のエンティティを作成するための効率的な方法が他にはないので、パフォーマンスへの影響に注意するべきです。

Unless within a transaction, this method will commit to the database immediately and exactly once per call. Thus, care should be taken in the creation of large numbers of entities. There doesn't seem to be a more efficient way to create large numbers of entities, however one should still be aware of the performance implications.

このメソッドは内部的にDatabaseProvider.insertReturningKey(Connection, Class, String, boolean, String, DBParam...)を呼び出してINSERTを行います。JDBC RETURN_GENERATED_KEYS定数がすべてのデータベースではサポートされていないので、このメソッドが必要になります。そのため、INSERTの実行と正しい主キーの取得は、データベースプロバイダの責任になります。

This method delegates the action INSERT action to DatabaseProvider.insertReturningKey(Connection, Class, String, boolean, String, DBParam...). This is necessary because not all databases support the JDBC RETURN_GENERATED_KEYS constant (e.g. PostgreSQL and HSQLDB). Thus, the database provider itself is responsible for handling INSERTion and retrieval of the correct primary key value.

引数 - Parameters:
	type - INSERTするエンティティの型 - The type of the entity to INSERT.
	params - オプションで行のフィールドの初期値を指定できる可変長配列。これらの値はINSERT文によりデータベースに渡される。 - An optional varargs array of initial values for the fields in the row. These values will be passed to the database within the INSERT statement.
戻り値 - Returns:
	INSERTされた行に対応する新たなエンティティのインスタンス - The new entity instance corresponding to the INSERTed row.
例外 - Throws:
	SQLException
関連項目 - See Also:
	DBParam, DatabaseProvider.insertReturningKey(Connection, Class, String, boolean, String, DBParam...)


create
public ,K> T create(Class type,
                                           Map params)
                              throws SQLException

指定された型のエンティティを作成し、INSERTを行います。マップでパラメータを指定します。このメソッドは内部でcreate(Class, DBParam...)メソッドを呼び出しているだけです。パラメータを大量に指定する場合、あるいは、無名内部クラスのコンストラクタの文法に慣れている人にとって、複数のオブジェクトを渡すよりもマップを作る方が楽であるので、マップを指定できるメソッドを用意しています。

Creates and INSERTs a new entity of the specified type with the given map of parameters. This method merely delegates to the create(Class, DBParam...) method. The idea behind having a separate convenience method taking a map is in circumstances with large numbers of parameters or for people familiar with the anonymous inner class constructor syntax who might be more comfortable with creating a map than with passing a number of objects.

引数 - Parameters:
	type - INSERTするエンティティの型 - The type of the entity to INSERT.
	params - INSERT時に渡すパラメータのマップ - A map of parameters to pass to the INSERT.
戻り値 - Returns:
	INSERTされた行に対応するエンティティのインスタンス - The new entity instance corresponding to the INSERTed row.
例外 - Throws:
	SQLException
関連項目 - See Also:
	create(Class, DBParam...)


delete
public void delete(RawEntity... entities)
            throws SQLException

指定したエンティティをデータベースから削除します。テーブルの行に対してDELETE文を呼び出し、インスタンスのキャッシュからエンティティを削除します。エンティティインスタンス自体は無効になりませんが、対応する行をもたないインスタンスを使いつづけることに意味はありません。

Deletes the specified entities from the database. DELETE statements are called on the rows in the corresponding tables and the entities are removed from the instance cache. The entity instances themselves are not invalidated, but it doesn't even make sense to continue using the instance without a row with which it is paired.

このメソッドはDELETE文を型によってグループ分けします。そのため、EntityAのインスタンスを5つとEntityBのインスタンスを二つ渡した場合、以下のSQLのプリペアード文が実行されます:

This method does attempt to group the DELETE statements on a per-type basis. Thus, if you pass 5 instances of EntityA and two instances of EntityB, the following SQL prepared statements will be invoked:

DELETE FROM entityA WHERE id IN (?,?,?,?,?);
DELETE FROM entityB WHERE id IN (?,?);

このメソッドにより多数のエンティティを型によってグループ分けできます。とはいえ、ユニークなエンティティの型が増えると、実行時間は直線的に増加します。

Thus, this method scales very well for large numbers of entities grouped into types. However, the execution time increases linearly for each entity of unique type.

引数 - Parameters:
	entities - 削除するエンティティを指定する可変長の配列。長さが0の場合、メソッドはすぐに終了します。 - A varargs array of entities to delete. Method returns immediately if length == 0.
例外 - Throws:
	SQLException


find
public ,K> T[] find(Class type)
                              throws SQLException

指定した型のエンティティをすべて返します。これは内部でfind(Class, Query)メソッドを呼び出します。

Returns all entities of the given type. This actually peers the call to the find(Class, Query) method.

引数 - Parameters:
	type - 取得するエンティティの型 - The type of entity to retrieve.
戻り値 - Returns:
	すべてのエンティティの配列 - An array of all entities which correspond to the given type.
例外 - Throws:
	SQLException


find
public ,K> T[] find(Class type,
                                           String criteria,
                                           Object... parameters)
                              throws SQLException

指定した型のエンティティのうち、条件に当てはまるものをすべて選択するための便利なメソッドです。条件にパラメータを指定できます。条件は、SQLのプリペアード文のWHEREの後ろに追加されます。

Convenience method to select all entities of the given type with the specified, parameterized criteria. The criteria String specified is appended to the SQL prepared statement immediately following the WHERE.

例 - Example:

manager.find(Person.class, "name LIKE ? OR age > ?", "Joe", 9);

これは、Queryオブジェクトにパラメータを設定して、内部的にfind(Class Query)メソッドを呼び出します。

This actually delegates the call to the find(Class, Query) method, properly parameterizing the Query object.

引数 - Parameters:
	type - 取得するエンティティの型 - The type of the entities to retrieve.
	criteria - パラメータを指定できるWHERE文。問い合わせのために使用します。 - A parameterized WHERE statement used to determine the results.
	parameters - 実行時にプリペアード文に渡すパラメータを入れる可変長の配列。この配列の長さは条件中の(文字'?'で指定した)パラメータの数と同じでなければなりません。- A varargs array of parameters to be passed to the executed prepared statement. The length of this array must match the number of parameters (denoted by the '?' char) in the criteria.
戻り値 - Returns:
	条件にあてはまるエンティティの配列 - An array of entities of the given type which match the specified criteria.
例外 - Throws:
	SQLException


find
public ,K> T[] find(Class type,
                                           Query query)
                              throws SQLException

指定したQueryに当てはまるエンティティをすべて選択します。デフォルトでは、指定した型の主キーフィールドの値からエンティティを作成します(たいていは、これは好ましい動作です)。

Selects all entities matching the given type and Query. By default, the entities will be created based on the values within the primary key field for the specified type (this is usually the desired behavior).

例 - Example:

manager.find(Person.class, Query.select().where("name LIKE ? OR age > ?", "Joe", 9).limit(10));

このメソッドは内部でfind(Class, String, Query)を呼び出し、主キーフィールドをStringパラメータとして渡します。

This method delegates the call to find(Class, String, Query), passing the primary key field for the given type as the String parameter.

引数 - Parameters:
	type - 取得するエンティティの型 - The type of the entities to retrieve.
	query - Queryインスタンス。問い合わせるために使用する。 - The Query instance to be used to determine the results.
戻り値 - Returns:
	問い合わせに当てはまるエンティティの配列 - An array of entities of the given type which match the specified query.
例外 - Throws:
	SQLException


find
public ,K> T[] find(Class type,
                                           String field,
                                           Query query)
                              throws SQLException

指定したQueryにあてはまるエンティティをすべて選択します。このメソッドではQueryインスタンスを使って、指定した型が表すテーブルに問い合わせるPreparedStatementを作成します。そして、(指定したパラメータを使用して)この問い合わせを実行します。このメソッドは結果セットを繰り返し読み取り、指定したフィールドを取得し、指定した型のエンティティをそれぞれの行に割り当てます。このエンティティの配列を返します。

Selects all entities of the specified type which match the given Query. This method creates a PreparedStatement using the Query instance specified against the table represented by the given type. This query is then executed (with the parameters specified in the query). The method then iterates through the result set and extracts the specified field, mapping an entity of the given type to each row. This array of entities is returned.

引数 - Parameters:
	type - 取得するエンティティの型 - The type of the entities to retrieve.
	field - エンティティの作成に使用するフィールド値。通常、これはエンティティに対応するテーブルの主キーです。 - The field value to use in the creation of the entities. This is usually the primary key field of the corresponding table.
	query - Queryインスタンス。問い合わせるために使用する。 - The Query instance to use in determining the results.
戻り値 - Returns:
	問い合わせに当てはまるエンティティの配列 - An array of entities of the given type which match the specified query.
例外 - Throws:
	SQLException


findWithSQL
public ,K> T[] findWithSQL(Class type,
                                                  String keyField,
                                                  String sql,
                                                  Object... parameters)
                                     throws SQLException

SQLを実行してキーフィールドを取得し、取得した行ごとに指定した型のインスタンスを作成します。SQLはパラメータを指定したPreparedStatementとして実行されます。

Executes the specified SQL and extracts the given key field, wrapping each row into a instance of the specified type. The SQL itself is executed as a PreparedStatement with the given parameters.

例 - Example:

manager.findWithSQL(Person.class, "personID", "SELECT personID FROM chairs WHERE position < ? LIMIT ?", 10, 5);

ActiveObjectsSQLは解析や変更を一切行いません。そのため、データベース固有の問い合わせをそれと気づかずに実行してしまうことがありえます。例えば、上記の問い合わせはMS SQL ServerOracleでは、SQLのLIMIT節を実装していないので、実行できません。したがって、このメソッドでのSQLの実行について十分に注意するか、さもなくば、特定のDBMSに縛られることを自覚する必要があります。

The SQL is not parsed or modified in any way by ActiveObjects. As such, it is possible to execute database-specific queries using this method without realizing it. For example, the above query will not run on MS SQL Server or Oracle, due to the lack of a LIMIT clause in their SQL implementation. As such, be extremely careful about what SQL is executed using this method, or else be conscious of the fact that you may be locking yourself to a specific DBMS.

引数 - Parameters:
	type 取得するエンティティの型。 - The type of the entities to retrieve.
	keyField エンティティの条件として使用するフィールドの値 通常、これはエンティティに対応するテーブルの主キーです。 - The field value to use in the creation of the entities. This is usually the primary key field of the corresponding table.
	sql - 実行するSQL文。 - The SQL statement to execute.
	parameters - 実行するプリペアード文のパラメータを入れる可変長の配列。この配列の長さは、条件中の(文字'?'で指定した)パラメータの数と同じでなければなりません。 - A varargs array of parameters to be passed to the executed prepared statement. The length of this array must match the number of parameters (denoted by the '?' char) in the criteria.
戻り値 - Returns:
	問い合わせに当てはまるエンティティの配列。 - An array of entities of the given type which match the specified query.
例外 - Throws:
	SQLException


count
public  int count(Class> type)
          throws SQLException

指定した型のエンティティを数えます。このメソッドの内部では count(Class, Query) を呼び出しています。

Counts all entities of the specified type. This method is actually a delegate for: count(Class, Query)

引数 - Parameters:
	type - 数えるエンティティの型 - The type of the entities which should be counted.
戻り値 - Returns:
	指定した型のエンティティの数 - The number of entities of the specified type.
例外 - Throws:
	SQLException


count
public  int count(Class> type,
                     String criteria,
                     Object... parameters)
          throws SQLException

指定した型のエンティティのうち、指定した条件とパラメータにあてはまるものを数えます。count(type, Query.select().where(criteria, parameters))と同じことを簡単に書けるメソッドです。

Counts all entities of the specified type matching the given criteria and parameters. This is a convenience method for: count(type, Query.select().where(criteria, parameters))

引数 - Parameters:
	type - 数えるエンティティの型。 - The type of the entities which should be counted.
	criteria パラメータかされたWHERE句。このWHERE句で決定された結果セットを数えます。 - A parameterized WHERE statement used to determine the result set which will be counted.
	parameters 実行するプリペアード文のパラメータを入れる可変長の配列。この配列の長さは、条件中の('?'文字で指定した)パラメータの数と同じでなければなりません。 - A varargs array of parameters to be passed to the executed prepared statement. The length of this array must match the number of parameters (denoted by the '?' char) in the criteria.
戻り値 - Returns:
	条件に当てはまるエンティティの数。 - The number of entities of the given type which match the specified criteria.
例外 - Throws:
	SQLException


count
public  int count(Class> type,
                     Query query)
          throws SQLException

指定した型のエンティティのうち、指定したQueryインスタンスにあてはまるものを数えます。パフォーマンスを最高にするために、SELECT COUNT(*)というSQLを実行します。

Counts all entities of the specified type matching the given Query instance. The SQL runs as a SELECT COUNT(*) to ensure maximum performance.

引数 - Parameters:
	type - 数えるエンティティの型 - The type of the entities which should be counted.
	query - Queryインスタンス。このQueryインスタンスで決まる結果セットを数えます。 - The Query instance used to determine the result set which will be counted.
戻り値 - Returns:
	Queryインスタンスに当てはまるエンティティの数 - The number of entities of the given type which match the specified query.
例外 - Throws:
	SQLException


setTableNameConverter
public void setTableNameConverter(TableNameConverter tableNameConverter)

エンティティのメソッドの名前を変換するために使用するTableNameConverterインスタンスを指定します。名前の変換とは、RawEntityを継承するインタフェースに対応するテーブル名を決めるプロセスです。

Specifies the TableNameConverter instance to use for name conversion of all entity types. Name conversion is the process of determining the appropriate table name from an arbitrary interface extending RawEntity.

デフォルトのテーブル名コンバータはCamelCaseTableNameConverterです。

The default table name converter is CamelCaseTableNameConverter.

関連項目 - See Also:
	getTableNameConverter()


getTableNameConverter
public TableNameConverter getTableNameConverter()

エンティティの型の名前を変換するために使用するTableNameConverterを取得します。

Retrieves the TableNameConverter instance used for name conversion of all entity types.

関連項目 - See Also:
	setTableNameConverter(TableNameConverter)


setFieldNameConverter
public void setFieldNameConverter(FieldNameConverter fieldNameConverter)

エンティティのメソッドの名前を変換するために使用するFieldNameConverterインスタンスを取得します。名前の変換とは、RawEntityを継承するインタフェースのメソッドに対応するフィールド名を決めるプロセスです

Specifies the FieldNameConverter instance to use for field name conversion of all entity methods. Name conversion is the process of determining the appropriate field name from an arbitrary method within an interface extending RawEntity.

デフォルトのフィールド名コンバータはCamelCaseFieldNameConverterです。

The default field name converter is CamelCaseFieldNameConverter.

関連項目 - See Also:
	getFieldNameConverter()


getFieldNameConverter
public FieldNameConverter getFieldNameConverter()

エンティティのメソッドの名前を変換するために使用するFieldNameConverterインスタンスを取得します。

Retrieves the FieldNameConverter instance used for name conversion of all entity methods.

関連項目 - See Also:
	setFieldNameConverter(FieldNameConverter)


setPolymorphicTypeMapper
public void setPolymorphicTypeMapper(PolymorphicTypeMapper typeMapper)

ポリモーフィックな型のフラグ値を変換するために使用するPolymorphicTypeMapperインスタンスを設定します。デフォルトの型マッパーは、マッピングを持たない(したがって、全ての値に対して完全修飾名を使う)DefaultPolymorphicTypeMapperインスタンスです。

Specifies the PolymorphicTypeMapper instance to use for all flag value conversion of polymorphic types. The default type mapper is an empty DefaultPolymorphicTypeMapper instance (thus using the fully qualified classname for all values).

関連項目 - See Also:
	getPolymorphicTypeMapper()


getPolymorphicTypeMapper
public PolymorphicTypeMapper getPolymorphicTypeMapper()

ポリモーフィックな型のフラグ値を変換するために使用するPolymorphicTypeMapperインスタンスを取得します。

Retrieves the PolymorphicTypeMapper instance used for flag value conversion of polymorphic types.

関連項目 - See Also:
	setPolymorphicTypeMapper(PolymorphicTypeMapper)


setCache
public void setCache(Cache cache)


getCache
public Cache getCache()


getProvider
public DatabaseProvider getProvider()

すべてのデータベース操作で、このEntityManagerが使用するデータベースプロバイダを取得します。このメソッドにより確実にデータベースプロバイダを取得できます。さらに、Connectionインスタンスの取得もできるので、ActiveObjectsの外部でJDBC操作を行うことができます。これは以下のように行います:

Retrieves the database provider used by this EntityManager for all database operations. This method can be used reliably to obtain a database provider and hence a Connection instance which can be used for JDBC operations outside of ActiveObjects. Thus:

Connection conn = manager.getProvider().getConnection();
 try {
     // ...
 } finally {
     conn.close();
 }