Skip to content

Commit f8c8fcd

Browse files
committed
增加数据库存储支持v1.2
1 parent c8e76b2 commit f8c8fcd

File tree

9 files changed

+149
-17
lines changed

9 files changed

+149
-17
lines changed

pom.xml

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@
118118
</execution>
119119
</executions>
120120
</plugin>
121-
<!-- 打jar包 -->
121+
<!-- 打jar包 https://blog.csdn.net/mn960mn/article/details/51554152 -->
122+
<!-- lib目录中jar的存放规则,默认是${groupId}/${artifactId}的目录格式,flat表示直接把jar放到lib目录 -->
123+
122124
<plugin>
123125
<groupId>org.codehaus.mojo</groupId>
124126
<artifactId>appassembler-maven-plugin</artifactId>
@@ -133,12 +135,18 @@
133135
</execution>
134136
</executions>
135137
<configuration>
136-
<assembleDirectory>${project.build.directory}/</assembleDirectory>
138+
<assembleDirectory>${project.build.directory}/nbs</assembleDirectory>
137139
<repositoryLayout>flat</repositoryLayout>
140+
<repositoryName>lib</repositoryName>
141+
<binFolder>bin</binFolder>
142+
<configurationDirectory>conf</configurationDirectory>
138143
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
139-
<configurationSourceDirectory>config</configurationSourceDirectory>
140144
<configurationDirectory>true</configurationDirectory>
145+
141146
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
147+
<encoding>UTF-8</encoding>
148+
<logsDirectory>logs</logsDirectory>
149+
<tempDirectory>tmp</tempDirectory>
142150
<extraJvmArguments>-Xms256m</extraJvmArguments>
143151
<binFileExtensions><unix>.sh</unix></binFileExtensions>
144152
<platforms>
@@ -152,15 +160,89 @@
152160
<name>nbs-client4j</name>
153161
<jvmSettings>
154162
<extraArguments>
163+
<extraArgument>-Dfile.encoding=utf-8</extraArgument>
155164
<extraArgument>-server</extraArgument>
156165
<extraArgument>-Xms256m</extraArgument>
157166
</extraArguments>
158167
</jvmSettings>
159168
</program>
160169
</programs>
161170
</configuration>
171+
162172
</plugin>
163173

174+
<!-- <plugin>
175+
<groupId>org.codehaus.mojo</groupId>
176+
<artifactId>appassembler-maven-plugin</artifactId>
177+
<version>2.0.0</version>
178+
<configuration>
179+
&lt;!&ndash; 根目录 &ndash;&gt;
180+
<assembleDirectory>${project.build.directory}/nbs</assembleDirectory>
181+
&lt;!&ndash; 打包的jar,以及maven依赖的jar放到这个目录里面 &ndash;&gt;
182+
<repositoryName>lib</repositoryName>
183+
&lt;!&ndash; 可执行脚本的目录 &ndash;&gt;
184+
<binFolder>bin</binFolder>
185+
&lt;!&ndash; 配置文件的目标目录 &ndash;&gt;
186+
<configurationDirectory>conf</configurationDirectory>
187+
&lt;!&ndash; 拷贝配置文件到上面的目录中 &ndash;&gt;
188+
<copyConfigurationDirectory>true</copyConfigurationDirectory>
189+
&lt;!&ndash; 从哪里拷贝配置文件 (默认src/main/config) &ndash;&gt;
190+
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
191+
&lt;!&ndash; lib目录中jar的存放规则,默认是${groupId}/${artifactId}的目录格式,flat表示直接把jar放到lib目录 &ndash;&gt;
192+
<repositoryLayout>flat</repositoryLayout>
193+
<encoding>UTF-8</encoding>
194+
<logsDirectory>logs</logsDirectory>
195+
<tempDirectory>tmp</tempDirectory>
196+
<daemons>
197+
<daemon>
198+
<id>nbs</id>
199+
<mainClass>UI.AppMainWindow</mainClass>
200+
<platforms>
201+
<platform>jsw</platform>
202+
</platforms>
203+
<generatorConfigurations>
204+
<generatorConfiguration>
205+
<generator>jsw</generator>
206+
<includes>
207+
<include>linux-x86-32</include>
208+
<include>linux-x86-64</include>
209+
<include>windows-x86-32</include>
210+
<include>windows-x86-64</include>
211+
</includes>
212+
<configuration>
213+
<property>
214+
<name>configuration.directory.in.classpath.first</name>
215+
<value>conf</value>
216+
</property>
217+
<property>
218+
<name>wrapper.ping.timeout</name>
219+
<value>120</value>
220+
</property>
221+
<property>
222+
<name>set.default.REPO_DIR</name>
223+
<value>lib</value>
224+
</property>
225+
<property>
226+
<name>wrapper.logfile</name>
227+
<value>logs/wrapper.log</value>
228+
</property>
229+
</configuration>
230+
</generatorConfiguration>
231+
</generatorConfigurations>
232+
<jvmSettings>
233+
&lt;!&ndash; jvm参数 &ndash;&gt;
234+
<systemProperties>
235+
<systemProperty>com.sun.management.jmxremote</systemProperty>
236+
<systemProperty>com.sun.management.jmxremote.port=1984</systemProperty>
237+
<systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty>
238+
<systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty>
239+
</systemProperties>
240+
</jvmSettings>
241+
</daemon>
242+
</daemons>
243+
</configuration>
244+
</plugin>
245+
&lt;!&ndash; package end &ndash;&gt;
164246
<plugin>
165247
<groupId>org.apache.maven.plugins</groupId>
166248
<artifactId>maven-dependency-plugin</artifactId>
@@ -172,14 +254,14 @@
172254
<goal>copy-dependencies</goal>
173255
</goals>
174256
<configuration>
175-
<!--&lt;!&ndash; ${project.build.directory} 构建目录,缺省为target &ndash;&gt; -->
257+
&lt;!&ndash;&lt;!&ndash; ${project.build.directory} 构建目录,缺省为target &ndash;&gt; &ndash;&gt;
176258
<outputDirectory>
177259
${project.build.directory}/lib
178260
</outputDirectory>
179261
</configuration>
180262
</execution>
181263
</executions>
182-
</plugin>
264+
</plugin>-->
183265

