【删除】不要的文件

This commit is contained in:
wxd-gaming
2024-08-05 20:44:36 +08:00
parent de11ad2d68
commit 111dff76f8
47 changed files with 0 additions and 14147 deletions

8
MariaDBServer/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="MariaDBServer" />
<module name="mysql-test" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="test@localhost" uuid="5f4c9ef3-ad8e-49ed-852c-c19f44d58a55">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3308/test</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="GBK">
<file url="file://$PROJECT_DIR$/src/main/java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/java/example/db/DBFactory.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/java/example/db/GraalvmMain.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/java/example/db/GraalvmUtil.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/java/example/db/Main.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/java/example/db/MyDB.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="GBK" />
<file url="file://$PROJECT_DIR$/../../../test/mysql-test/src/main/java" charset="GBK" />
<file url="file://$PROJECT_DIR$/../../../test/mysql-test/src/main/resources" charset="GBK" />
<file url="PROJECT" charset="GBK" />
</component>
</project>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="central" />
<option name="url" value="https://maven.aliyun.com/repository/central" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="aliyun maven" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="public" />
<option name="name" value="public" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="inner-release" />
<option name="name" value="inner-release" />
<option name="url" value="http://122.224.130.106:19081/nexus/content/repositories/releases/" />
</remote-repository>
</component>
</project>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/../../../test/mysql-test/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="graalvm-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,124 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../../../test/mysql-test" vcs="Git" />
</component>
</project>

View File

@@ -1 +0,0 @@
{"PID":31192, "states":0}

View File

@@ -1,2 +0,0 @@
@echo off
graalvm-win\exec\mysql-server

View File

@@ -1,45 +0,0 @@
@echo off
set option=-H:+UnlockExperimentalVMOptions
set option=%option% -H:+ReportExceptionStackTraces
set option=%option% -H:-ParseRuntimeOptions
set option=%option% -H:+AddAllCharsets
set option=%option% -H:ConfigurationFileDirectories=graalvm-win\\native-image\\config
set option=%option% --enable-http
set option=%option% --enable-https
set option=%option% --no-fallback
set option=%option% --report-unsupported-elements-at-runtime
set option=%option% --allow-incomplete-classpath
@REM set option=%option% --link-at-build-time
set option=%option% --initialize-at-build-time=com.sh
:: build-time
set option=%option% --initialize-at-run-time=com.sh
::<!--新增-->
::<!--trace 表示编译时 进行 跟踪有些情况下可能会报错比如在这里设置了A类但是A类没有MAIN方法 会导致报错-->
set option=%option% --trace-class-initialization=com.sun.beans.introspect.ClassInfo
set option=%option% --trace-class-initialization=com.sun.beans.introspect.MethodInfo
set option=%option% --trace-class-initialization=com.sun.beans.TypeResolver
set option=%option% --trace-class-initialization=java.beans.Introspector
set option=%option% --trace-class-initialization=java.beans.ThreadGroupContext
set option=%option% --trace-class-initialization=com.sh
set option=%option% --trace-object-instantiation=java.util.jar.JarFile
set option=%option% --add-exports=java.base/java.nio=ALL-UNNAMED
set option=%option% --add-opens java.base/java.nio=ALL-UNNAMED
set option=%option% -Dfile.encoding=GBK
set option=%option% -Dio.netty.tryReflectionSetAccessible=true
echo %option%
md graalvm-win\\exec
C:\\java\\graalvm-jdk-21.0.3+7.1\\bin\\native-image %option% -cp "target/mysql-server.jar;target/lib/*" -jar target\mysql-server.jar graalvm-win\exec\mysql-server

View File

@@ -1,2 +0,0 @@
@echo off
C:\\java\\graalvm-jdk-21.0.3+7.1\\bin\\java -agentlib:native-image-agent=config-merge-dir=graalvm-win\\native-image\\config -cp "target/mysql-server.jar;target/lib/*" example.db.GraalvmMain

View File

@@ -1,14 +0,0 @@
@echo off
:: 设置Java环境变量
set JAVA_HOME=C:\java\graalvm-jdk-21.0.3+7.1
set PATH=%JAVA_HOME%\bin;%PATH%
:: 检查JAVA_HOME是否配置成功
echo %JAVA_HOME%
echo %PATH%
:: 打印Java版本信息确认配置成功
java -version
D:\\apache-maven-3.3.9\\bin\\mvn clean compile test -Dtest=action.NativeClassActionTest#f1 -DfailIfNoTests=false package -f pom.xml

View File

@@ -1,10 +0,0 @@
[
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
},
{
"name":"sun.management.VMManagementImpl",
"fields":[{"name":"compTimeMonitoringSupport"}, {"name":"currentThreadCpuTimeSupport"}, {"name":"objectMonitorUsageSupport"}, {"name":"otherThreadCpuTimeSupport"}, {"name":"remoteDiagnosticCommandsSupport"}, {"name":"synchronizerUsageSupport"}, {"name":"threadAllocatedMemorySupport"}, {"name":"threadContentionMonitoringSupport"}]
}
]

View File

@@ -1,8 +0,0 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

View File

@@ -1,35 +0,0 @@
[
{
"name":"[Lorg.springframework.util.ConcurrentReferenceHashMap$Segment;"
},
{
"name":"java.lang.Thread",
"fields":[{"name":"threadLocalRandomProbe"}]
},
{
"name":"java.util.concurrent.ForkJoinTask",
"fields":[{"name":"aux"}, {"name":"status"}]
},
{
"name":"java.util.concurrent.atomic.Striped64",
"fields":[{"name":"base"}, {"name":"cellsBusy"}]
},
{
"name":"jdk.internal.misc.Unsafe"
},
{
"name":"org.apache.logging.log4j.spi.ExtendedLogger"
},
{
"name":"org.apache.logging.slf4j.SLF4JProvider"
},
{
"name":"org.eclipse.core.runtime.FileLocator"
},
{
"name":"org.slf4j.Logger"
},
{
"name":"org.slf4j.spi.LocationAwareLogger"
}
]

View File

@@ -1,8 +0,0 @@
{
"types":[
],
"lambdaCapturingTypes":[
],
"proxies":[
]
}

View File

@@ -1,4 +0,0 @@
@echo off
call graalvm-win\graalvm-package.bat
call graalvm-win\graalvm-package-server.bat
call graalvm-win\graalvm-image.bat

View File

@@ -1,7 +0,0 @@
port=3308
user=root
pwd=root
#需要多个数据库 用 ,分割 例如test,test2,test3
database=test,test2
#备份分钟数0是不备份1小时备份一次是60
bak=1

View File

