Fix SQL request issue. Fix date computing. Add methods.

This commit is contained in:
Christian P. MOMON 2013-09-10 18:32:35 +02:00
parent a9ebc14796
commit 2863aee6fa
6 changed files with 50 additions and 5 deletions

View file

@ -264,6 +264,18 @@ public class FileSikevaDB implements SikevaDB {
return 0; return 0;
} }
@Override
public long memorySizeOfAll() throws Exception {
// TODO Auto-generated method stub
return 0;
}
@Override
public long memorySizeOfAll(final String key) throws Exception {
// TODO Auto-generated method stub
return 0;
}
@Override @Override
public long memorySizeOfArchive() throws Exception { public long memorySizeOfArchive() throws Exception {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -46,7 +46,6 @@ public class SQLSikevaDB implements SikevaDB {
private String login; private String login;
private String password; private String password;
private Connection singleConnection; private Connection singleConnection;
private String contextName; private String contextName;
private DataSource dataSource; private DataSource dataSource;
@ -218,7 +217,7 @@ public class SQLSikevaDB implements SikevaDB {
if (maxDays < 0) { if (maxDays < 0) {
throw new IndexOutOfBoundsException("maxDays is negative."); throw new IndexOutOfBoundsException("maxDays is negative.");
} else { } else {
Date beforeDate = new Date(new Date().getTime() + maxDays * 24 * 60 * 60 * 1000); Date beforeDate = new Date(new Date().getTime() - maxDays * 24 * 60 * 60 * 1000);
clearArchive(beforeDate); clearArchive(beforeDate);
} }
} }
@ -338,7 +337,7 @@ public class SQLSikevaDB implements SikevaDB {
try { try {
connection = getConnection(); connection = getConnection();
connection.setAutoCommit(true); connection.setAutoCommit(true);
statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE AND TOPKEY=?"); statement = connection.prepareStatement("SELECT count(*) FROM elements WHERE TOPKEY=?");
statement.setString(1, key); statement.setString(1, key);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -903,6 +902,10 @@ public class SQLSikevaDB implements SikevaDB {
return result; return result;
} }
public String getContextName() {
return contextName;
}
/** /**
* *
* @return * @return
@ -1395,7 +1398,7 @@ public class SQLSikevaDB implements SikevaDB {
try { try {
connection = getConnection(); connection = getConnection();
connection.setAutoCommit(true); connection.setAutoCommit(true);
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NULL"); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?");
statement.setString(1, key); statement.setString(1, key);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -1445,6 +1448,32 @@ public class SQLSikevaDB implements SikevaDB {
return result; return result;
} }
/**
*
*/
@Override
public long memorySizeOfAll() throws Exception {
long result;
result = memorySize() + memorySizeOfArchive();
//
return result;
}
/**
*
*/
@Override
public long memorySizeOfAll(final String key) throws Exception {
long result;
result = memorySize(key) + memorySizeOfArchive(key);
//
return result;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1487,7 +1516,7 @@ public class SQLSikevaDB implements SikevaDB {
try { try {
connection = getConnection(); connection = getConnection();
connection.setAutoCommit(true); connection.setAutoCommit(true);
statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY IS NULL"); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?");
statement.setString(1, key); statement.setString(1, key);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();

View file

@ -102,6 +102,10 @@ public interface SikevaDB {
public long memorySize(String key, String subkey) throws Exception; public long memorySize(String key, String subkey) throws Exception;
public long memorySizeOfAll() throws Exception;
long memorySizeOfAll(String key) throws Exception;
public long memorySizeOfArchive() throws Exception; public long memorySizeOfArchive() throws Exception;
long memorySizeOfArchive(String key) throws Exception; long memorySizeOfArchive(String key) throws Exception;