Improve column order. Add log on open action. Clean files.
This commit is contained in:
parent
7709d3b442
commit
a84a4ca321
6 changed files with 87 additions and 80 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
#Build Number for ANT. Do not edit!
|
||||
#Sat Aug 24 15:54:52 CEST 2013
|
||||
build.number=1
|
||||
#Tue Sep 03 00:05:56 CEST 2013
|
||||
build.number=2
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
--
|
||||
-- Base de données: `sikevadb-kiwa`
|
||||
--
|
||||
CREATE DATABASE IF NOT EXISTS `sikevadb-test` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
|
||||
USE `sikevadb-kiwa`;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
|
@ -15,14 +9,16 @@ USE `sikevadb-kiwa`;
|
|||
|
||||
DROP TABLE IF EXISTS `elements`;
|
||||
CREATE TABLE IF NOT EXISTS `elements` (
|
||||
`ID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`TOPKEY` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`SUBKEY` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`VALUE` longtext COLLATE utf8_unicode_ci,
|
||||
`SIZE` int(11) NOT NULL DEFAULT '0',
|
||||
`DIGEST` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`CREATION_DATE` date NOT NULL,
|
||||
`EDITION_DATE` date NOT NULL,
|
||||
`ARCHIVE_DATE` date DEFAULT NULL,
|
||||
`VALUE` longtext COLLATE utf8_unicode_ci,
|
||||
PRIMARY KEY (`TOPKEY`),
|
||||
KEY `XKEYINDEX` (`TOPKEY`,`SUBKEY`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
`CREATION_DATE` datetime NOT NULL,
|
||||
`EDITION_DATE` datetime NOT NULL,
|
||||
`ARCHIVE_DATE` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`ID`),
|
||||
KEY `XKEYINDEX` (`TOPKEY`,`SUBKEY`),
|
||||
KEY `TOPKEYINDEX` (`TOPKEY`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
|
@ -29,6 +29,8 @@ import javax.naming.NamingException;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.StringList;
|
||||
|
||||
|
@ -38,6 +40,7 @@ import fr.devinsy.util.StringList;
|
|||
* @author Christian P. Momon
|
||||
*/
|
||||
public class SQLSikevaDB implements SikevaDB {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SQLSikevaDB.class);
|
||||
private String driverClassname;
|
||||
private String url;
|
||||
private String login;
|
||||
|
@ -584,7 +587,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||
statement.setString(1, key);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
|
@ -593,12 +596,12 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
Element element = new Element();
|
||||
element.setKey(resultSet.getString(1));
|
||||
element.setSubkey(resultSet.getString(2));
|
||||
element.setSize(resultSet.getLong(3));
|
||||
element.setDigest(resultSet.getString(4));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setValue(resultSet.getString(8));
|
||||
element.setValue(resultSet.getString(3));
|
||||
element.setSize(resultSet.getLong(4));
|
||||
element.setDigest(resultSet.getString(5));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
|
||||
//
|
||||
result.add(element);
|
||||
|
@ -634,7 +637,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC");
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
resultSet = statement.executeQuery();
|
||||
|
@ -644,12 +647,12 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
Element element = new Element();
|
||||
element.setKey(resultSet.getString(1));
|
||||
element.setSubkey(resultSet.getString(2));
|
||||
element.setSize(resultSet.getLong(3));
|
||||
element.setDigest(resultSet.getString(4));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setValue(resultSet.getString(8));
|
||||
element.setValue(resultSet.getString(3));
|
||||
element.setSize(resultSet.getLong(4));
|
||||
element.setDigest(resultSet.getString(5));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
|
||||
//
|
||||
result.add(element);
|
||||
|
@ -714,7 +717,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
try {
|
||||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection.prepareStatement("SELECT DISTINCT SUBKEY FROM elements WHERE KEY=? ORDER BY CREATION_DATE ASC");
|
||||
statement = connection.prepareStatement("SELECT DISTINCT SUBKEY FROM elements WHERE TOPKEY=? ORDER BY CREATION_DATE ASC");
|
||||
statement.setString(1, key);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
|
@ -924,7 +927,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NULL");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NULL");
|
||||
statement.setString(1, key);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
|
@ -934,12 +937,13 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
result = new Element();
|
||||
result.setKey(resultSet.getString(1));
|
||||
result.setSubkey(resultSet.getString(2));
|
||||
result.setSize(resultSet.getLong(3));
|
||||
result.setDigest(resultSet.getString(4));
|
||||
result.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
result.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
result.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
result.setValue(resultSet.getString(8));
|
||||
result.setValue(resultSet.getString(3));
|
||||
result.setSize(resultSet.getLong(4));
|
||||
result.setDigest(resultSet.getString(5));
|
||||
result.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
result.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
result.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
|
@ -977,7 +981,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?");
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
resultSet = statement.executeQuery();
|
||||
|
@ -988,12 +992,12 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
result = new Element();
|
||||
result.setKey(resultSet.getString(1));
|
||||
result.setSubkey(resultSet.getString(2));
|
||||
result.setSize(resultSet.getLong(3));
|
||||
result.setDigest(resultSet.getString(4));
|
||||
result.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
result.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
result.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
result.setValue(resultSet.getString(8));
|
||||
result.setValue(resultSet.getString(3));
|
||||
result.setSize(resultSet.getLong(4));
|
||||
result.setDigest(resultSet.getString(5));
|
||||
result.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
result.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
result.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
|
@ -1030,7 +1034,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE ASC");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE ASC");
|
||||
statement.setString(1, key);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
|
@ -1039,12 +1043,12 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
Element element = new Element();
|
||||
element.setKey(resultSet.getString(1));
|
||||
element.setSubkey(resultSet.getString(2));
|
||||
element.setSize(resultSet.getLong(3));
|
||||
element.setDigest(resultSet.getString(4));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setValue(resultSet.getString(8));
|
||||
element.setValue(resultSet.getString(3));
|
||||
element.setSize(resultSet.getLong(4));
|
||||
element.setDigest(resultSet.getString(5));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
|
||||
//
|
||||
result.add(element);
|
||||
|
@ -1080,7 +1084,7 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY CREATION_DATE ASC");
|
||||
.prepareStatement("SELECT TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY CREATION_DATE ASC");
|
||||
statement.setString(1, key);
|
||||
statement.setString(2, subkey);
|
||||
resultSet = statement.executeQuery();
|
||||
|
@ -1090,12 +1094,12 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
Element element = new Element();
|
||||
element.setKey(resultSet.getString(1));
|
||||
element.setSubkey(resultSet.getString(2));
|
||||
element.setSize(resultSet.getLong(3));
|
||||
element.setDigest(resultSet.getString(4));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(5)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setValue(resultSet.getString(8));
|
||||
element.setValue(resultSet.getString(3));
|
||||
element.setSize(resultSet.getLong(4));
|
||||
element.setDigest(resultSet.getString(5));
|
||||
element.setCreationDate(dateToDate(resultSet.getDate(6)));
|
||||
element.setEditionDate(dateToDate(resultSet.getDate(7)));
|
||||
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
|
||||
|
||||
//
|
||||
result.add(element);
|
||||
|
@ -1544,11 +1548,18 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
|
||||
//
|
||||
if (this.url != null) {
|
||||
//
|
||||
Class.forName(this.driverClassname).newInstance();
|
||||
this.singleConnection = DriverManager.getConnection(this.url, this.login, this.password);
|
||||
logger.info("Single connection opened with [{}].", this.url);
|
||||
|
||||
} else if (this.contextName != null) {
|
||||
//
|
||||
Context initialContext = new InitialContext();
|
||||
this.dataSource = (DataSource) initialContext.lookup(this.contextName);
|
||||
Context environmentContext = (Context) initialContext.lookup("java:comp/env");
|
||||
this.dataSource = (DataSource) environmentContext.lookup(this.contextName);
|
||||
logger.info("Database {} opened.", this.contextName);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Undefined source.");
|
||||
}
|
||||
|
@ -1567,16 +1578,16 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
connection = getConnection();
|
||||
connection.setAutoCommit(true);
|
||||
statement = connection
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setString(1, element.getKey());
|
||||
statement.setString(2, element.getSubkey());
|
||||
statement.setLong(3, element.getSize());
|
||||
statement.setString(4, element.getDigest());
|
||||
statement.setDate(5, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(6, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||
statement.setString(8, element.getValue());
|
||||
statement.setString(3, element.getValue());
|
||||
statement.setLong(4, element.getSize());
|
||||
statement.setString(5, element.getDigest());
|
||||
statement.setDate(6, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(7, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(8, dateToDate(element.getArchiveDate()));
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
|
@ -1627,16 +1638,16 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
// Insert new version of the element.
|
||||
statement.clearParameters();
|
||||
statement = connection
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setString(1, element.getKey());
|
||||
statement.setString(2, element.getSubkey());
|
||||
statement.setLong(3, element.getSize());
|
||||
statement.setString(4, element.getDigest());
|
||||
statement.setDate(5, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(6, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||
statement.setString(8, element.getValue());
|
||||
statement.setString(3, element.getValue());
|
||||
statement.setLong(4, element.getSize());
|
||||
statement.setString(5, element.getDigest());
|
||||
statement.setDate(6, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(7, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(8, dateToDate(element.getArchiveDate()));
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
|
@ -1697,16 +1708,16 @@ public class SQLSikevaDB implements SikevaDB {
|
|||
// Insert new version of the element.
|
||||
statement.clearParameters();
|
||||
statement = connection
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE,VALUE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
.prepareStatement("INSERT INTO elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setString(1, element.getKey());
|
||||
statement.setString(2, element.getSubkey());
|
||||
statement.setLong(3, element.getSize());
|
||||
statement.setString(4, element.getDigest());
|
||||
statement.setDate(5, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(6, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(7, dateToDate(element.getArchiveDate()));
|
||||
statement.setString(8, element.getValue());
|
||||
statement.setString(3, element.getValue());
|
||||
statement.setLong(4, element.getSize());
|
||||
statement.setString(5, element.getDigest());
|
||||
statement.setDate(6, dateToDate(element.getCreationDate()));
|
||||
statement.setDate(7, dateToDate(element.getEditionDate()));
|
||||
statement.setDate(8, dateToDate(element.getArchiveDate()));
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue