📄 resourcereferencebean.java
字号:
/* * UserEJB - CyberDemia's User management library implemented using EJBs. * Copyright (C) 2004 CyberDemia Research and Services * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * See the COPYING file located in the top-level-directory of * the archive of this library for complete text of license. */package com.cyberdemia.user;import javax.ejb.*;import com.cyberdemia.ejb.BaseEntityBean;/** * * ResourceReferenceBean is a reference to a User resource. A User may * be associated with any number of arbitrary resources * (particularly those from other modules unrelated to User Management) * using this resource reference mechanism. * A resource is categorized by a category key that gives it a certain * meaning to the User. For example, category keys may be * "child", "petName", "schoolTopic", etc. * Each category key may be associated with one or more resources. * Each resource must be identifiable by a unique resource Id, such as * the primary key to its record in a database (saved as a String). * It is up to the client code to figure out how to access the referenced resource. * From a database perpective, such a resource reference may be treated as * a custom many-to-many join table. * * @ejb.bean name="ResourceReferenceBean" * type="CMP" * view-type="local" * schema="ResourceReference" * cmp-version="2.x" * primkey-field="id" * local-jndi-name="ejb/LocalResourceReference" * * @ejb.util generate="physical" * @ejb.interface local-class="com.cyberdemia.user.LocalResourceReference" local-extends="javax.ejb.EJBLocalObject" * @ejb.home local-class="com.cyberdemia.user.LocalResourceReferenceHome" local-extends="javax.ejb.EJBLocalHome" * @ejb.finder signature="java.util.Collection findByUser(java.lang.Integer userId)" * query="select distinct Object(r) from ResourceReference r where r.user.id=?1" * @ejb.finder signature="java.util.Collection findByCategoryAndUser(java.lang.String catKey, java.lang.Integer userId)" * query="select distinct Object(r) from ResourceReference r where r.categoryKey=?1 and r.user.id=?2" * @ejb.finder signature="java.util.Collection findByAttributes(java.lang.String catKey, java.lang.String resId, java.lang.Integer userId)" * query="select distinct Object(r) from ResourceReference r where r.categoryKey=?1 and r.resourceId=?2 and r.user.id=?3" * * @ejb.pk class="java.lang.Integer" * @ejb.persistence table-name="ResourceReference" * @jboss.unknown-pk class="java.lang.Integer" auto-increment="true" jdbc-type="INTEGER" sql-type="INTEGER" * @jboss.entity-command name="mysql-get-generated-keys" * @jboss.method-attributes pattern="get*" read-only="true" * @jboss.container-configuration name="CyberDemia Optimized Standalone CMP" * * @author Alexander Yap * @version $Revision: 1.7 $ at $Date: 2004/06/20 10:18:12 $ by $Author: alexycyap $ */public abstract class ResourceReferenceBean extends BaseEntityBean{ /** * Gets the unique Id for this entity. * * @ejb.persistence * @ejb.pk-field * @ejb.interface-method * @jboss.persistence auto-increment="true" * * @return Unique Id */ public abstract Integer getId(); /** * Sets the unique Id for this entity. * @param id Unique Id */ public abstract void setId(Integer id); /** * Gets the category key. * The category key is used to logically group resources associated with a user. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" dbindex="true" * * @return The resource category key. */ public abstract String getCategoryKey(); /** * Sets the category key. * The category key is used to logically group resources associated with a user. * @param key Resource category key. */ public abstract void setCategoryKey(String key); /** * Gets the unique Id of the referenced resource. * * @ejb.interface-method * @ejb.persistence * * @return The resource unique Id. */ public abstract String getResourceId(); /** * Sets the unique Id of the referenced resource. * * @ejb.interface-method * * @param id The resource unique Id. */ public abstract void setResourceId(String id); /** * Gets the user of the referenced resource. * * @ejb.interface-method * @ejb.relation name="user-resourceReferences" role-name="resourceReference-belongs-to-user" target-ejb="UserBean" target-role-name="user-has-resourceReferences" target-multiple="yes" cascade-delete="yes" * @jboss.relation fk-constraint="yes" related-pk-field="id" fk-column="userId" * * @return The user. */ public abstract LocalUser getUser(); /** * Sets the user Id of the referenced resource. * * @param user The user. */ public abstract void setUser(LocalUser user); //----------------------------- // Create methods. //----------------------------- /** * Creates a ResourceReference. * * @ejb.create-method view-type="local" */ public Integer ejbCreate( String catKey, String resId) throws CreateException { // Note : Unique ID is assigned by database auto-increment setCategoryKey(catKey); setResourceId( resId); return null; } public void ejbPostCreate( String catKey, String resId) { // Nothing here } /** * Gets the auto-generated primary key (field "id"). * Useful to retrieve the primary key immediately after * creating the bean, when <code>getId()</code> would return null. * This method will convert the primary key to an Integer, * which is the type of the "id" field. * * @ejb.interface-method * * @return Primary key */ public Integer getGeneratedPrimaryKey() { Object pk = getEntityContext().getPrimaryKey(); if (pk instanceof Integer) { return (Integer)pk; } if (pk instanceof Number) { return new Integer(((Number)pk).intValue()); } return new Integer( pk.toString() ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -