记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
91b7435a
Commit
91b7435a
authored
Jun 08, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
注释掉mongo事物
parent
f5f0528c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
177 additions
and
2 deletions
+177
-2
.gitignore
.gitignore
+1
-1
TestMongodbHashIndexCreate.java
...quidnet/service/adam/test/TestMongodbHashIndexCreate.java
+62
-0
TestMongodbIndexCreate.java
...m/liquidnet/service/adam/test/TestMongodbIndexCreate.java
+62
-0
TestMongodbIndexCreateExample.java
...dnet/service/adam/test/TestMongodbIndexCreateExample.java
+52
-0
test.php
test.php
+0
-1
No files found.
.gitignore
View file @
91b7435a
...
...
@@ -16,7 +16,7 @@
**/target
# Test
**/test
#
**/test
# Gradle
build
...
...
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/test/java/com/liquidnet/service/adam/test/TestMongodbHashIndexCreate.java
0 → 100644
View file @
91b7435a
package
com
.
liquidnet
.
service
.
adam
.
test
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.client.model.IndexModel
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestMongodbIndexCreate
* @Package com.liquidnet.service.adam.test
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/6/7 17:02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TestMongodbHashIndexCreate
{
@Autowired
private
MongoTemplate
mongoTemplate
;
@Test
public
void
createMongodbIndex
(){
String
[]
collectionNames
=
{
"AdamUserInfoVo"
,
"AdamRealInfoVo"
,
"AdamThirdPartInfoVo"
,
"AdamUserMemberVo"
,
"AdamMemberVo"
};
HashMap
<
String
,
String
[]>
colNameMap
=
new
HashMap
();
colNameMap
.
put
(
"AdamUserInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamRealInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamThirdPartInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamUserMemberVo"
,
new
String
[]{
"uid"
});
colNameMap
.
put
(
"AdamMemberVo"
,
new
String
[]{
"member_id"
});
for
(
String
collectionName:
collectionNames
){
if
(
mongoTemplate
.
collectionExists
(
collectionName
)){
System
.
out
.
printf
(
"执行错误!"
);
return
;
}
for
(
Map
.
Entry
<
String
,
String
[]>
entry:
colNameMap
.
entrySet
())
{
System
.
out
.
print
(
entry
.
getKey
()
+
":"
+
entry
.
getValue
()
+
"\t"
);
if
(
entry
.
getKey
().
equalsIgnoreCase
(
collectionName
)){
//需要创建的索引集合
List
<
IndexModel
>
indexModels
=
new
ArrayList
<>();
String
[]
indexColArray
=
entry
.
getValue
();
for
(
String
indexName:
indexColArray
){
BasicDBObject
index1
=
new
BasicDBObject
();
index1
.
put
(
indexName
,
"hashed"
);
indexModels
.
add
(
new
IndexModel
(
index1
));
}
mongoTemplate
.
createCollection
(
collectionName
).
createIndexes
(
indexModels
);
}
}
}
}
}
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/test/java/com/liquidnet/service/adam/test/TestMongodbIndexCreate.java
0 → 100644
View file @
91b7435a
package
com
.
liquidnet
.
service
.
adam
.
test
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.client.model.IndexModel
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestMongodbIndexCreate
* @Package com.liquidnet.service.adam.test
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/6/7 17:02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TestMongodbIndexCreate
{
@Autowired
private
MongoTemplate
mongoTemplate
;
@Test
public
void
createMongodbIndex
(){
String
[]
collectionNames
=
{
"AdamUserInfoVo"
,
"AdamRealInfoVo"
,
"AdamThirdPartInfoVo"
,
"AdamUserMemberVo"
,
"AdamMemberVo"
};
HashMap
<
String
,
String
[]>
colNameMap
=
new
HashMap
();
colNameMap
.
put
(
"AdamUserInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamRealInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamThirdPartInfoVo"
,
new
String
[]{
"uid"
,
"state"
});
colNameMap
.
put
(
"AdamUserMemberVo"
,
new
String
[]{
"uid"
});
colNameMap
.
put
(
"AdamMemberVo"
,
new
String
[]{
"member_id"
});
for
(
String
collectionName:
collectionNames
){
if
(
mongoTemplate
.
collectionExists
(
collectionName
)){
System
.
out
.
printf
(
"执行错误!"
);
return
;
}
for
(
Map
.
Entry
<
String
,
String
[]>
entry:
colNameMap
.
entrySet
())
{
System
.
out
.
print
(
entry
.
getKey
()
+
":"
+
entry
.
getValue
()
+
"\t"
);
if
(
entry
.
getKey
().
equalsIgnoreCase
(
collectionName
)){
//需要创建的索引集合
List
<
IndexModel
>
indexModels
=
new
ArrayList
<>();
String
[]
indexColArray
=
entry
.
getValue
();
for
(
String
indexName:
indexColArray
){
BasicDBObject
index1
=
new
BasicDBObject
();
index1
.
put
(
indexName
,
1
);
indexModels
.
add
(
new
IndexModel
(
index1
));
}
mongoTemplate
.
createCollection
(
collectionName
).
createIndexes
(
indexModels
);
}
}
}
}
}
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/test/java/com/liquidnet/service/adam/test/TestMongodbIndexCreateExample.java
0 → 100644
View file @
91b7435a
package
com
.
liquidnet
.
service
.
adam
.
test
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.client.model.IndexModel
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestMongodbIndexCreate
* @Package com.liquidnet.service.adam.test
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/6/7 17:02
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TestMongodbIndexCreateExample
{
@Autowired
private
MongoTemplate
mongoTemplate
;
@Test
public
void
createMongodbIndex
(){
String
[]
collectionNames
=
{
"test-mongo"
};
// String[] collectionNames = {"AdamUserInfoVo","AdamRealInfoVo","AdamThirdPartInfoVo","AdamUserMemberVo","AdamMemberVo"};
for
(
String
collectionName:
collectionNames
){
if
(
mongoTemplate
.
collectionExists
(
collectionName
)){
System
.
out
.
printf
(
"执行错误!"
);
return
;
}
//需要创建的索引集合
List
<
IndexModel
>
indexModels
=
new
ArrayList
<>();
BasicDBObject
index1
=
new
BasicDBObject
();
index1
.
put
(
"name"
,
1
);
indexModels
.
add
(
new
IndexModel
(
index1
));
BasicDBObject
index2
=
new
BasicDBObject
();
index2
.
put
(
"name"
,
1
);
index2
.
put
(
"age"
,
1
);
indexModels
.
add
(
new
IndexModel
((
index2
)));
mongoTemplate
.
createCollection
(
collectionName
).
createIndexes
(
indexModels
);
}
}
}
test.php
deleted
100644 → 0
View file @
f5f0528c
<?php
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment