Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dapang liu
Halo
Commits
bee21d7d
Unverified
Commit
bee21d7d
authored
5 years ago
by
Ryan Wang
Committed by
GitHub
5 years ago
Browse files
Options
Download
Email Patches
Plain Diff
refactor: get database version. (#698)
parent
40f510f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/run/halo/app/listener/StartedListener.java
+25
-2
src/main/java/run/halo/app/listener/StartedListener.java
src/main/java/run/halo/app/model/support/HaloConst.java
+4
-7
src/main/java/run/halo/app/model/support/HaloConst.java
src/main/java/run/halo/app/service/impl/AdminServiceImpl.java
+2
-11
...main/java/run/halo/app/service/impl/AdminServiceImpl.java
with
31 additions
and
20 deletions
+31
-20
src/main/java/run/halo/app/listener/StartedListener.java
+
25
-
2
View file @
bee21d7d
...
...
@@ -2,6 +2,7 @@ package run.halo.app.listener;
import
lombok.extern.slf4j.Slf4j
;
import
org.flywaydb.core.Flyway
;
import
org.flywaydb.core.internal.jdbc.JdbcUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.ansi.AnsiColor
;
...
...
@@ -16,6 +17,7 @@ import org.springframework.util.Assert;
import
org.springframework.util.ResourceUtils
;
import
run.halo.app.config.properties.HaloProperties
;
import
run.halo.app.model.properties.PrimaryProperties
;
import
run.halo.app.model.support.HaloConst
;
import
run.halo.app.service.OptionService
;
import
run.halo.app.service.ThemeService
;
import
run.halo.app.utils.FileUtils
;
...
...
@@ -23,6 +25,9 @@ import run.halo.app.utils.FileUtils;
import
java.io.IOException
;
import
java.net.URI
;
import
java.nio.file.*
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.SQLException
;
import
java.util.Collections
;
/**
...
...
@@ -57,7 +62,11 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
@Override
public
void
onApplicationEvent
(
ApplicationStartedEvent
event
)
{
this
.
migrate
();
try
{
this
.
migrate
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
this
.
initThemes
();
this
.
initDirectory
();
this
.
printStartInfo
();
...
...
@@ -77,8 +86,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
/**
* Migrate database.
*/
private
void
migrate
()
{
private
void
migrate
()
throws
SQLException
{
log
.
info
(
"Starting migrate database..."
);
Flyway
flyway
=
Flyway
.
configure
()
.
locations
(
"classpath:/migration"
)
...
...
@@ -88,6 +98,19 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
.
load
();
flyway
.
repair
();
flyway
.
migrate
();
// Gets database connection
Connection
connection
=
flyway
.
getConfiguration
().
getDataSource
().
getConnection
();
// Gets database metadata
DatabaseMetaData
databaseMetaData
=
JdbcUtils
.
getDatabaseMetaData
(
connection
);
// Gets database product name
HaloConst
.
DATABASE_PRODUCT_NAME
=
databaseMetaData
.
getDatabaseProductName
()
+
" "
+
databaseMetaData
.
getDatabaseProductVersion
();
// Close connection.
connection
.
close
();
log
.
info
(
"Migrate database succeed."
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/run/halo/app/model/support/HaloConst.java
+
4
-
7
View file @
bee21d7d
...
...
@@ -54,17 +54,14 @@ public class HaloConst {
* Version constant. (Available in production environment)
*/
public
static
final
String
HALO_VERSION
;
/**
* Path separator.
*/
public
static
final
String
FILE_SEPARATOR
=
File
.
separator
;
/**
* Suffix of freemarker template file
*/
public
static
final
String
SUFFIX_FTL
=
".ftl"
;
/**
* Custom freemarker tag method key.
*/
...
...
@@ -135,12 +132,12 @@ public class HaloConst {
* Content api token param name
*/
public
final
static
String
API_ACCESS_KEY_QUERY_NAME
=
"api_access_key"
;
public
final
static
String
ONE_TIME_TOKEN_QUERY_NAME
=
"ott"
;
public
final
static
String
ONE_TIME_TOKEN_HEADER_NAME
=
"ott"
;
/**
* Database product name.
*/
public
static
String
DATABASE_PRODUCT_NAME
=
null
;
/**
* user_session
*/
...
...
This diff is collapsed.
Click to expand it.
src/main/java/run/halo/app/service/impl/AdminServiceImpl.java
+
2
-
11
View file @
bee21d7d
...
...
@@ -5,7 +5,6 @@ import cn.hutool.core.lang.Validator;
import
cn.hutool.core.util.RandomUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.lang.NonNull
;
...
...
@@ -93,10 +92,6 @@ public class AdminServiceImpl implements AdminService {
private
final
ApplicationEventPublisher
eventPublisher
;
private
final
String
driverClassName
;
private
final
String
mode
;
public
AdminServiceImpl
(
PostService
postService
,
SheetService
sheetService
,
AttachmentService
attachmentService
,
...
...
@@ -110,9 +105,7 @@ public class AdminServiceImpl implements AdminService {
AbstractStringCacheStore
cacheStore
,
RestTemplate
restTemplate
,
HaloProperties
haloProperties
,
ApplicationEventPublisher
eventPublisher
,
@Value
(
"${spring.datasource.driver-class-name}"
)
String
driverClassName
,
@Value
(
"${spring.profiles.active:prod}"
)
String
mode
)
{
ApplicationEventPublisher
eventPublisher
)
{
this
.
postService
=
postService
;
this
.
sheetService
=
sheetService
;
this
.
attachmentService
=
attachmentService
;
...
...
@@ -127,8 +120,6 @@ public class AdminServiceImpl implements AdminService {
this
.
restTemplate
=
restTemplate
;
this
.
haloProperties
=
haloProperties
;
this
.
eventPublisher
=
eventPublisher
;
this
.
driverClassName
=
driverClassName
;
this
.
mode
=
mode
;
}
...
...
@@ -297,7 +288,7 @@ public class AdminServiceImpl implements AdminService {
// Get application start time.
environmentDTO
.
setStartTime
(
ManagementFactory
.
getRuntimeMXBean
().
getStartTime
());
environmentDTO
.
setDatabase
(
"org.h2.Driver"
.
equals
(
driverClassName
)
?
"H2"
:
"MySQL"
);
environmentDTO
.
setDatabase
(
DATABASE_PRODUCT_NAME
);
environmentDTO
.
setVersion
(
HaloConst
.
HALO_VERSION
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help