diff --git a/pom.xml b/pom.xml index 115f598..7666981 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,16 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + diff --git a/src/main/java/minsecurity/identity/persist/sqlite/Sqlite.java b/src/main/java/minsecurity/identity/persist/sqlite/Sqlite.java new file mode 100644 index 0000000..dfa3206 --- /dev/null +++ b/src/main/java/minsecurity/identity/persist/sqlite/Sqlite.java @@ -0,0 +1,54 @@ +package minsecurity.identity.persist.sqlite; + +/* + * @Author: zhengqi wu + * @Description: Sqlite封装 + * @Version: 1.0.0 + * @Date: 22:34 2021/04/01 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ +// 存在配置信息,使用单例模式封装工具类 +public class Sqlite { + private static final Sqlite Instance = new Sqlite(); // sqlite 唯一object + + private String passwd = "2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99"; // 初始数据库密码 + private String db_file = "identity.db"; // 数据库文件名 + private Sqlite(){ + + } + + /** + * 获取Sqlite object + * @return Sqlite object + */ + public static Sqlite getInstance() { + return Instance; + } + + /** + * 设置数据库的连接密码 + * @param pass 新密码 + * @throws Exception + */ + public void setPasswd(String pass) throws Exception { + if (pass.length() != 64){ + throw new Exception("Invalid Length"); + } + passwd = pass; + } + + public void open(String filePath){ + try{ + boolean db_exists = SqliteUtil.pathExists(filePath); + if (!db_exists){ + + } + String real_db_file = filePath + db_file; + + }catch (Exception ex){ + // TODO 出错时关闭数据库 + } + } + + +} diff --git a/src/main/java/minsecurity/identity/persist/sqlite/SqliteUtil.java b/src/main/java/minsecurity/identity/persist/sqlite/SqliteUtil.java new file mode 100644 index 0000000..03820c8 --- /dev/null +++ b/src/main/java/minsecurity/identity/persist/sqlite/SqliteUtil.java @@ -0,0 +1,33 @@ +package minsecurity.identity.persist.sqlite; + +import java.io.File; + +/* + * @Author: zhengqi wu + * @Description: sqlite工具类封装 + * @Version: 1.0.0 + * @Date: 10:34 2021/03/10 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ + +// 无配置信息,采用静态类 +public final class SqliteUtil { + // Home returns the home directory for the executing user. + // + // This uses an OS-specific method for discovering the home directory. + // An error is returned if a home directory cannot be detected. + public static String home() + { + return System.getProperty("user.home"); + } + + /** + * 判断文件是否存在 + * @param path 特定文件路径 + * @return 判断结果 + */ + public static boolean pathExists(String path){ + File file = new File(path); + return file.exists(); + } +} diff --git a/src/main/java/minsecurity/identity/persist/sqlite/db/Db.java b/src/main/java/minsecurity/identity/persist/sqlite/db/Db.java new file mode 100644 index 0000000..8198d7a --- /dev/null +++ b/src/main/java/minsecurity/identity/persist/sqlite/db/Db.java @@ -0,0 +1,4 @@ +package minsecurity.identity.persist.sqlite.db; + +public class Db { +} diff --git a/src/main/java/minsecurity/identity/persist/sqlite/db/Internal.java b/src/main/java/minsecurity/identity/persist/sqlite/db/Internal.java new file mode 100644 index 0000000..11433d0 --- /dev/null +++ b/src/main/java/minsecurity/identity/persist/sqlite/db/Internal.java @@ -0,0 +1,4 @@ +package minsecurity.identity.persist.sqlite.db; + +public class Internal { +} diff --git a/src/test/java/minsecurity/identity/sqlite/SqliteTest.java b/src/test/java/minsecurity/identity/sqlite/SqliteTest.java new file mode 100644 index 0000000..8f2f170 --- /dev/null +++ b/src/test/java/minsecurity/identity/sqlite/SqliteTest.java @@ -0,0 +1,14 @@ +package minsecurity.identity.sqlite; + +import minsecurity.identity.persist.sqlite.SqliteUtil; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +public class SqliteTest { + @Test + public void testHome(){ + System.out.println(SqliteUtil.home()); + assertFalse(SqliteUtil.pathExists("/aaa/1.txt")); + } +}