184266
<!-- The configuration of maven-assembly-plugin -->
185267
<!-- <plugin>

profile/nbs.db

0 Bytes
Binary file not shown.

src/main/java/UI/AppMainWindow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ private void loadEnv(){
274274
ipfsDir.mkdirs();
275275
}
276276

277-
File f = new File(ConstantsUI.PROFILE_ROOT);
277+
/**
278+
* 初始化
279+
*/
280+
File f = new File(ConfigHelper.NBS_CACHE_AVATAR_ROOT_PATH);
278281
if(!f.exists()){
279282
f.mkdirs();
280283
}

src/main/java/com/nbs/biz/dao/ContactsDao.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.nbs.biz.dao;
22

3+
import com.nbs.biz.model.ContactsEntity;
34
import org.apache.ibatis.session.SqlSession;
45

6+
import java.util.List;
57

68

79
/**
@@ -20,4 +22,13 @@ public ContactsDao(SqlSession session) {
2022
public int existCountByPeerId(String peerId){
2123
return 0;
2224
}
25+
26+
/**
27+
*
28+
* @param id
29+
* @return
30+
*/
31+
public List<ContactsEntity> findAllExcludeId(String id){
32+
return session.selectList("findAllExcludeId",id);
33+
}
2334
}

src/main/java/com/nbs/biz/service/ContactsService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.nbs.biz.model.ContactsEntity;
66
import org.apache.ibatis.session.SqlSession;
77

8+
import java.util.List;
9+
810
/**
911
* @Package : com.nbs.biz.service
1012
* @Description : <p></p>
@@ -24,11 +26,14 @@ public ContactsService(SqlSession session) {
2426
}
2527

2628
public int insertOrUpdate(ContactsEntity entity){
27-
2829
if(exist(entity.getId())){
2930
return update(entity);
3031
}else {
3132
return insert(entity);
3233
}
3334
}
35+
36+
public List<ContactsEntity> getAllExcludeSelf(String peerid){
37+
return dao.findAllExcludeId(peerid);
38+
}
3439
}

src/main/java/com/nbs/ui/panels/ContactsPanel.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import UI.panel.im.IMPanel;
55
import com.alibaba.fastjson.JSON;
66
import com.nbs.biz.model.ContactsEntity;
7+
import com.nbs.biz.service.ContactsService;
78
import com.nbs.entity.ContactsItem;
89
import com.nbs.entity.PeerBoradcastInfo;
910
import com.nbs.entity.PeerInfoBase;
@@ -16,14 +17,17 @@
1617
import com.nbs.ui.components.GBC;
1718
import com.nbs.ui.components.NbsListView;
1819
import com.nbs.utils.Base64CodecUtil;
20+
import com.nbs.utils.DbUtil;
1921
import com.nbs.utils.RadomCharactersHelper;
2022
import io.ipfs.api.IPFS;
2123
import io.ipfs.api.JSONParser;
24+
import org.apache.ibatis.session.SqlSession;
2225
import org.slf4j.Logger;
2326
import org.slf4j.LoggerFactory;
2427

2528
import javax.swing.*;
2629
import java.awt.*;
30+
import java.io.IOException;
2731
import java.util.ArrayList;
2832
import java.util.Collections;
2933
import java.util.List;
@@ -43,7 +47,10 @@
4347
public class ContactsPanel extends ParentAvailablePanel {
4448
private Logger logger = LoggerFactory.getLogger(ContactsPanel.class);
4549

46-
50+
/**
51+
*
52+
*/
53+
private ContactsService service;
4754
/**
4855
*
4956
*/
@@ -70,6 +77,7 @@ public class ContactsPanel extends ParentAvailablePanel {
7077
public ContactsPanel(JPanel parent) {
7178
super(parent);
7279
context = this;
80+
service = new ContactsService(DbUtil.getSqlSession());
7381
initComponent();
7482
initView();
7583
initData();
@@ -132,10 +140,10 @@ private void getPeerAvatar(){
132140
* @return
133141
*/
134142
private List<ContactsEntity> getContacts(){
135-
List<ContactsEntity> contacts = new ArrayList<>();
143+
List<ContactsEntity> contacts = service.findAll();
144+
if(contacts==null)contacts = new ArrayList<>();
136145
RadomCharactersHelper charactersHelper = RadomCharactersHelper.getInstance();
137146
String hashPre = "hash.";
138-
139147
if(AppMainWindow.currentPeerInfo()!=null){
140148
PeerInfoBase base = AppMainWindow.currentPeerInfo();
141149
ContactsEntity selfModel = new ContactsEntity(base.getPeerID(),base.getNick());
@@ -144,15 +152,35 @@ private List<ContactsEntity> getContacts(){
144152
contacts.add(selfModel);
145153
}
146154

147-
//虚拟6
155+
IPFS ipfs = IPFSHelper.getInstance().getIpfs();
156+
157+
try {
158+
Object obj = ipfs.pubsub.peers();
159+
if(obj==null)return contacts;
160+
List<String> peers = (List<String>)JSONParser.getValue(obj,"Strings");
161+
if(peers!=null&&peers.size()>0){
162+
for(String peerId : peers){
163+
StringBuilder nickSb = new StringBuilder();
164+
nickSb.append(peerId.substring(0,5)).append("...")
165+
.append(peerId.substring(peerId.length()-4));
166+
ContactsEntity entity = new ContactsEntity(peerId,nickSb.toString());
167+
contacts.add(entity);
168+
}
169+
}
170+
} catch (IOException e) {
171+
e.printStackTrace();
172+
}
173+
174+
175+
/* //虚拟6
148176
int count = 6;
149177
for(int i=0;i<count;i++){
150178
String id = charactersHelper.generated(hashPre,20);
151179
152180
String name = charactersHelper.generated("",6);
153181
ContactsEntity model = new ContactsEntity(name,name);
154182
contacts.add(model);
155-
}
183+
}*/
156184
return contacts;
157185
}
158186

src/main/resources/mybatis/ContactsMapper.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
SELECT * FROM nbs_contacts
2727
</select>
2828

29+
<select id="findAllExcludeId" resultMap="BaseResultMap">
30+
SELECT * FROM nbs_contacts where id != #{id}
31+
</select>
32+
2933
<select id="find" resultMap="BaseResultMap" statementType="STATEMENT" parameterType="map">
3034
SELECT * FROM nbs_contacts where ${field} = ${val}
3135
</select>

src/main/resources/mybatis/TableMapper.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
<update id="createNbsContacts">
1010
create table nbs_contacts (
11-
id integer ,
12-
peerid varchar(64) ,
11+
id varchar(64) PRIMARY KEY,
1312
fromid varchar (64),
1413
nick varchar(100),
1514
avatar varchar(100),

src/test/java/com/nbs/db/test/TableServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public void crateTest(){
5555
public void createNbsContacts(){
5656
TableService service = new TableService(DbUtil.getSqlSession());
5757
service.initNbsContacts();
58-
List<NBSTest> lst = service.getAll();
59-
if(lst!=null){
58+
// List<NBSTest> lst = service.getAll();
59+
/* if(lst!=null){
6060
String json = JSON.toJSONStringWithDateFormat(lst,"yyyy-MM-dd HH:mm:ss");
6161
System.out.println(json);
62-
}
62+
}*/
6363
}
6464

6565
}

0 commit comments

Comments
 (0)