Ver Fonte

[search-console-b2b] copy LuceneMessage to com.uas.search.console.b2b.jms.platformmanager

sunyj há 8 anos atrás
pai
commit
9993600164

+ 2 - 2
search-console-b2b/src/main/java/com/uas/search/console/b2b/Platformb2bRepositoryConfiguration.java

@@ -25,7 +25,7 @@ import com.uas.search.console.b2b.util.SearchConstants;
  */
 @Configuration
 @EnableJpaRepositories(entityManagerFactoryRef = "platformb2bEntityManagerFactory", transactionManagerRef = "platformb2bTransactionManager", basePackages = {
-		"com.uas.search.console.b2b.dao" })
+		"com.uas.search.console.b2b.dao", "com.uas.search.console.b2b.jms.platformb2b"})
 public class Platformb2bRepositoryConfiguration {
 
 	@Autowired
@@ -40,7 +40,7 @@ public class Platformb2bRepositoryConfiguration {
 	public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
 		return builder.dataSource(platformb2bDataSource)
 				.properties(jpaProperties.getHibernateProperties(platformb2bDataSource))
-				.packages("com.uas.search.console.b2b.model").persistenceUnit("platformb2bPersistenceUnit").build();
+				.packages("com.uas.search.console.b2b.model", "com.uas.search.console.b2b.jms.platformb2b").persistenceUnit("platformb2bPersistenceUnit").build();
 	}
 
 	@Bean(name = "platformb2bEntityManager")

+ 2 - 2
search-console-b2b/src/main/java/com/uas/search/console/b2b/PlatformmanagerRepositoryConfiguration.java

@@ -24,7 +24,7 @@ import com.uas.search.console.b2b.util.SearchConstants;
  */
 @Configuration
 @EnableJpaRepositories(entityManagerFactoryRef = "platformmanagerEntityManagerFactory", transactionManagerRef = "platformmanagerTransactionManager", basePackages = {
-		"com.uas.search.console.b2b.platformmanager.dao" })
+		"com.uas.search.console.b2b.platformmanager.dao", "com.uas.search.console.b2b.jms.platformmanager"})
 public class PlatformmanagerRepositoryConfiguration {
 
 	@Autowired
@@ -38,7 +38,7 @@ public class PlatformmanagerRepositoryConfiguration {
 	public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
 		return builder.dataSource(platformmanagerDataSource)
 				.properties(jpaProperties.getHibernateProperties(platformmanagerDataSource))
-				.packages("com.uas.search.console.b2b.platformmanager.model")
+				.packages("com.uas.search.console.b2b.platformmanager.model", "com.uas.search.console.b2b.jms.platformmanager")
 				.persistenceUnit("platformmanagerPersistenceUnit").build();
 	}
 

+ 153 - 0
search-console-b2b/src/main/java/com/uas/search/console/b2b/jms/platformmanager/LuceneMessage.java

@@ -0,0 +1,153 @@
+package com.uas.search.console.b2b.jms.platformmanager;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 用于实时更新的消息
+ *
+ * @author sunyj
+ * @since 2016年12月1日 下午3:05:22
+ */
+@Entity
+@Table(name = "lucene$message")
+public class LuceneMessage implements Serializable {
+
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @Column(name = "me_id")
+    private Long id;
+
+    /**
+     * 表名
+     */
+    @Column(name = "me_table_name")
+    private String tableName;
+
+    /**
+     * 更改类型
+     */
+    @Column(name = "me_method_type")
+    private String methodType;
+
+    /**
+     * 数据 id
+     */
+    @Column(name = "me_data_id")
+    private Long dataId;
+
+    /**
+     * 数据,可为空
+     */
+    @Column(name = "me_data")
+    private String data;
+
+    /**
+     * 优先级
+     */
+    @Column(name = "me_priority")
+    private Long priority;
+
+    /**
+     * 尝试次数
+     */
+    @Column(name = "me_retry_count")
+    private Long retryCount;
+
+    /**
+     * 时间
+     */
+    @Column(name = "me_create_time")
+    private Date createTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
+    public String getMethodType() {
+        return methodType;
+    }
+
+    public void setMethodType(String methodType) {
+        this.methodType = methodType;
+    }
+
+    public Long getDataId() {
+        return dataId;
+    }
+
+    public void setDataId(Long dataId) {
+        this.dataId = dataId;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public Long getPriority() {
+        return priority;
+    }
+
+    public void setPriority(Long priority) {
+        this.priority = priority;
+    }
+
+    public Long getRetryCount() {
+        return retryCount;
+    }
+
+    public void setRetryCount(Long retryCount) {
+        this.retryCount = retryCount;
+    }
+
+    public String getCreateTime() {
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime);
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    @Override
+    public String toString() {
+        return "LuceneMessage{" +
+                "id=" + id +
+                ", tableName='" + tableName + '\'' +
+                ", methodType='" + methodType + '\'' +
+                ", dataId=" + dataId +
+                ", data='" + data + '\'' +
+                ", priority=" + priority +
+                ", retryCount=" + retryCount +
+                ", createTime=" + createTime +
+                '}';
+    }
+}
+

+ 46 - 0
search-console-b2b/src/main/java/com/uas/search/console/b2b/jms/platformmanager/LuceneMessageDao.java

@@ -0,0 +1,46 @@
+package com.uas.search.console.b2b.jms.platformmanager;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.jpa.repository.query.Procedure;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * @author sunyj
+ * @since 2016年12月1日 下午5:35:24
+ */
+@Repository
+public interface LuceneMessageDao
+        extends JpaSpecificationExecutor<LuceneMessage>, JpaRepository<LuceneMessage, Long> {
+
+    /**
+     * 获取指定数目的数据
+     *
+     * @param start 开始的记录
+     * @param size  指定数目
+     * @return 数据
+     */
+    @Query(value = "select * from lucene$message where me_retry_count < 5 order by me_priority desc, me_id limit ?1, ?2", nativeQuery = true)
+    List<LuceneMessage> findList(Integer start, Integer size);
+
+    /**
+     * 统计行数
+     *
+     * @return 行数
+     */
+    @Query(value = "select count(1) from lucene$message where me_retry_count < 5", nativeQuery = true)
+    long count();
+
+    /**
+     * 出队消息
+     *
+     * @param id 消息 id
+     */
+    @Transactional
+    @Procedure(procedureName = "dequeue_lucene_message")
+    void dequeueLuceneMessage(Long id);
+}