-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11fa481
commit 767a3ec
Showing
17 changed files
with
155 additions
and
33 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 46 additions & 1 deletion
47
src/main/java/com/teamsixnus/scaleup/config/DatabaseConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
package com.teamsixnus.scaleup.config; | ||
|
||
import java.sql.SQLException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import tech.jhipster.config.JHipsterConstants; | ||
import tech.jhipster.config.h2.H2ConfigurationHelper; | ||
|
||
@Configuration | ||
@EnableJpaRepositories({ "com.teamsixnus.scaleup.repository" }) | ||
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware") | ||
@EnableTransactionManagement | ||
public class DatabaseConfiguration {} | ||
public class DatabaseConfiguration { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class); | ||
|
||
private final Environment env; | ||
|
||
public DatabaseConfiguration(Environment env) { | ||
this.env = env; | ||
} | ||
|
||
/** | ||
* Open the TCP port for the H2 database, so it is available remotely. | ||
* | ||
* @return the H2 database TCP server. | ||
* @throws SQLException if the server failed to start. | ||
*/ | ||
@Bean(initMethod = "start", destroyMethod = "stop") | ||
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) | ||
public Object h2TCPServer() throws SQLException { | ||
String port = getValidPortForH2(); | ||
log.debug("H2 database is available on port {}", port); | ||
return H2ConfigurationHelper.createServer(port); | ||
} | ||
|
||
private String getValidPortForH2() { | ||
int port = Integer.parseInt(env.getProperty("server.port")); | ||
if (port < 10000) { | ||
port = 10000 + port; | ||
} else { | ||
if (port < 63536) { | ||
port = port + 2000; | ||
} else { | ||
port = port - 2000; | ||
} | ||
} | ||
return String.valueOf(port); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#H2 Server Properties | ||
#Wed Aug 14 23:11:21 SGT 2024 | ||
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/scaleup|scaleup | ||
webAllowOthers=true | ||
webPort=8092 | ||
webSSL=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.