新增: 支持 PostgreSQL 数据库
This commit is contained in:
parent
0998501c93
commit
7f962319f5
@ -6,7 +6,10 @@
|
|||||||
<persistence-unit name="z_im">
|
<persistence-unit name="z_im">
|
||||||
<shared-cache-mode>ALL</shared-cache-mode>
|
<shared-cache-mode>ALL</shared-cache-mode>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://47.106.237.198:3306/z_im"/>
|
<!-- mysql -->
|
||||||
|
<!--<property name="javax.persistence.jdbc.url" value="jdbc:mysql://47.106.237.198:3306/z_im"/>-->
|
||||||
|
<!-- postgresql -->
|
||||||
|
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://47.106.237.198:3306/z_im?currentSchema=public"/>
|
||||||
<property name="javax.persistence.jdbc.user" value="u_im"/>
|
<property name="javax.persistence.jdbc.user" value="u_im"/>
|
||||||
<property name="javax.persistence.jdbc.password" value="u_im@2024"/>
|
<property name="javax.persistence.jdbc.password" value="u_im@2024"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
12
pom.xml
12
pom.xml
@ -28,12 +28,24 @@
|
|||||||
<version>2.2.0</version>
|
<version>2.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redkalex</groupId>
|
||||||
|
<artifactId>redkale-plugins</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<version>8.2.0</version>
|
<version>8.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.7.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.tccn</groupId>
|
<groupId>net.tccn</groupId>
|
||||||
<artifactId>zhub-client-redkale</artifactId>
|
<artifactId>zhub-client-redkale</artifactId>
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
package com.zchd.base;
|
package com.zchd.base;
|
||||||
|
|
||||||
|
import com.zchd.base.util.Utils;
|
||||||
import net.tccn.zhub.ZHubClient;
|
import net.tccn.zhub.ZHubClient;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.service.AbstractService;
|
import org.redkale.service.AbstractService;
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
||||||
|
import org.redkale.source.DataJdbcSource;
|
||||||
import org.redkale.source.DataSource;
|
import org.redkale.source.DataSource;
|
||||||
|
import org.redkale.source.PoolSource;
|
||||||
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
import org.redkalex.cache.redis.MyRedisCacheSource;
|
import org.redkalex.cache.redis.MyRedisCacheSource;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.sql.Connection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -42,6 +47,21 @@ public class BaseService extends AbstractService {
|
|||||||
@Resource(name = "APP_NAME")
|
@Resource(name = "APP_NAME")
|
||||||
protected String APP_NAME = "";
|
protected String APP_NAME = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(AnyValue config) {
|
||||||
|
|
||||||
|
PoolSource<Connection> source = ((DataJdbcSource) zimSource).getReadPoolSource();
|
||||||
|
// postgresql 设置当前schema
|
||||||
|
if ("postgresql".equals(source.getDbtype())) {
|
||||||
|
String url = source.getUrl();
|
||||||
|
String schema = getCurrentSchema(url);
|
||||||
|
if (Utils.isEmpty(schema)) {
|
||||||
|
schema = "public";
|
||||||
|
}
|
||||||
|
((DataJdbcSource) zimSource).directExecute(String.format("SET search_path TO %s;", schema));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected RetResult retError(String info) {
|
protected RetResult retError(String info) {
|
||||||
return new RetResult<>(100, info);
|
return new RetResult<>(100, info);
|
||||||
}
|
}
|
||||||
@ -49,4 +69,21 @@ public class BaseService extends AbstractService {
|
|||||||
protected RetResult retError(int code, String info) {
|
protected RetResult retError(int code, String info) {
|
||||||
return new RetResult<>(code, info);
|
return new RetResult<>(code, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 postgresql url当前schema
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getCurrentSchema(String url) {
|
||||||
|
String[] arr = url.split("currentSchema=");
|
||||||
|
if (arr.length > 1) {
|
||||||
|
String[] arr2 = arr[1].split("&");
|
||||||
|
if (arr2.length > 0) {
|
||||||
|
return arr2[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ public class ImAccountService extends BaseService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(AnyValue config) {
|
public void init(AnyValue config) {
|
||||||
|
super.init(config);
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
List<Serializable> list = zimSource.queryColumnList("userid", ImUser.class, new Flipper(1, "userid DESC"), (FilterBean) null);
|
List<Serializable> list = zimSource.queryColumnList("userid", ImUser.class, new Flipper(1, "userid DESC"), (FilterBean) null);
|
||||||
|
@ -79,7 +79,7 @@ public class ImChatWebSocket extends WebSocket {
|
|||||||
final int userid = (int) getUserid();
|
final int userid = (int) getUserid();
|
||||||
getLogger().info("im:state-change:" + userid + "---ws connected---");
|
getLogger().info("im:state-change:" + userid + "---ws connected---");
|
||||||
intCache.setBit("im:user", userid, true);
|
intCache.setBit("im:user", userid, true);
|
||||||
// 推送离线状态
|
// 推送上线状态
|
||||||
zhub.publish("im:online:" + getAttribute("appid"), getAttribute("guserid"));
|
zhub.publish("im:online:" + getAttribute("appid"), getAttribute("guserid"));
|
||||||
// 上线开启订阅
|
// 上线开启订阅
|
||||||
messageMonitor.online(userid);
|
messageMonitor.online(userid);
|
||||||
|
Loading…
Reference in New Issue
Block a user