Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
renren-generator
Overview
Overview
Details
Activity
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
吴迪
renren-generator
Commits
eb6f167c
Commit
eb6f167c
authored
May 10, 2020
by
gxz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了一些格式的内容
parent
ac23435e
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
40 additions
and
39 deletions
+40
-39
MongoTableInfoAdaptor.java
src/main/java/io/renren/adaptor/MongoTableInfoAdaptor.java
+2
-2
DbConfig.java
src/main/java/io/renren/config/DbConfig.java
+12
-11
MongoConfig.java
src/main/java/io/renren/config/MongoConfig.java
+2
-2
MongoDBGeneratorDao.java
src/main/java/io/renren/dao/MongoDBGeneratorDao.java
+3
-3
MongoDefinition.java
src/main/java/io/renren/entity/mongo/MongoDefinition.java
+6
-6
MongoGeneratorEntity.java
...ain/java/io/renren/entity/mongo/MongoGeneratorEntity.java
+4
-3
Type.java
src/main/java/io/renren/entity/mongo/Type.java
+3
-2
SysGeneratorService.java
src/main/java/io/renren/service/SysGeneratorService.java
+5
-7
GenUtils.java
src/main/java/io/renren/utils/GenUtils.java
+3
-3
No files found.
src/main/java/io/renren/adaptor/MongoTableInfoAdaptor.java
View file @
eb6f167c
...
...
@@ -27,6 +27,7 @@ public class MongoTableInfoAdaptor {
}
return
result
;
}
public
static
Map
<
String
,
String
>
tableInfo
(
String
name
)
{
Map
<
String
,
String
>
tableInfo
=
new
HashMap
<>(
4
*
4
/
3
+
1
);
tableInfo
.
put
(
"engine"
,
"mongo无引擎"
);
...
...
@@ -51,7 +52,7 @@ public class MongoTableInfoAdaptor {
String
extra
=
definition
.
isArray
()
?
"array"
:
""
;
map
.
put
(
"extra"
,
extra
);
map
.
put
(
"columnComment"
,
""
);
map
.
put
(
"dataType"
,
definition
.
hasChild
()
?
propertyName:
type
);
map
.
put
(
"dataType"
,
definition
.
hasChild
()
?
propertyName
:
type
);
map
.
put
(
"columnName"
,
propertyName
);
// mongo默认主键是_id
String
columnKey
=
propertyName
.
equals
(
mongoKey
)
?
"PRI"
:
""
;
...
...
@@ -62,5 +63,4 @@ public class MongoTableInfoAdaptor {
}
}
src/main/java/io/renren/config/DbConfig.java
View file @
eb6f167c
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
*
<p>
* https://www.renren.io
*
*
<p>
* 版权所有,侵权必究!
*/
...
...
@@ -37,26 +37,27 @@ public class DbConfig {
private
MongoDBGeneratorDao
mongoDBGeneratorDao
;
private
static
boolean
mongo
=
false
;
@Bean
@Primary
public
GeneratorDao
getGeneratorDao
(){
if
(
"mysql"
.
equalsIgnoreCase
(
database
))
{
public
GeneratorDao
getGeneratorDao
()
{
if
(
"mysql"
.
equalsIgnoreCase
(
database
))
{
return
mySQLGeneratorDao
;
}
else
if
(
"oracle"
.
equalsIgnoreCase
(
database
))
{
}
else
if
(
"oracle"
.
equalsIgnoreCase
(
database
))
{
return
oracleGeneratorDao
;
}
else
if
(
"sqlserver"
.
equalsIgnoreCase
(
database
))
{
}
else
if
(
"sqlserver"
.
equalsIgnoreCase
(
database
))
{
return
sqlServerGeneratorDao
;
}
else
if
(
"postgresql"
.
equalsIgnoreCase
(
database
))
{
}
else
if
(
"postgresql"
.
equalsIgnoreCase
(
database
))
{
return
postgreSQLGeneratorDao
;
}
else
if
(
"mongodb"
.
equalsIgnoreCase
(
database
))
{
}
else
if
(
"mongodb"
.
equalsIgnoreCase
(
database
))
{
mongo
=
true
;
return
mongoDBGeneratorDao
;
}
else
{
}
else
{
throw
new
RRException
(
"不支持当前数据库:"
+
database
);
}
}
public
static
boolean
isMongo
(){
public
static
boolean
isMongo
()
{
return
mongo
;
}
...
...
src/main/java/io/renren/config/MongoConfig.java
View file @
eb6f167c
...
...
@@ -35,8 +35,8 @@ public class MongoConfig {
ServerAddress
serverAddress
=
new
ServerAddress
(
this
.
host
,
this
.
port
);
adds
.
add
(
serverAddress
);
if
(
this
.
auth
)
{
MongoCredential
mongoCredential
=
MongoCredential
.
createScramSha1Credential
(
this
.
username
,
this
.
source
,
this
.
password
.
toCharArray
());
MongoCredential
mongoCredential
=
MongoCredential
.
createScramSha1Credential
(
this
.
username
,
this
.
source
,
this
.
password
.
toCharArray
());
MongoClientOptions
mongoClientOptions
=
MongoClientOptions
.
builder
().
build
();
return
new
MongoClient
(
adds
,
mongoCredential
,
mongoClientOptions
);
}
...
...
src/main/java/io/renren/dao/MongoDBGeneratorDao.java
View file @
eb6f167c
...
...
@@ -29,10 +29,10 @@ public class MongoDBGeneratorDao implements GeneratorDao {
@Override
public
Map
<
String
,
String
>
queryTable
(
String
tableName
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<>(
4
*
4
/
3
+
1
);
Map
<
String
,
String
>
result
=
new
HashMap
<>(
4
*
4
/
3
+
1
);
result
.
put
(
"engine"
,
""
);
result
.
put
(
"createTime"
,
""
);
result
.
put
(
"tableComment"
,
"mongoDB "
+
tableName
);
result
.
put
(
"tableComment"
,
"mongoDB "
+
tableName
);
result
.
put
(
"tableName"
,
tableName
);
return
result
;
...
...
@@ -41,7 +41,7 @@ public class MongoDBGeneratorDao implements GeneratorDao {
@Override
public
List
<
Map
<
String
,
String
>>
queryColumns
(
String
tableName
)
{
MongoDefinition
mongoDefinition
=
MongoManager
.
getInfo
(
tableName
);
if
(
mongoDefinition
==
null
)
{
if
(
mongoDefinition
==
null
)
{
System
.
out
.
println
(
tableName
);
MongoScanner
mongoScanner
=
new
MongoScanner
(
mongoDBCollectionFactory
.
getCollection
(
tableName
));
mongoDefinition
=
mongoScanner
.
getProduct
();
...
...
src/main/java/io/renren/entity/mongo/MongoDefinition.java
View file @
eb6f167c
...
...
@@ -6,6 +6,7 @@ import org.apache.commons.collections.CollectionUtils;
import
java.io.Serializable
;
import
java.util.*
;
/**
* 解析表之后得到的信息实体
* 换句话说这个类就是一张mongo一张表的内容
...
...
@@ -24,7 +25,7 @@ public class MongoDefinition implements Serializable {
private
List
<
MongoDefinition
>
child
;
public
List
<
MongoGeneratorEntity
>
getChildrenInfo
(
String
tableName
){
public
List
<
MongoGeneratorEntity
>
getChildrenInfo
(
String
tableName
)
{
List
<
MongoGeneratorEntity
>
result
=
new
ArrayList
<>();
MongoGeneratorEntity
info
=
new
MongoGeneratorEntity
();
// 表信息
...
...
@@ -37,11 +38,11 @@ public class MongoDefinition implements Serializable {
List
<
MongoDefinition
>
child
=
this
.
getChild
();
for
(
MongoDefinition
mongoDefinition
:
child
)
{
Map
<
String
,
String
>
columnInfo
=
new
HashMap
<>(
5
);
columnInfo
.
put
(
"columnName"
,
mongoDefinition
.
getPropertyName
());
columnInfo
.
put
(
"dataType"
,
Type
.
typeInfo
(
mongoDefinition
.
getType
()));
columnInfo
.
put
(
"extra"
,
mongoDefinition
.
isArray
()?
"array"
:
""
);
columnInfo
.
put
(
"columnName"
,
mongoDefinition
.
getPropertyName
());
columnInfo
.
put
(
"dataType"
,
Type
.
typeInfo
(
mongoDefinition
.
getType
()));
columnInfo
.
put
(
"extra"
,
mongoDefinition
.
isArray
()
?
"array"
:
""
);
columnsInfo
.
add
(
columnInfo
);
if
(
mongoDefinition
.
hasChild
())
{
if
(
mongoDefinition
.
hasChild
())
{
result
.
addAll
(
mongoDefinition
.
getChildrenInfo
(
mongoDefinition
.
getPropertyName
()));
}
}
...
...
@@ -59,7 +60,6 @@ public class MongoDefinition implements Serializable {
}
public
MongoDefinition
setType
(
Integer
type
)
{
this
.
type
=
type
;
return
this
;
...
...
src/main/java/io/renren/entity/mongo/MongoGeneratorEntity.java
View file @
eb6f167c
...
...
@@ -6,8 +6,10 @@ import io.renren.entity.TableEntity;
import
java.util.List
;
import
java.util.Map
;
/** mysql一张表只需要一个表信息和列名信息
/**
* mysql一张表只需要一个表信息和列名信息
* 但是mongo一张表可能需要多个实体类 所以单独用一个bean封装
*
* @author gxz
* @date 2020/5/10 0:14
*/
...
...
@@ -18,8 +20,7 @@ public class MongoGeneratorEntity {
private
List
<
Map
<
String
,
String
>>
columns
;
public
TableEntity
toTableEntity
(){
public
TableEntity
toTableEntity
()
{
TableEntity
tableEntity
=
new
TableEntity
();
Map
<
String
,
String
>
tableInfo
=
this
.
tableInfo
;
tableEntity
.
setTableName
(
tableInfo
.
get
(
"tableName"
));
...
...
src/main/java/io/renren/entity/mongo/Type.java
View file @
eb6f167c
...
...
@@ -17,14 +17,15 @@ public enum Type {
DOUBLE
(
1
);
private
final
int
num
;
Type
(
int
num
)
{
this
.
num
=
num
;
}
public
static
String
typeInfo
(
int
num
){
public
static
String
typeInfo
(
int
num
)
{
Type
[]
values
=
values
();
for
(
Type
value
:
values
)
{
if
(
Objects
.
equals
(
num
,
value
.
num
))
{
if
(
Objects
.
equals
(
num
,
value
.
num
))
{
return
value
.
toString
();
}
}
...
...
src/main/java/io/renren/service/SysGeneratorService.java
View file @
eb6f167c
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
*
<p>
* https://www.renren.io
*
*
<p>
* 版权所有,侵权必究!
*/
...
...
@@ -43,7 +43,7 @@ public class SysGeneratorService {
Page
<?>
page
=
PageHelper
.
startPage
(
query
.
getPage
(),
query
.
getLimit
());
List
<
Map
<
String
,
Object
>>
list
=
generatorDao
.
queryList
(
query
);
int
total
=
(
int
)
page
.
getTotal
();
if
(
generatorDao
instanceof
MongoDBGeneratorDao
)
{
if
(
generatorDao
instanceof
MongoDBGeneratorDao
)
{
total
=
mongoDBCollectionFactory
.
getCollectionTotal
(
query
);
}
return
new
PageUtils
(
list
,
total
,
query
.
getLimit
(),
query
.
getPage
());
...
...
@@ -58,11 +58,10 @@ public class SysGeneratorService {
}
public
byte
[]
generatorCode
(
String
[]
tableNames
)
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ZipOutputStream
zip
=
new
ZipOutputStream
(
outputStream
);
for
(
String
tableName
:
tableNames
)
{
for
(
String
tableName
:
tableNames
)
{
//查询表信息
Map
<
String
,
String
>
table
=
queryTable
(
tableName
);
//查询列信息
...
...
@@ -70,12 +69,11 @@ public class SysGeneratorService {
//生成代码
GenUtils
.
generatorCode
(
table
,
columns
,
zip
);
}
if
(
MongoManager
.
isMongo
())
{
if
(
MongoManager
.
isMongo
())
{
GenUtils
.
generatorMongoCode
(
tableNames
,
zip
);
}
IOUtils
.
closeQuietly
(
zip
);
return
outputStream
.
toByteArray
();
}
...
...
src/main/java/io/renren/utils/GenUtils.java
View file @
eb6f167c
...
...
@@ -195,8 +195,8 @@ public class GenUtils {
for
(
Map
<
String
,
String
>
column
:
mongoGeneratorEntity
.
getColumns
())
{
ColumnEntity
columnEntity
=
new
ColumnEntity
();
String
columnName
=
column
.
get
(
"columnName"
);
if
(
columnName
.
contains
(
"."
))
{
columnName
=
columnName
.
substring
(
columnName
.
lastIndexOf
(
"."
)
+
1
);
if
(
columnName
.
contains
(
"."
))
{
columnName
=
columnName
.
substring
(
columnName
.
lastIndexOf
(
"."
)
+
1
);
}
columnEntity
.
setColumnName
(
columnName
);
columnEntity
.
setDataType
(
column
.
get
(
"dataType"
));
...
...
@@ -301,7 +301,7 @@ public class GenUtils {
packagePath
+=
packageName
.
replace
(
"."
,
File
.
separator
)
+
File
.
separator
+
moduleName
+
File
.
separator
;
}
if
(
template
.
contains
(
"MongoChildrenEntity.java.vm"
))
{
return
packagePath
+
"entity"
+
File
.
separator
+
"inner"
+
File
.
separator
+
currentTableName
+
File
.
separator
+
className
+
"InnerEntity.java"
;
return
packagePath
+
"entity"
+
File
.
separator
+
"inner"
+
File
.
separator
+
currentTableName
+
File
.
separator
+
className
+
"InnerEntity.java"
;
}
if
(
template
.
contains
(
"Entity.java.vm"
)
||
template
.
contains
(
"MongoEntity.java.vm"
))
{
return
packagePath
+
"entity"
+
File
.
separator
+
className
+
"Entity.java"
;
...
...
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