📄 attachmentbean.java
字号:
/* * SchoolEJB - CyberDemia's library of EJBs for educational related services. * Copyright (C) 2003 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.school;import javax.ejb.*;import com.cyberdemia.ejb.BaseEntityBean;/** * <p> * AttachmentBean stores the data and meta-data for attachments to questions/answer choices/etc, * such as GIF/PNG images. The object that it is attached to is referred to as the "owner", * and its ID is stored as the ownerId field. The owner type is stored as the ownerType field. * </p> * <p> * Container-managed-relationship is not used to associate AttachmentBean to its owner * because it may be very expensive and wasteful to always retrieve attachment content * whenever the owner is accessed. Therefore, this relationship is managed by application code. * Attachment data is only accessed when required. * </p> * * @ejb.bean name="AttachmentBean" * type="CMP" * view-type="local" * schema="Attachment" * cmp-version="2.x" * primkey-field="id" * local-jndi-name="ejb/LocalAttachment" * * @ejb.util generate="physical" * @ejb.interface local-class="com.cyberdemia.school.LocalAttachment" local-extends="javax.ejb.EJBLocalObject" * @ejb.home local-class="com.cyberdemia.school.LocalAttachmentHome" local-extends="javax.ejb.EJBLocalHome" * @ejb.pk class="java.lang.Integer" * @ejb.persistence table-name="CDAttachment" * * @ejb.finder signature="java.util.Collection findByOwner(java.lang.Integer ownerId, java.lang.Integer ownerType)" * query="SELECT DISTINCT OBJECT(a) FROM Attachment a WHERE a.ownerId=?1 AND a.ownerType=?2" * @jboss.query signature="java.util.Collection findByOwner(java.lang.Integer ownerId, java.lang.Integer ownerType)" * query="SELECT DISTINCT OBJECT(a) FROM Attachment a WHERE a.ownerId=?1 AND a.ownerType=?2 ORDER BY a.orderingIndex" * * @jboss.method-attributes pattern="get*" read-only="true" * * @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.container-configuration name="CyberDemia Optimized Standalone CMP" * * @author Alexander Yap * @version $Revision: 1.1 $ at $Date: 2004/06/20 14:56:19 $ by $Author: alexycyap $ */public abstract class AttachmentBean extends BaseEntityBean{ /** * Value of ownerType field to denote that the owner is a Question. */ public static final Integer QUESTION_OWNER_TYPE = new Integer(0); /** * Value of ownerType field to denote that the owner is an AnswerChoice. */ public static final Integer ANSWER_CHOICE_OWNER_TYPE = new Integer(1); /** * Gets the ID (primary key) of this answer choice. * * @ejb.persistence * @ejb.pk-field * @ejb.interface-method * @jboss.persistence auto-increment="true" * * @return ID of this answer choice. */ public abstract Integer getId(); /** * Sets the ID (primary key) of this answer choice. * @param id ID of this answer choice. */ public abstract void setId(Integer id); /** * Gets the attachment content. * * @ejb.interface-method * @ejb.persistence * @jboss.jdbc-type type="BLOB" * @jboss.sql-type type="MEDIUMBLOB" * * @return Attachment content */ public abstract byte[] getContent(); public abstract void setContent(byte[] content); /** * Gets the attachment content type. * For example "image/gif". * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" * * @return Attachment content type */ public abstract String getContentType(); /** * Sets the attachment content type. * For example "image/gif". * * @param contentType Attachment content type */ public abstract void setContentType(String contentType); /** * Gets the attachment content size in bytes. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" * * @return Attachment content size in bytes */ public abstract long getSize(); /** * Sets the attachment content size in bytes. * * @param size Attachment content size in bytes */ public abstract void setSize(long size); /** * Gets the attachment ordering index. * This is used to preserve the ordering of multiple attachments to a owner. * The first attachment has index 0, second attachment has index 1, etc. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" * * @return Ordering index */ public abstract int getOrderingIndex(); /** * Sets the attachment ordering index. * This is used to preserve the ordering of multiple attachments to a owner. * * @param index Ordering index */ public abstract void setOrderingIndex(int index); /** * Gets the attachment positioning meta-data. * This is useful when the attachment may be laid out visually on the GUI. * For example a GIF image attached to a question may have position * specified as "EAST" to indicate that it should be displayed to the right * of the main question text. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" * * @return Positioning meta data. */ public abstract String getPosition(); /** * Sets the attachment positioning meta-data. * This is useful when the attachment may be laid out visually on the GUI. * For example a GIF image attached to a question may have position * specified as "EAST" to indicate that it should be displayed to the right * of the main question text. * * @ejb.interface-method * * @param position Positioning meta data */ public abstract void setPosition(String position); /** * Gets the owner ID. * This is the ID of the object that this attachment is attached to. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" dbindex="true" * * @return Owner ID. */ public abstract Integer getOwnerId(); /** * Sets the owner ID. * This is the ID of the object that this attachment is attached to. * * @param ownerId Owner ID */ public abstract void setOwnerId(Integer ownerId); /** * Gets the owner type. * For example AttachmentBean.QUESTION_OWNER_TYPE or AttachmentBean.ANSWER_CHOICE_OWNER_TYPE. * * @ejb.interface-method * @ejb.persistence * @jboss.persistence not-null="true" dbindex="true" * * @return Owner type. */ public abstract Integer getOwnerType(); /** * Sets the owner type. * For example AttachmentBean.QUESTION_OWNER_TYPE or AttachmentBean.ANSWER_CHOICE_OWNER_TYPE. * * @param ownerType Owner type */ public abstract void setOwnerType(Integer ownerType); /** * 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() ); } //----------------------------- // Create methods. //----------------------------- /** * Creates an Attachment. * * @ejb.create-method view-type="local" */ public Integer ejbCreate( Integer ownerId, Integer ownerType, int orderingIndex, String position, byte[] content, String contentType ) throws CreateException { // Note : Unique ID is assigned by database auto-increment setOwnerId(ownerId); setOwnerType(ownerType); setOrderingIndex(orderingIndex); setPosition( position ); setContent(content); setContentType(contentType); setSize( content.length ); return null; } public void ejbPostCreate( Integer ownerId, Integer ownerType, int orderingIndex, String position, byte[] content, String contentType ) { // Nothing here }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -