|
17 | 17 | import com.microsoft.semantickernel.data.vectorstorage.options.GetRecordOptions; |
18 | 18 | import com.microsoft.semantickernel.data.vectorstorage.options.VectorSearchOptions; |
19 | 19 | import com.mysql.cj.jdbc.MysqlDataSource; |
| 20 | + |
| 21 | +import java.io.IOException; |
20 | 22 | import java.nio.file.Files; |
21 | 23 | import java.nio.file.Path; |
22 | 24 | import java.util.ArrayList; |
@@ -61,6 +63,16 @@ public enum QueryProvider { |
61 | 63 | HSQLDB |
62 | 64 | } |
63 | 65 |
|
| 66 | + static Path createTempDbFile(String prefix) { |
| 67 | + try { |
| 68 | + Path file = Files.createTempFile(prefix, ".db"); |
| 69 | + file.toFile().deleteOnExit(); |
| 70 | + return file; |
| 71 | + } catch (IOException e) { |
| 72 | + throw new RuntimeException(e); |
| 73 | + } |
| 74 | + } |
| 75 | + |
64 | 76 | private JDBCVectorStoreRecordCollection<Hotel> buildRecordCollection(QueryProvider provider, |
65 | 77 | @Nonnull String collectionName) { |
66 | 78 | SQLVectorStoreQueryProvider queryProvider; |
@@ -88,17 +100,18 @@ private JDBCVectorStoreRecordCollection<Hotel> buildRecordCollection(QueryProvid |
88 | 100 | .build(); |
89 | 101 | break; |
90 | 102 | case SQLite: |
| 103 | + Path sqliteDb = createTempDbFile("sqliteDb"); |
91 | 104 | SQLiteDataSource sqliteDataSource = new SQLiteDataSource(); |
92 | | - sqliteDataSource.setUrl("jdbc:sqlite:file:testdb"); |
| 105 | + sqliteDataSource.setUrl("jdbc:sqlite:file:" + sqliteDb.toFile().getAbsolutePath()); |
93 | 106 | dataSource = sqliteDataSource; |
| 107 | + |
94 | 108 | queryProvider = SQLiteVectorStoreQueryProvider.builder() |
95 | | - .withDataSource(sqliteDataSource) |
| 109 | + .withDataSource(dataSource) |
96 | 110 | .build(); |
97 | 111 | break; |
98 | 112 | case HSQLDB: |
99 | 113 | try { |
100 | | - Path file = Files.createTempFile("testdb", ".db"); |
101 | | - file.toFile().deleteOnExit(); |
| 114 | + Path file = createTempDbFile("testHSQLDB"); |
102 | 115 |
|
103 | 116 | Properties properties = new Properties(); |
104 | 117 | properties.putAll( |
|
0 commit comments