@@ -1,156 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example.db</groupId>
<artifactId>MariaDBServer</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<encoding>GBK</encoding>
<java.version>21</java.version>
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
<maven.compiler.encoding>${encoding}</maven.compiler.encoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.compilerVersion>${java.version}</maven.compiler.compilerVersion>
</properties>
<repositories>
<repository>
<id>public</id>
<url>https://maven.aliyun.com/repository/public</url>
<!-- <url>https://repo1.maven.org/maven2/</url>-->
</repository>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/central</url>
<!-- <url>https://repo1.maven.org/maven2/</url>-->
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>public</name>
<url>https://maven.aliyun.com/repository/public</url>
</pluginRepository>
<pluginRepository>
<id>central</id>
<name>central</name>
<url>https://maven.aliyun.com/repository/central</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.4.1</version>
</dependency>
</dependencies>
<build>
<finalName>mysql-server</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>example.db.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- <copy todir="${project.build.directory}/lib" overwrite="true">
<fileset dir="${basedir}/../libs" erroronmissingdir="false">
<include name="*.jar"/>
</fileset>
</copy>-->
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,99 +0,0 @@
package example.db;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Properties;
/**
* 数据库工厂
*
* @author: Troy.Chen(無心道, 15388152619)
* @version: 2024-07-23 16:45
**/
public class DBFactory {
private static final DBFactory ins = new DBFactory();
public static final File ok = new File("db-ok.txt");
public static DBFactory getIns() {
return ins;
}
DBFactory() {}
private DBConfigurationBuilder configBuilder;
private MyDB myDB;
public void init() throws Exception {
Properties props = new Properties();
props.load(Files.newInputStream(Paths.get("my.ini")));
configBuilder = DBConfigurationBuilder.newBuilder();
configBuilder.setPort(Integer.parseInt(props.getProperty("port"))); // OR, default: setPort(0); => autom. detect free port
configBuilder.setBaseDir("data-base/"); // just an example
configBuilder.setDataDir("data-base/data");
myDB = new MyDB(props, configBuilder.build());
myDB.start();
write(1);
}
public static void write(int state) throws IOException {
String json = "{\"PID\":" + fetchProcessId() + ", \"states\":" + state + "}";
Files.write(
ok.toPath(),
json.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
);
}
public DBConfigurationBuilder getConfigBuilder() {
return configBuilder;
}
public MyDB getMyDB() {
return myDB;
}
public void stop() {
System.out.println("addShutdownHook");
try {
write(0);
} catch (Exception ignore) {}
try {
getMyDB().stop();
} catch (Throwable e) {
System.out.println("关闭服务 " + e);
}
for (int i = 3; i > 0; i--) {
System.out.println("exit " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
Runtime.getRuntime().halt(0);
}
public static String fetchProcessId() {
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName();
return name.substring(0, name.indexOf("@"));
} catch (Exception ignore) {
return "-1";
}
}
}

View File

@@ -1,31 +0,0 @@
package example.db;
import java.net.URL;
import java.util.List;
public class GraalvmMain {
public static void main(String[] args) throws Exception {
DBFactory.getIns().init();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
List<String> strings = GraalvmUtil.jarResources();
for (String string : strings) {
URL resource = contextClassLoader.getResource(string);
System.out.println(string + " - " + resource);
}
System.out.println("====================================================");
System.out.println("");
System.out.println("数据库服务器启动完成 - " + "127.0.0.1:" + DBFactory.getIns().getMyDB().props.getProperty("port") + "/" + DBFactory.getIns().getMyDB().props.getProperty("database"));
System.out.println("敲回车键可以关闭服务");
System.out.println("");
System.out.println("====================================================");
Thread addShutdownHook = new Thread(() -> {
DBFactory.getIns().stop();
});
Thread.sleep(30_000);
addShutdownHook.run();
Runtime.getRuntime().halt(0);
}
}

View File

@@ -1,110 +0,0 @@
package example.db;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class GraalvmUtil {
/** ?????????? <br>?????????????????????У?<br>??????????config????<br>???????в???jar??????? TODO ???????????е??·????? */
public static Stream<Tuple<String, InputStream>> resourceStreams(final String path) {
return resourceStreams(Thread.currentThread().getContextClassLoader(), path);
}
/** ?????????? <br>?????????????????????У?<br>??????????config????<br>???????в???jar??????? TODO ???????????е??·????? */
public static Stream<Tuple<String, InputStream>> resourceStreams(ClassLoader classLoader, final String path) {
try {
String findPath = path;
boolean fileExists = new File(path).exists();
if (!fileExists) {/*?????????????????????????*/
URL resource = classLoader.getResource(path);
if (resource != null) {
findPath = URLDecoder.decode(resource.getPath(), StandardCharsets.UTF_8.toString());
if (findPath.startsWith("/")) {
findPath = findPath.substring(1);
}
if (findPath.contains(".zip!") || findPath.contains(".jar!")) {
findPath = findPath.substring(5, findPath.indexOf("!/"));
try (FileInputStream fileInputStream = new FileInputStream(findPath);
ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);) {
List<Tuple<String, InputStream>> tmps = new ArrayList<>();
ZipEntry nextEntry = null;
while ((nextEntry = zipInputStream.getNextEntry()) != null) {
if (nextEntry.isDirectory()) continue;
String name = nextEntry.getName();
String replace = name.replace("\\", "/");
if (replace.startsWith(path)) {
/* todo ??????????????????????? */
byte[] extra = new byte[(int) nextEntry.getSize()];
zipInputStream.read(extra, 0, (int) nextEntry.getSize());
tmps.add(new Tuple<>(nextEntry.getName(), new ByteArrayInputStream(extra)));
}
}
return tmps.stream();
}
}
}
}
return Files.walk(Paths.get(findPath), 999)
.map(Path::toFile)
.filter(File::isFile)
.map(file -> {
try {
return new Tuple<>(file.getPath(), Files.newInputStream(file.toPath()));
} catch (Exception e) {
throw new RuntimeException("resources:" + file, e);
}
});
} catch (Exception e) {
throw new RuntimeException("resources:" + path, e);
}
}
public static String javaClassPath() {
return System.getProperty("java.class.path");
}
public static List<String> jarResources() throws Exception {
List<String> resourcesPath = new ArrayList<>();
String x = javaClassPath();
String[] split = x.split(File.pathSeparator);
for (String string : split) {
if (!string.endsWith(".jar")) continue;
try (InputStream inputStream = Files.newInputStream(Paths.get(string));
ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
ZipEntry nextEntry = null;
while ((nextEntry = zipInputStream.getNextEntry()) != null) {
/* todo ??????????????????????? */
resourcesPath.add(nextEntry.getName());
}
}
}
return resourcesPath;
}
public static class Tuple<F, S> {
public final F f;
public final S s;
public Tuple(F f, S s) {
this.f = f;
this.s = s;
}
}
}

View File

@@ -1,55 +0,0 @@
package example.db;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static Logger log = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws Exception {
log.info("s");
DBFactory.getIns().init();
WebService.getIns().start();
System.out.println("====================================================");
System.out.println("");
System.out.println("数据库服务器启动完成 - " + "127.0.0.1:" + DBFactory.getIns().getMyDB().props.getProperty("port") + "/" + DBFactory.getIns().getMyDB().props.getProperty("database"));
System.out.println("敲回车键可以关闭服务");
System.out.println("");
System.out.println("====================================================");
Thread thread = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
System.out.println("敲回车,等待程序退出");
try {
Thread.sleep(10_000);
} catch (InterruptedException e) {
break;
}
}
});
thread.start();
Thread hook = new Thread(() -> {
DBFactory.getIns().stop();
});
Runtime.getRuntime().addShutdownHook(hook);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
try {
thread.interrupt();
thread.join();
} catch (Exception ignore) {}
hook.run();
}
}

View File

@@ -1,126 +0,0 @@
package example.db;
import ch.vorburger.exec.ManagedProcess;
import ch.vorburger.exec.ManagedProcessException;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfiguration;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
public class MyDB extends DB {
final Properties props;
final Timer timer = new Timer();
public MyDB(Properties props, DBConfiguration config) {
super(config);
this.props = props;
try {
this.prepareDirectories();
} catch (Exception e) {
if (!check(e))
e.printStackTrace(System.err);
}
try {
this.unpackEmbeddedDb();
} catch (Exception ignore) {}
try {
this.install();
} catch (Exception e) {
if (!check(e))
e.printStackTrace(System.err);
}
}
private boolean check(Throwable e) {
if (e != null) {
if (e.getMessage().contains("is not empty. Only new or empty existing directories are accepted for --datadir"))
return true;
if (e.getCause() != null && check(e.getCause())) {
return true;
}
}
return false;
}
public void initDb() {
try {
String database = props.getProperty("database");
String[] split = database.split(",|");
for (String dbName : split) {
createDB(dbName, props.getProperty("user"), props.getProperty("pwd"));
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
int bak_Time = Integer.parseInt(props.getProperty("bak"));
initBakTimer(bak_Time);
}
public void initBakTimer(int bak_Time) {
if (bak_Time > 0) {
timer.scheduleAtFixedRate(
new TimerTask() {
@Override public void run() {
bakSql();
}
},
TimeUnit.MINUTES.toMillis(bak_Time),
TimeUnit.MINUTES.toMillis(bak_Time)
);
}
}
public void bakSql() {
try {
String format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS").format(new Date());
String database = props.getProperty("database");
String[] split = database.split(",|");
for (String dbName : split) {
File outputFile = new File("data-base/bak/" + dbName + "/" + format + ".sql");
outputFile.getParentFile().mkdirs();
ManagedProcess managedProcess = dumpSQL(
outputFile,
dbName,
props.getProperty("user"),
props.getProperty("pwd")
);
try {
managedProcess.start();
managedProcess.waitForExit();
} catch (Exception ignore) {
}
try {
managedProcess.destroy();
} catch (Exception ignore) {}
System.out.println("备份:" + outputFile);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
@Override public synchronized void start() throws ManagedProcessException {
super.start();
initDb();
}
@Override public synchronized void stop() throws ManagedProcessException {
timer.cancel();
timer.purge();
/*备份可能会卡住*/
// bakSql();
super.stop();
}
}

View File

@@ -1,49 +0,0 @@
package example.db;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
/**
* @author: Troy.Chen(ŸoÐĵÀ, 15388152619)
* @version: 2024-07-29 16:46
**/
public class WebService {
private static final WebService ins = new WebService();
public static WebService getIns() {
return ins;
}
WebService() {
}
HttpServer httpServer;
public void start() throws Exception {
httpServer = HttpServer.create(new InetSocketAddress(19902), 0);
httpServer.createContext("/api/db/stop", new HttpHandler() {
@Override public void handle(HttpExchange exchange) throws IOException {
byte[] bytes = "ok".getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, bytes.length);
exchange.getResponseBody().write(bytes);
exchange.getResponseBody().flush();
exchange.close();
DBFactory.getIns().stop();
}
});
httpServer.start();
System.out.println("http://localhost:19902/api/db/stop");
}
}

View File

@@ -1,5 +0,0 @@
# Example for properties file
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=DEBUG
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

View File

@@ -1,44 +0,0 @@
package code;
import example.db.DBFactory;
import org.mariadb.jdbc.MariaDbDataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class DbTest {
public static void main(String[] args) throws Exception {
DBFactory.getIns().init();
// 获取数据源
MariaDbDataSource dataSource = new MariaDbDataSource(DBFactory.getIns().getConfigBuilder().getURL("test"));
dataSource.setUser("root");
dataSource.setPassword("root");
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
String sql = "CREATE TABLE if not exists employees (id INT PRIMARY KEY, name VARCHAR(255))";
stmt.executeUpdate(sql);
int cur = (int) (System.currentTimeMillis() / 1000);
sql = "INSERT INTO employees (id, name) VALUES (" + cur + ", 'John')";
stmt.executeUpdate(sql);
System.out.println("Created table and inserted row!");
// 查询向数据库中插入的数据
ResultSet rs = stmt.executeQuery("SELECT * FROM employees");
// 打印查询结果
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
System.out.println(id + ", " + name);
}
}
}

View File

@@ -1,19 +0,0 @@
package code;
import example.db.GraalvmUtil;
import java.net.URL;
import java.util.List;
public class Test2 {
public static void main(String[] args) throws Exception {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
List<String> strings = GraalvmUtil.jarResources();
for (String string : strings) {
URL resource = contextClassLoader.getResource(string);
System.out.println(string + " - " + resource);
}
}
}

View File

@@ -1,2 +0,0 @@
@echo off
graalvm-win\exec\mysql-server

View File

@@ -1,52 +0,0 @@
@echo off
set option=-H:+UnlockExperimentalVMOptions
set option=%option% -H:+ReportExceptionStackTraces
set option=%option% -H:-ParseRuntimeOptions
set option=%option% -H:+AddAllCharsets
set option=%option% -H:ConfigurationFileDirectories=graalvm-win\\native-image\\config
set option=%option% --enable-http
set option=%option% --enable-https
set option=%option% --no-fallback
set option=%option% --report-unsupported-elements-at-runtime
set option=%option% --allow-incomplete-classpath
@REM set option=%option% --link-at-build-time
set option=%option% --initialize-at-build-time=com.sh
:: build-time
set option=%option% --initialize-at-run-time=com.sh
::<!--新增-->
::<!--trace 表示编译时 进行 跟踪有些情况下可能会报错比如在这里设置了A类但是A类没有MAIN方法 会导致报错-->
set option=%option% --trace-class-initialization=com.sun.beans.introspect.ClassInfo
set option=%option% --trace-class-initialization=com.sun.beans.introspect.MethodInfo
set option=%option% --trace-class-initialization=com.sun.beans.TypeResolver
set option=%option% --trace-class-initialization=java.beans.Introspector
set option=%option% --trace-class-initialization=java.beans.ThreadGroupContext
set option=%option% --trace-class-initialization=com.sh
set option=%option% --trace-object-instantiation=java.util.jar.JarFile
set option=%option% --add-exports=java.base/java.nio=ALL-UNNAMED
set option=%option% --add-opens java.base/java.nio=ALL-UNNAMED
set option=%option% -Dfile.encoding=GBK
set option=%option% -Dio.netty.tryReflectionSetAccessible=true
:: 关闭控制台窗口
set option=%option% -H:NativeLinkerOption=/SUBSYSTEM:WINDOWS
:: 关闭控制台窗口
set option=%option% -H:NativeLinkerOption=/ENTRY:mainCRTStartup
echo %option%
md graalvm-win\\exec
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
C:\\java\\graalvm-jdk-21.0.3+7.1\\bin\\native-image.cmd %option% -cp "target/mysql-server.jar;target/lib/*" -jar target\mysql-server.jar target\mysql-server

View File

@@ -1,2 +0,0 @@
@echo off
C:\\java\\graalvm-jdk-21.0.3+7.1\\bin\\java -agentlib:native-image-agent=config-merge-dir=graalvm-win\\native-image\\config -cp "target/mysql-server.jar;target/lib/*" fxdb.fxdb.MainApplication 1

View File

@@ -1,14 +0,0 @@
@echo off
:: 设置Java环境变量
set JAVA_HOME=C:\java\graalvm-jdk-21.0.3+7.1
set PATH=%JAVA_HOME%\bin;%PATH%
:: 检查JAVA_HOME是否配置成功
echo %JAVA_HOME%
echo %PATH%
:: 打印Java版本信息确认配置成功
java -version
D:\\apache-maven-3.3.9\\bin\\mvn clean package -f pom.xml

View File

@@ -1,4 +0,0 @@
@echo off
call graalvm-win\graalvm-package.bat
call graalvm-win\graalvm-package-server.bat
call graalvm-win\graalvm-image.bat

View File

@@ -1,156 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fx-db</groupId>
<artifactId>fx-db</artifactId>
<version>1.0-SNAPSHOT</version>
<name>fx-db</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
</properties>
<repositories>
<repository>
<id>public</id>
<url>https://maven.aliyun.com/repository/public</url>
<!-- <url>https://repo1.maven.org/maven2/</url>-->
</repository>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/central</url>
<!-- <url>https://repo1.maven.org/maven2/</url>-->
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>public</name>
<url>https://maven.aliyun.com/repository/public</url>
</pluginRepository>
<pluginRepository>
<id>central</id>
<name>central</name>
<url>https://maven.aliyun.com/repository/central</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>mysql-server</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>fxdb.fxdb.MainApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>fxdb.fxdb.MainApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>gluonfx-maven-plugin</artifactId>
<version>1.0.10</version>
<configuration>
<target>host</target>
<mainClass>fxdb.fxdb.MainApplication</mainClass>
<bundlesList>
<list>fxdb.fxdb.HelloController</list>
</bundlesList>
<reflectionList>
<list>fxdb.fxdb.HelloController</list>
</reflectionList>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,29 +0,0 @@
package fxdb.fxdb;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("qj-712-fx-db");
stage.setScene(scene);
stage.setOnCloseRequest(windowEvent -> {
System.out.println("禁止关闭");
stage.setIconified(true);
windowEvent.consume();
});
stage.show();
}
public static void main(String[] args) {
launch();
}
}

View File

@@ -1,70 +0,0 @@
package fxdb.fxdb;
import fxdb.fxdb.service.DBFactory;
import fxdb.fxdb.service.WebService;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import java.io.PrintStream;
import java.util.concurrent.CompletableFuture;
public class HelloController {
@FXML private TextArea textAreaGame;
@FXML private TextField txt_port;
@FXML private TextField txt_user;
@FXML private TextField txt_pwd;
Thread hook;
public HelloController() throws Exception {
PrintStream printStream = new PrintStream(System.out) {
@Override public void println(String x) {
if (textAreaGame.getText().length() > 1024 * 1024 * 30) {
int i = textAreaGame.getText().indexOf("\n");
textAreaGame.setText(textAreaGame.getText().substring(i + 1));
}
textAreaGame.appendText(x + "\n");
}
};
System.setOut(printStream);
hook = new Thread(() -> {
DBFactory.getIns().stop();
Runtime.getRuntime().halt(0);
});
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(500);
WebService.getIns().start();
onReStartDb();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
public void onReStartDb() throws Exception {
onStopDb();
DBFactory.getIns().init(
"local_712_xw",
Integer.parseInt(txt_port.getText()),
txt_user.getText(),
txt_pwd.getText()
);
System.out.println("启动成功");
}
public void onStopDb() throws Exception {
DBFactory.getIns().stop();
System.out.println("停止成功");
}
public void onCloseWindow() {
hook.start();
}
}

View File

@@ -1,22 +0,0 @@
package fxdb.fxdb;
import fxdb.fxdb.service.GraalvmUtil;
import javafx.application.Application;
import java.net.URL;
import java.util.List;
public class MainApplication {
public static void main(String[] args) throws Exception {
if (args.length > 0) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
List<String> strings = GraalvmUtil.jarResources();
for (String string : strings) {
URL resource = contextClassLoader.getResource(string);
System.out.println(string + " - " + resource);
}
}
Application.launch(HelloApplication.class);
}
}

View File

@@ -1,91 +0,0 @@
package fxdb.fxdb.service;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
/**
* 数据库工厂
*
* @author: Troy.Chen(無心道, 15388152619)
* @version: 2024-07-23 16:45
**/
public class DBFactory {
private static final DBFactory ins = new DBFactory();
public static final File ok = new File("db-ok.txt");
public static DBFactory getIns() {
return ins;
}
DBFactory() {}
private DBConfigurationBuilder configBuilder;
private MyDB myDB;
public void init(String dataBase, int port, String user, String pwd) throws Exception {
configBuilder = DBConfigurationBuilder.newBuilder();
configBuilder.setPort(port); // OR, default: setPort(0); => autom. detect free port
configBuilder.setBaseDir("data-base/"); // just an example
configBuilder.setDataDir("data-base/data");
myDB = new MyDB(configBuilder.build(), dataBase, user, pwd, 60);
myDB.start();
write(1);
}
public static void write(int state) throws IOException {
String json = "{\"PID\":" + fetchProcessId() + ", \"states\":" + state + "}";
Files.write(
ok.toPath(),
json.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
);
}
public DBConfigurationBuilder getConfigBuilder() {
return configBuilder;
}
public MyDB getMyDB() {
return myDB;
}
public void stop() {
System.out.println("addShutdownHook");
try {
write(0);
} catch (Exception ignore) {}
try {
if (getMyDB() != null) {
getMyDB().stop();
}
} catch (Throwable e) {
System.out.println("关闭服务 " + e);
}
System.out.println("关闭服务完成");
}
public static String fetchProcessId() {
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName();
return name.substring(0, name.indexOf("@"));
} catch (Exception ignore) {
return "-1";
}
}
}

View File

@@ -1,110 +0,0 @@
package fxdb.fxdb.service;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class GraalvmUtil {
/** ?????????? <br>?????????????????????У?<br>??????????config????<br>???????в???jar??????? TODO ???????????е??·????? */
public static Stream<Tuple<String, InputStream>> resourceStreams(final String path) {
return resourceStreams(Thread.currentThread().getContextClassLoader(), path);
}
/** ?????????? <br>?????????????????????У?<br>??????????config????<br>???????в???jar??????? TODO ???????????е??·????? */
public static Stream<Tuple<String, InputStream>> resourceStreams(ClassLoader classLoader, final String path) {
try {
String findPath = path;
boolean fileExists = new File(path).exists();
if (!fileExists) {/*?????????????????????????*/
URL resource = classLoader.getResource(path);
if (resource != null) {
findPath = URLDecoder.decode(resource.getPath(), StandardCharsets.UTF_8.toString());
if (findPath.startsWith("/")) {
findPath = findPath.substring(1);
}
if (findPath.contains(".zip!") || findPath.contains(".jar!")) {
findPath = findPath.substring(5, findPath.indexOf("!/"));
try (FileInputStream fileInputStream = new FileInputStream(findPath);
ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);) {
List<Tuple<String, InputStream>> tmps = new ArrayList<>();
ZipEntry nextEntry = null;
while ((nextEntry = zipInputStream.getNextEntry()) != null) {
if (nextEntry.isDirectory()) continue;
String name = nextEntry.getName();
String replace = name.replace("\\", "/");
if (replace.startsWith(path)) {
/* todo ??????????????????????? */
byte[] extra = new byte[(int) nextEntry.getSize()];
zipInputStream.read(extra, 0, (int) nextEntry.getSize());
tmps.add(new Tuple<>(nextEntry.getName(), new ByteArrayInputStream(extra)));
}
}
return tmps.stream();
}
}
}
}
return Files.walk(Paths.get(findPath), 999)
.map(Path::toFile)
.filter(File::isFile)
.map(file -> {
try {
return new Tuple<>(file.getPath(), Files.newInputStream(file.toPath()));
} catch (Exception e) {
throw new RuntimeException("resources:" + file, e);
}
});
} catch (Exception e) {
throw new RuntimeException("resources:" + path, e);
}
}
public static String javaClassPath() {
return System.getProperty("java.class.path");
}
public static List<String> jarResources() throws Exception {
List<String> resourcesPath = new ArrayList<>();
String x = javaClassPath();
String[] split = x.split(File.pathSeparator);
for (String string : split) {
if (!string.endsWith(".jar")) continue;
try (InputStream inputStream = Files.newInputStream(Paths.get(string));
ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
ZipEntry nextEntry = null;
while ((nextEntry = zipInputStream.getNextEntry()) != null) {
/* todo ??????????????????????? */
resourcesPath.add(nextEntry.getName());
}
}
}
return resourcesPath;
}
public static class Tuple<F, S> {
public final F f;
public final S s;
public Tuple(F f, S s) {
this.f = f;
this.s = s;
}
}
}

