cmp-ProductBean.java

本文介绍了一个使用容器管理持久化的实体Bean示例——产品Bean。该Bean包含基本的产品信息如ID、名称、描述和基准价格,并实现了EJB生命周期方法。

package examples;

 

import javax.ejb.*;

 

/**

 * Entity Bean which demonstrates Container-Managed persistence.

 *

 * This is a product that's persistent.  It has an ID #, a name,

 * a description, and a base price.

 */

public abstract class ProductBean implements EntityBean {

 

 protected EntityContext ctx;

 

 public ProductBean() {

 }

 

 //----------------------------------------------------------------

 // Begin abstract get/set methods

 //----------------------------------------------------------------

 

        public abstract String getName();

 public abstract void setName(String name);

 public abstract String getDescription();

 public abstract void setDescription(String description); 

        public abstract double getBasePrice(); 

        public abstract void setBasePrice(double price); 

 public abstract String getProductID();

 public abstract void setProductID(String productID);

 

 //----------------------------------------------------------------

 // End abstract get/set methods

 //----------------------------------------------------------------

 

 //----------------------------------------------------------------

 // Begin EJB-required methods.  The methods below are called

 // by the Container, and never called by client code.

 //----------------------------------------------------------------

 

 /**

  * Called by Container.

  * Implementation can acquire needed resources.

  */

 public void ejbActivate() {

  System.out.println("ejbActivate() called.");

 }

 

 /**

  * EJB Container calls this method right before it

  * removes the Entity Bean from the database.

  * Corresponds to when client calls home.remove().

  */

 public void ejbRemove() {

  System.out.println("ejbRemove() called.");

 }

 

 /**

  * Called by Container.

  * Releases held resources for passivation.

  */

 public void ejbPassivate() {

  System.out.println("ejbPassivate () called.");

 }

 

 /**

  * Called from the Container.  Updates the entity bean

  * instance to reflect the current value stored in

  * the database.

  *

  * Since we're using Container-Managed Persistence, we

  * can leave this method blank.  The EJB Container will

  * automatically set our public fields to the correct values.

  */

 public void ejbLoad() {

  System.out.println("ejbLoad() called.");

 }

 

 /**

  * Called from the Container.  Updates the database to

  * reflect the current values of this in-memory Entity Bean

  * instance representation.

  *

  * Since we're using Container-Managed Persistence, we can

  * leave this method blank.  The EJB Container will

  * automatically save our public fields into the database.

  */

 public void ejbStore() {

  System.out.println("ejbStore() called.");

 }

 

 /**

  * Called by Container.  Associates this Bean instance with

  * a particular context.  Once done, we can query the

  * Context for environment info

  */

 public void setEntityContext(EntityContext ctx) {

  System.out.println("setEntityContext called");

  this.ctx = ctx;

 }

 

 /**

  * Called by Container.  Disassociates this Bean instance

  * with a particular context environment.

  */

 public void unsetEntityContext() {

  System.out.println("unsetEntityContext called");

  this.ctx = null;

 }

 

 /**

  * Called after ejbCreate().  Now, the Bean can retrieve

  * its EJBObject from its context, and pass it as a 'this'

  * argument.

  */

 public void ejbPostCreate(String productID, String name, String description, double basePrice) {

  System.out.println("ejbPostCreate() called");

 }

 

 /**

  * This is the initialization method that corresponds to the

  * create() method in the Home Interface.

  *

  * When the client calls the Home Object's create() method,

  * the Home Object then calls this ejbCreate() method.

  *

  * NOTE: Since we're using Container-Managed persistence,

  * this method returns void.  With Bean-Managed Persistence,

  * we returned the PK.  This is because our Bean was

  * responsible for dealing with PKs and accessing

  * the database.  Now that we let the Container handle

  * persistence, the Container makes the Primary Key.

  *

  * We still need to initialize our Bean's fields with the

  * parameters passed from the client, so that the Container

  * can inspect our Bean and create the corresponding database

  * entries.

  */

 public String ejbCreate(String productID, String name, String description, double basePrice) {

  System.out.println("ejbCreate() called");

 

  setProductID(productID);

  setName(name);

  setDescription(description);

  setBasePrice(basePrice);

 

  return productID;

 }

 

 // No finder methods - they are implemented by Container

 

 //----------------------------------------------------------------

 // End EJB-required methods

 //----------------------------------------------------------------

}

 

你的问题是: > `if [ -r $TARGET ] && \ grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \ grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \ cmp -s .tmpver.1 .tmpver.2; then rm -f .tmpcompile` 会忽略 `compile.h` 里的注释吗? --- ### ✅ 简要回答: **默认情况下,这个脚本不会专门忽略注释行**,除非注释行匹配了 `$IGNORE_PATTERN`。 也就是说: - **是否忽略注释,取决于 `$IGNORE_PATTERN` 的值。** - 如果 `$IGNORE_PATTERN` 包含匹配注释的正则表达式(例如 `^//` 或 `^/\*`),那就会忽略。 - 否则,注释行会被保留,并参与比较。 --- ### 🧪 脚本逐行解释: ```bash if [ -r $TARGET ] && \ grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \ grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \ cmp -s .tmpver.1 .tmpver.2; then rm -f .tmpcompile ``` - `[ -r $TARGET ]`:检查目标文件是否可读。 - `grep -v $IGNORE_PATTERN $TARGET > .tmpver.1`:将 `$TARGET` 中**不匹配** `$IGNORE_PATTERN` 的行输出到 `.tmpver.1`。 - 同理 `.tmpcompile` 被处理成 `.tmpver.2`。 - `cmp -s .tmpver.1 .tmpver.2`:静默比较两个文件是否完全一致。 - 如果一致,就删除 `.tmpcompile`。 --- ### 📌 关键点:是否忽略注释? 取决于 `$IGNORE_PATTERN` 的值,例如: ```bash IGNORE_PATTERN='UTS_VERSION\|#.*' ``` 这只会忽略包含 `UTS_VERSION` 或以 `#` 开头的行,并**不会忽略 C 风格注释**(如 `//` 或 `/* */`)。 如果你希望也忽略注释,可以将 `$IGNORE_PATTERN` 设置为: ```bash IGNORE_PATTERN='UTS_VERSION\|#.*\|^//\|^/\*' ``` 这样就能忽略: - `UTS_VERSION` - `#` 开头的预处理行 - `//` 单行注释 - `/* */` 多行注释开头 --- ### ✅ 总结: | 项目 | 说明 | |-----------------------|------| | 是否忽略注释? | **取决于 `$IGNORE_PATTERN`** | | 默认是否忽略? | **否** | | 如何让它忽略注释? | 在 `$IGNORE_PATTERN` 中添加 `^//` 或 `^/\*` 正则表达式 | | 注释是否参与比较? | 是,除非被 `grep -v` 排除 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值