作成者/最終変更者
アプリケーションでは、あるエンティティを作成したユーザーと、そのエンティティを最後に変更したユーザーの ID をエンティティにマークするのが一般的なシナリオです。
Ebean では、実装可能なインターフェイス `io.ebean.config.CurrentUserProvider` を介してこれを行う便利な方法を提供しています。
このインターフェイスは、`Object currentUser();` という単一のメソッドのみを指定します。このメソッドは、標準のエンティティ識別子(`Long、String、UUID`)を返します。
Ebean は、新しいインスタンスを作成することで `CurrentUserProvider` をインスタンス化することに注意してください。
実装例
この実装は機能しません。単にアイデアを提供するだけです。
/**
* Returns the current user typically from a Thread local or similar context.
*/
public class MyCurrentUserProvider implements CurrentUserProvider {
@Override
public Object currentUser() {
// Here you get the user id, from some kind of static
// context access (session information, thread local, etc..)
return someContext.getId();
}
}
有効化
`application.properties` ファイルで、インターフェイスを実装するクラスを Ebean に伝えるために、次のプロパティを設定する必要があります: `ebean.currentUserProvider=org.app.MyCurrentUserProvider`