View File

@@ -1,128 +0,0 @@
package fxdb.fxdb.service;
import ch.vorburger.exec.ManagedProcess;
import ch.vorburger.exec.ManagedProcessException;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfiguration;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
public class MyDB extends DB {
private String data_base;
private String user;
private String pwd;
int bak_Time = 0;
Timer timer = new Timer();
public MyDB(DBConfiguration config, String data_base, String user, String pwd, int bak_Time) {
super(config);
this.data_base = data_base;
this.user = user;
this.pwd = pwd;
try {
this.prepareDirectories();
} catch (Exception e) {
if (!check(e))
e.printStackTrace(System.err);
}
try {
this.unpackEmbeddedDb();
} catch (Exception ignore) {}
try {
this.install();
} catch (Exception e) {
if (!check(e))
e.printStackTrace(System.err);
}
}
private boolean check(Throwable e) {
if (e != null) {
if (e.getMessage().contains("is not empty. Only new or empty existing directories are accepted for --datadir"))
return true;
if (e.getCause() != null && check(e.getCause())) {
return true;
}
}
return false;
}
public void initDb() {
try {
String[] split = data_base.split(",|");
for (String dbName : split) {
createDB(dbName, user, pwd);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
initBakTimer();
}
public void initBakTimer() {
if (bak_Time > 0) {
timer.scheduleAtFixedRate(
new TimerTask() {
@Override public void run() {
bakSql();
}
},
TimeUnit.MINUTES.toMillis(bak_Time),
TimeUnit.MINUTES.toMillis(bak_Time)
);
}
}
public void bakSql() {
try {
String format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS").format(new Date());
String[] split = data_base.split(",|");
for (String dbName : split) {
File outputFile = new File("data-base/bak/" + dbName + "/" + format + ".sql");
outputFile.getParentFile().mkdirs();
ManagedProcess managedProcess = dumpSQL(
outputFile,
dbName, user, pwd
);
try {
managedProcess.start();
managedProcess.waitForExit();
} catch (Exception ignore) {
}
try {
managedProcess.destroy();
} catch (Exception ignore) {}
System.out.println("备份:" + outputFile);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
@Override public synchronized void start() throws ManagedProcessException {
super.start();
initDb();
}
@Override public synchronized void stop() throws ManagedProcessException {
if (timer != null) {
timer.cancel();
timer.purge();
timer = null;
}
/*这里会卡*/
// bakSql();
super.stop();
}
}

View File

@@ -1,49 +0,0 @@
package fxdb.fxdb.service;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
/**
* @author: Troy.Chen(無心道, 15388152619)
* @version: 2024-07-29 16:46
**/
public class WebService {
private static final WebService ins = new WebService();
public static WebService getIns() {
return ins;
}
WebService() {
}
HttpServer httpServer;
public void start() throws Exception {
httpServer = HttpServer.create(new InetSocketAddress(19902), 0);
httpServer.createContext("/api/db/stop", new HttpHandler() {
@Override public void handle(HttpExchange exchange) throws IOException {
byte[] bytes = "ok".getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, bytes.length);
exchange.getResponseBody().write(bytes);
exchange.getResponseBody().flush();
exchange.close();
DBFactory.getIns().stop();
}
});
httpServer.start();
System.out.println("http://localhost:19902/api/db/stop");
}
}

View File

@@ -1,12 +0,0 @@
module fxdb.fxdb {
requires java.management;
requires javafx.controls;
requires javafx.fxml;
requires jdk.httpserver;
requires org.kordamp.bootstrapfx.core;
requires ch.vorburger.mariadb4j;
requires ch.vorburger.exec;
opens fxdb.fxdb to javafx.fxml;
exports fxdb.fxdb;
}

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox alignment="CENTER" prefHeight="800" prefWidth="1200" spacing="20.0" xmlns="http://javafx.com/javafx/22"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fxdb.fxdb.HelloController">
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0"/>
</padding>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity"
minWidth="-Infinity" style="-fx-background-color: 999999;" tabClosingPolicy="UNAVAILABLE"
VBox.vgrow="ALWAYS">
<Tab text="设置">
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<Label layoutX="41.0" layoutY="51.0" text="端口:"/>
<TextField fx:id="txt_port" layoutX="100.0" layoutY="45.0" text="3308"/>
<Label layoutX="41.0" layoutY="78.0" prefHeight="15.0" prefWidth="48.0" text="用户:"/>
<TextField fx:id="txt_user" layoutX="100.0" layoutY="109.0" text="root"/>
<Label layoutX="41.0" layoutY="113.0" text="密码:"/>
<TextField fx:id="txt_pwd" layoutX="100.0" layoutY="74.0" text="root"/>
<Button layoutX="100.0" layoutY="144.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="64.0"
fx:id="btn_stop_db" onMouseClicked="#onStopDb" text="停止"/>
<Button fx:id="btn_restart_db" layoutX="100.0" layoutY="177.0" mnemonicParsing="false"
onMouseClicked="#onReStartDb" text="重启服务"/>
<Button fx:id="btn_close_window" layoutX="100.0" layoutY="210.0" mnemonicParsing="false"
onMouseClicked="#onCloseWindow" text="退出程序"/>
</children>
</AnchorPane>
</Tab>
<Tab text="输出">
<AnchorPane minHeight="0.0" minWidth="0.0">
<TextArea fx:id="textAreaGame" layoutX="255.0" layoutY="96.0" style="-fx-background-color: 99999;"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"/>
</AnchorPane>
</Tab>
</TabPane>
</VBox>