Improved Demo. Added helper methods for numeric subkey.

This commit is contained in:
Christian P. MOMON 2017-04-25 23:50:24 +02:00
parent ff63a72919
commit 7ea53a7955
4 changed files with 252 additions and 22 deletions

View file

@ -37,6 +37,8 @@ public interface SikevaDB
public long countOfElements(String key) throws SikevaDBException; public long countOfElements(String key) throws SikevaDBException;
public long countOfElements(String key, long subkey) throws SikevaDBException;
public long countOfElements(String key, String subkey) throws SikevaDBException; public long countOfElements(String key, String subkey) throws SikevaDBException;
public void create() throws SikevaDBException; public void create() throws SikevaDBException;
@ -45,6 +47,8 @@ public interface SikevaDB
public Element getElement(String key) throws SikevaDBException; public Element getElement(String key) throws SikevaDBException;
public Element getElement(String key, long subkey) throws SikevaDBException;
public Element getElement(String key, String subkey) throws SikevaDBException; public Element getElement(String key, String subkey) throws SikevaDBException;
public Elements getElements() throws SikevaDBException; public Elements getElements() throws SikevaDBException;
@ -57,6 +61,8 @@ public interface SikevaDB
public String getValue(String key) throws SikevaDBException; public String getValue(String key) throws SikevaDBException;
public String getValue(String key, long subkey) throws SikevaDBException;
public String getValue(String key, String subkey) throws SikevaDBException; public String getValue(String key, String subkey) throws SikevaDBException;
public StringList getValues(String key) throws SikevaDBException; public StringList getValues(String key) throws SikevaDBException;
@ -75,25 +81,33 @@ public interface SikevaDB
public long memorySize(String key) throws SikevaDBException; public long memorySize(String key) throws SikevaDBException;
public long memorySize(String key, long subkey) throws SikevaDBException;
public long memorySize(String key, String subkey) throws SikevaDBException; public long memorySize(String key, String subkey) throws SikevaDBException;
void open() throws SikevaDBException; void open() throws SikevaDBException;
void put(Element element) throws SikevaDBException; void put(Element element) throws SikevaDBException;
void put(String key, long subkey, String value) throws SikevaDBException;
void put(String key, String value) throws SikevaDBException; void put(String key, String value) throws SikevaDBException;
void put(String key, String subkey, String value) throws SikevaDBException; void put(String key, String subkey, String value) throws SikevaDBException;
void remove(final String key) throws SikevaDBException; void remove(final String key) throws SikevaDBException;
void remove(final String key, final long subkey) throws SikevaDBException;
void remove(final String key, final String subkey) throws SikevaDBException; void remove(final String key, final String subkey) throws SikevaDBException;
void removeMany(final String key, final String... subkeys) throws SikevaDBException; void removeMany(final String key, final String... subkeys) throws SikevaDBException;
void renameKey(final String oldKey, final String newKey) throws SikevaDBException; void renameKey(final String oldKey, final String newKey) throws SikevaDBException;
void renameSubKey(final String key, final String oldSubKey, final String newSubKey) throws SikevaDBException; void renameSubkey(final String key, final long oldSubKey, final long newSubKey) throws SikevaDBException;
void renameSubkey(final String key, final String oldSubKey, final String newSubKey) throws SikevaDBException;
void replaceInValue(final String key, final String... tokens) throws SikevaDBException; void replaceInValue(final String key, final String... tokens) throws SikevaDBException;

View file

@ -101,10 +101,10 @@ public final class SikevaDBDemo
{ {
for (int index = 0; index < 10; index++) for (int index = 0; index < 10; index++)
{ {
database.put("victor", String.valueOf(index), "victor" + index); database.put("victor", index, "victor" + index);
} }
String value = database.getValue("victor", String.valueOf(7)); String value = database.getValue("victor", 7);
if (StringUtils.equals(value, "victor7")) if (StringUtils.equals(value, "victor7"))
{ {
System.out.println("victor is correctly stored."); System.out.println("victor is correctly stored.");
@ -114,10 +114,9 @@ public final class SikevaDBDemo
System.out.println("victor is NOT correctly stored."); System.out.println("victor is NOT correctly stored.");
} }
// TODOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO String.valueOf -> //
// int database.remove("victor", 5);
database.remove("victor", String.valueOf(5)); if (database.getValue("victor", 5) == null)
if (database.getValue("victor", String.valueOf(5)) == null)
{ {
System.out.println("(victor, 5) is correctly removed."); System.out.println("(victor, 5) is correctly removed.");
} }
@ -127,6 +126,10 @@ public final class SikevaDBDemo
} }
} }
//
System.out.println("Database values:\t" + database.countOfElements());
System.out.println("Database memory:\t" + database.memorySize() + " bytes");
// //
database.close(); database.close();
} }

View file

