net.java.ao.RawEntityのJavadoc
ActiveObjectsのnet.java.ao.RawEntityクラスのJavadocの日本語訳です。原文は、https://activeobjects.dev.java.net/api/net/java/ao/RawEntity.htmlです。
以下、日本語訳
net.java.ao Interface RawEntity既知のサブインタフェースの一覧: Entity
public interface RawEntity
すべてのエンティティのスーパーインタフェースです。このインタフェースは主キーを限定しません。独自の主キーフィールドを指定したい場合、Entityではなくこのインタフェースを拡張しまます。このインタフェースはエンティティ階層で最も一般的なインタフェースであり、エンティティの共通のメソッドの多くを定義します。共通のメソッドとは、save()やaddPropertyChangeListener(PropertyChangeListener)などです。
The superinterface for all entities, regardless of primary key. Developers may choose to extend this interface rather than Entity if they need to specify a custom primary key field. As this interface is the most generic superinterface in the entity hierarchy, it defines most of the common entity methods, such as save() and addPropertyChangeListener(PropertyChangeListener).
このインタフェースがパラメータ化されているのは、EntityManager.find(Class, String, Object...)メソッドの型チェックのためです。このインタフェースを継承する場合、ジェネリック型と主キーメソッドの戻り値の型は同じにした方が良いです。困ったことに、これは強制できません。したがって、開発者がこの仕様を正しくと守る必要があります。
This interface is parameterized for the sake of typechecking in the EntityManager.find(Class, String, Object...) method. The generic type specified when inheriting this interface should be the same as the return type of the primary key method. Unfortunately, this is unenforcable, so it is left up to the developers to ensure the spec is followed.
作成者: Daniel Spiewak
メソッドの概要
void addPropertyChangeListener(PropertyChangeListener listener) | プロパティ変更リスナをエンティティに追加します。 |
EntityManager getEntityManager() | このエンティティを管理するEntityManagerのインスタンスを取得します。 |
Class<? extends RawEntity |
エンティティインタフェースの実際のクラスインスタンスを返します。 |
void init() | エンティティインタフェースが作成された時に呼び出されます。 |
void removePropertyChangeListener(PropertyChangeListener listener) | プロパティ変更リスナをエンティティから削除します。 |
void save() | エンティティの変更された(汚れた)フィールドをすべてデータベースに保存します。 |
メソッドの詳細
init
void init()
エンティティインタフェースが作成された時に呼び出されます。このメソッドが定義されているのは、既存のメカニズムと共通のインタフェース提供するためです。エンティティの実装定義がこのメソッドを実装できるように作られています。実装定義が存在しない場合、AOはこのメソッドの呼び出しを無視します。
Called when the entity instance is created. This method is defined here in order to provide a common interface through an existing mechanism. It is designed to be implemented within an entity defined implementation. Any calls to this method will be ignored by AO unless a defined implementation is present.
save
void save()
エンティティの変更された(汚れた)フィールドをすべてデータベースに保存します。ほとんどの場合、実装定義でこのメソッドをオーバーライドしないほうがいいです。しかし、どうしても必要であれば、オーバーライドすることは可能です。
Saves all changed (dirty) fields within the entity to the database. This method should almost never be overridden within a defined implementation. However, it is possible to do so if absolutely necessary.
getEntityManager
EntityManager getEntityManager()
このエンティティを管理するEntityManagerのインスタンスを取得します。実装定義で独自のクエリを実行するには、このメソッドを使ってEntityManagerインスタンスを取得します。
Retrieves the EntityManager instance which manages this entity. This method can be used by defined implementations to get the relevant EntityManager instance in order to run custom queries.
戻り値: このエンティティを管理するEntityManagerのインスタンス。
getEntityType
Class> getEntityType()
エンティティインタフェースの実際のクラスインスタンスを返します。このメソッドが必要なのは、プロクシインスタンスへのObject.getClass()の呼び出しが期待する値を返さないからです。それはさておき、RawEntityが提供するこのメソッドを使うことで、エンティティインタフェースにアクセスできます。例えば、以下のようになります:
Returns the actual Class instance which corresponds to the original entity interface. This is necessary because calling Object.getClass() on a proxy instance doesn't return the value one would expect. As such, RawEntity provides this method to give developers access to the originating entity interface. Example:
public interface Person extends Entity { // ... } // ... Person p = manager.get(Person.class, 2); p.getEntityType(); // Person.classを返す。 p.getClass(); // 返す値は予測できない。おそらく、$Proxy26.classのようなものを返す。
戻り値: エンティティを定義するクラス。
addPropertyChangeListener
void addPropertyChangeListener(PropertyChangeListener listener)
プロパティ変更リスナをエンティティに追加します。このメソッドの目的は、Bean仕様の順守を強調することも一部ありますが、より重要なのは開発者にsetterのリスナを登録できるようにすることです。
Adds a property change listener to the entity. This method is included partly to emphasize compliance with the bean spec (sort of), but more to enable developers to register listeners on the setters. This method is called when the setter is called, not when save() is invoked.
PropertyChangeEventが正しい古い値を持っていないことがあるので注意が必要です。正しい古い値を取得するためには、データベースに対する追加のSELECTが必要になることも多いからです。メモリ内に古い値がない場合、nullが渡されます。
Be aware that the PropertyChangeEvent may or may not have a valid oldValue. This is because retrieving a previous value under many circumstances may result in an extra database SELECT. If no oldValue is available in memory, null will be passed.
ミューテータの呼び出し時にだけ実行する必要のあるコードは、実装定義ではなくプロパティ変更リスナを使って書いた方が良いです。
Any trivial custom code which only needs to run on mutator invocation should use property change listeners, rather than a defined implementation.
引数: listener - 追加する変更リスナ。
removePropertyChangeListener
void removePropertyChangeListener(PropertyChangeListener listener)
プロパティ変更リスナをエンティティから削除します。
Removes a property change listener from the entity.
引数: listener - 削除する変更リスナ。 関連項目: addPropertyChangeListener(PropertyChangeListener)