spring+hibernate+struts2+compass整合(二)

2014-11-24 07:34:31 · 作者: · 浏览: 3
oducts() {
22 return getHibernateTemplate().find("from Product order by id desc");
23 }
24
25 public void remove(String id) {
26 getHibernateTemplate().delete(getProduct(id));
27
28 }
29
30 public void update(Product product) {
31 getHibernateTemplate().saveOrUpdate(product);
32
33 }
34
35 }

/compass1/src/com/v512/example/model/Product.java
在实体类中注入compass
1 package com.v512.example.model;
2
3 import org.compass.annotations.*;
4
5 /**
6 * Product entity.
7 *
8 * @author MyEclipse Persistence Tools
9 */
10 @Searchable
11 public class Product implements java.io.Serializable {
12
13 // Fields
14 //在实体类中注入compass
15 @SearchableId
16 private String id;
17 @SearchableProperty(name = "name")
18 private String name;
19 @SearchableProperty(name = "price")
20 private Double price;
21 @SearchableProperty(name = "brand")
22 private String brand;
23 @SearchableProperty(name = "description")
24 private String description;
25
26 // Constructors
27
28 /** default constructor */
29 public Product() {
30 }
31
32 /** full constructor */
33 public Product(String name, Double price, String brand, String description) {
34 this.name = name;
35 this.price = price;
36 this.brand = brand;
37 this.description = description;
38 }
39
40 // Property accessors
41
42 public String getId() {
43 return this.id;
44 }
45
46 public void setId(String id) {
47 this.id = id;
48 }
49
50 public String getName() {
51 return this.name;
52 }
53
54 public void setName(String name) {
55 this.name = name;
56 }
57
58 public Double getPrice() {
59 return this.price;
60 }
61
62 public void setPrice(Double price) {
63 this.price = price;
64 }
65
66 public String getBrand() {
67 return this.brand;
68 }
69
70 public void setBrand(String brand) {
71 this.brand = brand;
72 }
73
74 public String getDescription() {
75 return this.description;
76 }
77
78 public void setDescription(String description) {
79 this.description = description;
80 }
81
82 }

/compass1/src/com/v512/example/model/Product.hbm.xml
1 < xml version="1.0" encoding="utf-8" >
2 3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4
7
8
9
10
11
12

13
14
15

16
17
18

19
20
21

22
23
24

25

26

/compass1/src/com/v512/example/service/ProductManager.java
1 package com.v512.example.service;
2
3 import java.util.List;
4
5 import com.v512.example.model.Product;
6
7 public interface ProductManager {
8 public void insertProduct(Product p);
9
10 public Product findProdcut(String id);
11
12 public List searchProducts(String queryString);
13
14 }

/compass1/src/com/v512/example/service/impl/CompassIndexBuilder.java
1 package com.v512.example.service.impl;
2
3 import org.compass.gps.CompassGps;
4 import org.springframework.beans.factory.InitializingBean;
5
6 /**
7 * 通过quartz定时调度定时重建索引或自动随Spring ApplicationContext启动而重建索引的Builder.
8 * 会启动后延时数秒新开线程调用compassGps.index()函数.
9 * 默认会在Web应用每