@ -99,6 +99,7 @@ public class FileTreeSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -109,6 +110,7 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* @throws IOException * @throws IOException
*
*/ */
@Override @Override
public void clear() throws SikevaDBException public void clear() throws SikevaDBException
@ -128,6 +130,7 @@ public class FileTreeSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -201,6 +204,22 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public long countOfElements(final String key, final long subkey) throws SikevaDBException
{
long result;
result = countOfElements(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public long countOfElements(final String key, final String subkey) public long countOfElements(final String key, final String subkey)
@ -231,6 +250,7 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void create() throws SikevaDBException public void create() throws SikevaDBException
@ -256,6 +276,7 @@ public class FileTreeSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -362,6 +383,21 @@ public class FileTreeSikevaDB implements SikevaDB
return result; return result;
} }
/**
* {@inheritDoc}
*
*/
@Override
public Element getElement(final String key, final long subkey) throws SikevaDBException
{
Element result;
result = getElement(key, String.valueOf(subkey));
//
return result;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -599,6 +635,21 @@ public class FileTreeSikevaDB implements SikevaDB
return result; return result;
} }
/**
* {@inheritDoc}
*
*/
@Override
public String getValue(final String key, final long subkey) throws SikevaDBException
{
String result;
result = getValue(key, String.valueOf(subkey));
//
return result;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -857,7 +908,21 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException */
@Override
public long memorySize(final String key, final long subkey) throws SikevaDBException
{
long result;
result = memorySize(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public long memorySize(final String key, final String subkey) throws SikevaDBException public long memorySize(final String key, final String subkey) throws SikevaDBException
@ -961,7 +1026,16 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException */
@Override
public void put(final String key, final long subkey, final String value) throws SikevaDBException
{
put(key, String.valueOf(subkey), value);
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public void put(final String key, final String value) throws SikevaDBException public void put(final String key, final String value) throws SikevaDBException
@ -996,7 +1070,6 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException
*/ */
@Override @Override
public void put(final String key, final String subkey, final String value) throws SikevaDBException public void put(final String key, final String subkey, final String value) throws SikevaDBException
@ -1032,7 +1105,6 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException
*/ */
@Override @Override
public void remove(final String key) throws SikevaDBException public void remove(final String key) throws SikevaDBException
@ -1063,7 +1135,16 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException */
@Override
public void remove(final String key, final long subkey) throws SikevaDBException
{
remove(key, String.valueOf(subkey));
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public void remove(final String key, final String subkey) throws SikevaDBException public void remove(final String key, final String subkey) throws SikevaDBException
@ -1095,7 +1176,6 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws SikevaDBException
*/ */
@Override @Override
public void removeMany(final String key, final String... subkeys) throws SikevaDBException public void removeMany(final String key, final String... subkeys) throws SikevaDBException
@ -1118,6 +1198,7 @@ public class FileTreeSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void renameKey(final String oldKey, final String newKey) public void renameKey(final String oldKey, final String newKey)
@ -1161,7 +1242,17 @@ public class FileTreeSikevaDB implements SikevaDB
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void renameSubKey(final String key, final String oldSubkey, final String newSubkey) throws SikevaDBException public void renameSubkey(final String key, final long oldSubKey, final long newSubkey) throws SikevaDBException
{
renameSubkey(key, String.valueOf(oldSubKey), String.valueOf(newSubkey));
}
/**
* {@inheritDoc}
*
*/
@Override
public void renameSubkey(final String key, final String oldSubkey, final String newSubkey) throws SikevaDBException
{ {
this.logger.debug("renameSybKey starting... [{}][{}][{}]", oldSubkey, newSubkey); this.logger.debug("renameSybKey starting... [{}][{}][{}]", oldSubkey, newSubkey);

View file

@ -139,7 +139,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* This methods clear all data in current opened database. * {@inheritDoc}
* *
*/ */
@Override @Override
@ -167,7 +167,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* This method closes the current database session. * {@inheritDoc}
* *
*/ */
@Override @Override
@ -246,6 +246,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public long countOfElements() throws SikevaDBException public long countOfElements() throws SikevaDBException
@ -281,6 +282,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public long countOfElements(final String key) throws SikevaDBException public long countOfElements(final String key) throws SikevaDBException
@ -324,6 +326,22 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public long countOfElements(final String key, final long subkey) throws SikevaDBException
{
long result;
result = countOfElements(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public long countOfElements(final String key, final String subkey) throws SikevaDBException public long countOfElements(final String key, final String subkey) throws SikevaDBException
@ -371,10 +389,8 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* This method creates the schema (table) used by SQLSikevaDB. * {@inheritDoc}
* *
* @throws IOException
* @throws SikevaDBException
*/ */
@Override @Override
public void create() throws SikevaDBException public void create() throws SikevaDBException
@ -446,6 +462,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -535,6 +552,9 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* *
* @param id
* @return
* @throws SikevaDBException
*/ */
public Element getElement(final long id) throws SikevaDBException public Element getElement(final long id) throws SikevaDBException
{ {
@ -603,6 +623,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public Element getElement(final String key) throws SikevaDBException public Element getElement(final String key) throws SikevaDBException
@ -674,6 +695,22 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public Element getElement(final String key, final long subkey) throws SikevaDBException
{
Element result;
result = getElement(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public Element getElement(final String key, final String subkey) throws SikevaDBException public Element getElement(final String key, final String subkey) throws SikevaDBException
@ -750,6 +787,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -807,6 +845,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public Elements getElements(final String key) throws SikevaDBException public Elements getElements(final String key) throws SikevaDBException
@ -872,6 +911,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public StringList getKeys() throws SikevaDBException public StringList getKeys() throws SikevaDBException
@ -931,6 +971,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public StringList getSubkeys(final String key) throws SikevaDBException public StringList getSubkeys(final String key) throws SikevaDBException
@ -991,6 +1032,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public String getValue(final String key) throws SikevaDBException public String getValue(final String key) throws SikevaDBException
@ -1048,6 +1090,22 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public String getValue(final String key, final long subkey) throws SikevaDBException
{
String result;
result = getValue(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public String getValue(final String key, final String subkey) throws SikevaDBException public String getValue(final String key, final String subkey) throws SikevaDBException
@ -1110,6 +1168,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public StringList getValues(final String key) throws SikevaDBException public StringList getValues(final String key) throws SikevaDBException
@ -1151,6 +1210,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -1172,6 +1232,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -1186,6 +1247,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -1208,6 +1270,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public boolean isCreated() throws SikevaDBException public boolean isCreated() throws SikevaDBException
@ -1222,6 +1285,7 @@ public class SQLSikevaDB implements SikevaDB
} }
/** /**
* {@inheritDoc}
* *
*/ */
@Override @Override
@ -1237,6 +1301,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public long memorySize() throws SikevaDBException public long memorySize() throws SikevaDBException
@ -1273,6 +1338,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public long memorySize(final String key) throws SikevaDBException public long memorySize(final String key) throws SikevaDBException
@ -1316,6 +1382,22 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public long memorySize(final String key, final long subkey) throws SikevaDBException
{
long result;
result = memorySize(key, String.valueOf(subkey));
//
return result;
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public long memorySize(final String key, final String subkey) throws SikevaDBException public long memorySize(final String key, final String subkey) throws SikevaDBException
@ -1366,6 +1448,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void open() throws SikevaDBException public void open() throws SikevaDBException
@ -1427,6 +1510,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void put(final Element element) throws SikevaDBException public void put(final Element element) throws SikevaDBException
@ -1547,6 +1631,17 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public void put(final String key, final long subkey, final String value) throws SikevaDBException
{
put(key, String.valueOf(subkey), String.valueOf(value));
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public void put(final String key, final String value) throws SikevaDBException public void put(final String key, final String value) throws SikevaDBException
@ -1627,6 +1722,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void put(final String key, final String subkey, final String value) throws SikevaDBException public void put(final String key, final String subkey, final String value) throws SikevaDBException
@ -1720,6 +1816,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void remove(final String key) throws SikevaDBException public void remove(final String key) throws SikevaDBException
@ -1772,6 +1869,17 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/
@Override
public void remove(final String key, final long subkey) throws SikevaDBException
{
remove(key, String.valueOf(subkey));
}
/**
* {@inheritDoc}
*
*/ */
@Override @Override
public void remove(final String key, final String subkey) throws SikevaDBException public void remove(final String key, final String subkey) throws SikevaDBException
@ -1820,6 +1928,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void removeMany(final String key, final String... subkeys) throws SikevaDBException public void removeMany(final String key, final String... subkeys) throws SikevaDBException
@ -1872,6 +1981,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void renameKey(final String oldKey, final String newKey) throws SikevaDBException public void renameKey(final String oldKey, final String newKey) throws SikevaDBException
@ -1920,9 +2030,20 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void renameSubKey(final String key, final String oldKey, final String newKey) throws SikevaDBException public void renameSubkey(final String key, final long oldSubkey, final long newSubkey) throws SikevaDBException
{
renameSubkey(key, String.valueOf(oldSubkey), String.valueOf(newSubkey));
}
/**
* {@inheritDoc}
*
*/
@Override
public void renameSubkey(final String key, final String oldKey, final String newKey) throws SikevaDBException
{ {
if ((key == null) || (oldKey == null) || (newKey == null)) if ((key == null) || (oldKey == null) || (newKey == null))
{ {
@ -1936,6 +2057,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void replaceInValue(final String key, final String... tokens) throws SikevaDBException public void replaceInValue(final String key, final String... tokens) throws SikevaDBException
@ -1959,6 +2081,7 @@ public class SQLSikevaDB implements SikevaDB
/** /**
* {@inheritDoc} * {@inheritDoc}
*
*/ */
@Override @Override
public void replaceInValues(final String key, final String... tokens) throws SikevaDBException public void replaceInValues(final String key, final String... tokens) throws SikevaDBException
@ -2031,5 +2154,4 @@ public class SQLSikevaDB implements SikevaDB
{ {
this.url = url; this.url = url;
} }
} }