初始化Bean,实现Spring运行加载
public class CompassIndexBuilder implements InitializingBean{
private boolean buildIndex = false;
private int lazySecond =10;
private CompassGps compassGps;
private Thread compassStartThread = new Thread( new Runnable(){
public void run() {
try {
Thread.sleep(lazySecond * 1000);
Stopwatch watch =new Stopwatch();
compassGps.index();
print("Compass builder index cost time :"+watch.reset());
} catch (InterruptedException e) {
print("Compass builder throw graveness error "+e);
}
}
});
public void print(String str){
PrintWriter printWriter = new PrintWriter(System.out);
printWriter.println(str);
}
public void afterPropertiesSet() throws Exception {
if(buildIndex){
compassStartThread.setDaemon(true);
compassStartThread.setName("Compass index builder");
compassStartThread.start();
}
}
public void setBuildIndex(boolean buildIndex) {
this.buildIndex = buildIndex;
}
public void setLazySecond(int lazySecond) {
this.lazySecond = lazySecond;
}
public void setCompassGps(CompassGps compassGps) {
this.compassGps = compassGps;
}
}
Compass Search,my tools
import java.util.ArrayList;
import java.util.List;
import org.compass.core.Compass;
import org.compass.core.CompassCallback;
import org.compass.core.CompassException;
import org.compass.core.CompassHits;
import org.compass.core.CompassQuery;
import org.compass.core.CompassQueryBuilder;
import org.compass.core.CompassSession;
import org.compass.core.CompassTemplate;
import org.hibernate.cfg.annotations.QueryBinder;
public class CompassSearch<E> implements Search<E>{
private Compass compass;
public void delete(E e) {
CompassTemplate template = new CompassTemplate(compass);
template.delete(e);
}
public List<E> find(final String keyword) {
CompassTemplate template = new CompassTemplate(compass);
return template.execute(new CompassCallback<List<E>>(){
public List<E> doInCompass(CompassSession session) throws CompassException {
List<E> results = new ArrayList<E>();
CompassQueryBuilder queryBuilder= session.queryBuilder();
CompassHits hits = null;
CompassQuery allProperty = queryBuilder.queryString(keyword).toQuery();
hits = allProperty.hits();
int length = hits.length();
for(int i=0;i<length; i++){
results.add((E)hits.data(i));
}
return results;
}
});
}
public void index(E e) {
CompassTemplate template = new CompassTemplate(compass);
template.create(e);
}
public void update(final E e) {
CompassTemplate template = new CompassTemplate(compass);
template.execute(new CompassCallback<E>(){
public E doInCompass(CompassSession session)
throws CompassException {
session.delete(e);
session.create(e);
return null;
}
});
}
public void setCompass(Compass compass) {
this.compass = compass;
}
}
<bean id="annotationConfiguration" class="org.compass.annotations.config.CompassAnnotationsConfiguration" />
<bean id="compass" class="org.compass.spring.LocalCompassBean">
<property name="compassConfiguration">
<ref bean="annotationConfiguration"/>
</property>
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="settings">
<props>
<prop key="compass.engine.connection">d:/compass</prop>
<prop key="compass.transaction.factory">
org.compass.spring.transaction.SpringSyncTransactionFactory
</prop>
<prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">
org.mira.lucene.analysis.IK_CAnalyzer
</prop>
</props>
</property>
<!-- <property name="resourceJarLocations">
<list>
<value>WEB-INF/lib/your.jar</value>
</list>
</property>
-->
<property name="resourceDirectoryLocations">
<list>
<value>com/you/model</value>
</list>
</property>
</bean>
<bean id="jpaGpsDevice" class="org.compass.gps.device.jpa.JpaGpsDevice">
<property name="name">
<value>JpaGpsDevice</value>
</property>
<property name="entityManagerFactory">
<ref bean="entityManagerFactory"/>
</property>
<property name="mirrorDataChanges">
<value>true</value>
</property>
</bean>
<bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop">
<property name="compass">
<ref bean="compass"/>
</property>
<property name="gpsDevices">
<ref bean="jpaGpsDevice"/>
</property>
</bean>
<bean id="compassTemplate" class="org.compass.core.CompassTemplate">
<property name="compass">
<ref bean="compass"/>
</property>
</bean>
<bean id="compassIndexBuilder" class="com.crm.compass.CompassIndexBuilder">
<property name="buildIndex" value="true" />
<property name="lazySecond" value="10" />
<property name="compassGps">
<ref bean="compassGps"/>
</property>
</bean>
<bean id="exploitCustomerSearch" class="com.crm.dao.compass.ExploitCustomerSearch">
<property name="compass">
<ref bean="compass"/>
</property>
</bean>
if you look do not understand ,please check
http://lqw.iteye.com/blog/348970
分享到:
相关推荐
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码 hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码
hibernate-jpa-2.0-api-1.0.1.Final-sources.jar hibernate jpa 源代码
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar官方下载,请放心使用
`hibernate-jpa-2.1-api-1.0.0.final.jar`是Hibernate对JPA 2.1规范的实现库,它使得开发者能够使用Hibernate的高效功能同时遵循JPA规范。 **1. Hibernate与JPA的关系** Hibernate最初作为一个独立的ORM框架,后来...
在本主题中,我们将深入探讨"JPA (Java Persistence API) 与 Hibernate"在Spring Boot框架中的应用。作为从零开始学习Spring Boot的一部分,理解如何有效地利用这些技术进行数据库操作至关重要。 首先,JPA是Java...
java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil 或javax/persistence/entitylistener问题
Struts2、Hibernate3和Spring是Java开发中常用的三大框架,它们各自负责不同的职责:Struts2用于控制应用程序的流程,Hibernate3则是优秀的对象关系映射(ORM)框架,Spring则提供全面的依赖注入(DI)和面向切面...
赠送jar包:spring-data-jpa-2.0.9.RELEASE.jar; 赠送原API文档:spring-data-jpa-2.0.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-jpa-2.0.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-data-jpa...
java运行依赖jar包
克隆存储库git clone https://github.com/callicoder/spring-boot-postgresql-jpa-hibernate-rest-api-demo.git 2.配置PostgreSQL 首先,创建一个名为postgres_demo的数据库。 然后,打开src/main/resources/...
JPA + Hibernate + Spring + Data JPA-快速入门模板 模板/范例 Hibernate独立 Hibernate+ JPA Hibernate + Spring XML Hibernate + JPA + Spring XML Hibernate + JPA + Spring批注 Hibernate + JPA + Spring批注...
赠送jar包:spring-data-jpa-2.0.9.RELEASE.jar; 赠送原API文档:spring-data-jpa-2.0.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-jpa-2.0.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-data-jpa...
2. **JPA Provider**: Hibernate作为JPA的实现,其自身包含了一个JPA提供者,如`hibernate-entitymanager.jar`,它提供了对JPA规范的实现。 3. **JTA (Java Transaction API)**: 为了实现事务管理,通常需要`jta.jar...
《在线商店项目:基于Spring Boot、JSP、JPA-Hibernate和Spring MVC的实现》 在信息技术领域,构建一个功能完善的在线商店系统是一项常见的任务,它涉及到多种技术的集成和应用。本项目“online-store-spring”正是...
本篇文章将重点围绕“hibernate-jpa-2.1-api-1.0.0.final-sources.jar.zip”这一压缩包,深入解析Hibernate对JPA 2.1 API的实现,以期帮助读者深入理解其内部机制。 JPA(Java Persistence API)是Java平台上的一个...
这个源码包"hibernate-jpa-2.0-api-1.0.1.Final-sources"包含了完整的源代码,可以帮助我们深入了解其内部机制,从而更好地应用在实际项目中。 1. **JPA简介**:Java Persistence API(JPA)是Java平台上的一个标准...