Skip to content

Commit 82874af

Browse files
[MOD] store:reset → store:close; minor changes
1 parent 7ab1fdf commit 82874af

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

basex-core/src/main/java/org/basex/core/Stores.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,18 @@ public synchronized void clear() {
122122
}
123123

124124
/**
125-
* Resets the stores.
125+
* Closes a store.
126+
* @param name name of store
126127
* @param info input info
127128
* @throws QueryException query exception
128129
*/
129-
public synchronized void reset(final InputInfo info) throws QueryException {
130-
for(final String name : stores.keySet()) {
131-
try {
132-
writeStore(name, false);
133-
} catch(final IOException | QueryException ex) {
134-
throw STORE_IO_X.get(info, ex);
135-
}
130+
public synchronized void close(final String name, final InputInfo info) throws QueryException {
131+
try {
132+
writeStore(name, false);
133+
} catch(final IOException ex) {
134+
throw STORE_IO_X.get(info, ex);
136135
}
137-
stores.clear();
136+
stores.remove(name);
138137
}
139138

140139
/**
@@ -164,8 +163,8 @@ public synchronized void read(final String name, final InputInfo info, final Que
164163
throws QueryException {
165164
if(storeFile(name).exists()) {
166165
readStore(name, info, qc);
167-
} else if(standardStore(name)) {
168-
stores.remove("");
166+
} else {
167+
stores.remove(name);
169168
}
170169
}
171170

@@ -186,17 +185,9 @@ public synchronized void write(final String name, final InputInfo info) throws Q
186185
/**
187186
* Deletes a store.
188187
* @param name name of store
189-
* @param info input info
190-
* @param qc query context
191-
* @throws QueryException query exception
192188
*/
193-
public synchronized void delete(final String name, final InputInfo info,
194-
final QueryContext qc) throws QueryException {
195-
if(standardStore(name)) {
196-
get(name, false, info, qc).map.clear();
197-
} else {
198-
stores.remove(name);
199-
}
189+
public synchronized void delete(final String name) {
190+
stores.remove(name);
200191
storeFile(name).delete();
201192
}
202193

basex-core/src/main/java/org/basex/query/func/Function.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,8 +1822,11 @@ EMPTY_SEQUENCE_Z, flag(NDT), PROC_URI, Perm.ADMIN),
18221822
_STORE_CLEAR(StoreClear::new, "clear()",
18231823
params(), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18241824
/** XQuery function. */
1825+
_STORE_CLOSE(StoreClose::new, "close([name])",
1826+
params(STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
1827+
/** XQuery function. */
18251828
_STORE_DELETE(StoreDelete::new, "delete([name])",
1826-
params(STRING_O), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
1829+
params(STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18271830
/** XQuery function. */
18281831
_STORE_GET(StoreGet::new, "get(key[,name])",
18291832
params(STRING_O, STRING_ZO), ITEM_ZM, flag(NDT), STORE_URI, Perm.CREATE),
@@ -1841,16 +1844,13 @@ ITEM_ZM, flag(HOF, NDT), STORE_URI, Perm.CREATE),
18411844
params(STRING_O, ITEM_ZM, STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18421845
/** XQuery function. */
18431846
_STORE_READ(StoreRead::new, "read([name])",
1844-
params(STRING_O), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
1847+
params(STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18451848
/** XQuery function. */
18461849
_STORE_REMOVE(StoreRemove::new, "remove(key[,name])",
18471850
params(STRING_O, STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18481851
/** XQuery function. */
1849-
_STORE_RESET(StoreReset::new, "reset()",
1850-
params(), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
1851-
/** XQuery function. */
18521852
_STORE_WRITE(StoreWrite::new, "write([name])",
1853-
params(STRING_O), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
1853+
params(STRING_ZO), EMPTY_SEQUENCE_Z, flag(NDT), STORE_URI, Perm.CREATE),
18541854

18551855
// Strings Module
18561856

basex-core/src/main/java/org/basex/query/func/store/StoreReset.java renamed to basex-core/src/main/java/org/basex/query/func/store/StoreClose.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
* @author BaseX Team, BSD License
1111
* @author Christian Gruen
1212
*/
13-
public final class StoreReset extends StoreFn {
13+
public final class StoreClose extends StoreFn {
1414
@Override
1515
public Empty item(final QueryContext qc, final InputInfo ii) throws QueryException {
16-
stores(qc).reset(info);
16+
final String name = toName(arg(0), qc);
17+
18+
stores(qc).close(name, info);
1719
return Empty.VALUE;
1820
}
1921
}

basex-core/src/main/java/org/basex/query/func/store/StoreDelete.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public final class StoreDelete extends StoreFn {
1414
@Override
1515
public Empty item(final QueryContext qc, final InputInfo ii) throws QueryException {
1616
final String name = toName(arg(0), qc);
17-
stores(qc).delete(name, info, qc);
17+
stores(qc).delete(name);
1818
return Empty.VALUE;
1919
}
2020
}

basex-core/src/test/java/org/basex/query/func/StoreModuleTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public final class StoreModuleTest extends SandboxTest {
4040
query(_STORE_LIST.args() + " => count()", 0);
4141
}
4242

43+
/** Test method. */
44+
@Test public void close() {
45+
final Function func = _STORE_CLOSE;
46+
query(_STORE_PUT.args("key", "RESET"));
47+
query(_STORE_PUT.args("key", "RESET", "cache"));
48+
query(func.args(), "");
49+
query(_STORE_GET.args("key"), "RESET");
50+
query(_STORE_GET.args("key", "cache"), "RESET");
51+
}
52+
4353
/** Test method. */
4454
@Test public void delete() {
4555
final Function func = _STORE_DELETE;
@@ -162,6 +172,11 @@ public final class StoreModuleTest extends SandboxTest {
162172
query(func.args("READ"));
163173
query(_STORE_KEYS.args(), "key");
164174

175+
query(_STORE_PUT.args("key", "READ", "NEW"));
176+
query(_STORE_KEYS.args("NEW"), "key");
177+
query(func.args("NEW"));
178+
query(_STORE_KEYS.args("NEW"), "");
179+
165180
// invalid names
166181
for(final char ch : INVALID) error(func.args(ch), STORE_NAME_X);
167182
}
@@ -180,18 +195,6 @@ public final class StoreModuleTest extends SandboxTest {
180195
query(_STORE_LIST.args() + "=> count()", 0);
181196
}
182197

183-
/** Test method. */
184-
@Test public void reset() {
185-
final Function func = _STORE_RESET;
186-
query(_STORE_PUT.args("key", "RESET"));
187-
query(_STORE_PUT.args("key", "RESET", "cache"));
188-
query(_STORE_GET.args("key"), "RESET");
189-
query(_STORE_GET.args("key", "cache"), "RESET");
190-
query(func.args(), "");
191-
query(_STORE_GET.args("key"), "RESET");
192-
query(_STORE_GET.args("key", "cache"), "RESET");
193-
}
194-
195198
/** Test method. */
196199
@Test public void write() {
197200
final Function func = _STORE_WRITE;

0 commit comments

Comments
 (0)