Refactored code: added database status check in methods, replaced

NullPointerException with IllegarlArgumentException, fixed SQL create
method, improved code…
This commit is contained in:
Christian P. MOMON 2018-02-28 15:50:48 +01:00
parent 615cc5e908
commit 280e8c7a57
6 changed files with 1523 additions and 1417 deletions

View file

@ -22,23 +22,23 @@ package fr.devinsy.sikevadb.core;
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
public class UnopenedDatabaseException extends SikevaDBException
public class ClosedDatabaseException extends SikevaDBException
{
private static final long serialVersionUID = 8364599416669077052L;
/**
*
*/
public UnopenedDatabaseException()
public ClosedDatabaseException()
{
super();
super("Invalid database status for this operation: closed.");
}
/**
*
* @param message
*/
public UnopenedDatabaseException(final String message)
public ClosedDatabaseException(final String message)
{
super(message);
}
@ -48,7 +48,7 @@ public class UnopenedDatabaseException extends SikevaDBException
* @param message
* @param cause
*/
public UnopenedDatabaseException(final String message, final Throwable cause)
public ClosedDatabaseException(final String message, final Throwable cause)
{
super(message, cause);
}
@ -57,7 +57,7 @@ public class UnopenedDatabaseException extends SikevaDBException
*
* @param cause
*/
public UnopenedDatabaseException(final Throwable cause)
public ClosedDatabaseException(final Throwable cause)
{
super(cause);
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of SikevaDB, simple key value database.
*
* SikevaDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* SikevaDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SikevaDB. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.sikevadb.core;
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
public class OpenedDatabaseException extends SikevaDBException
{
private static final long serialVersionUID = 8364599416669077052L;
/**
*
*/
public OpenedDatabaseException()
{
super("Invalid database status for this operation: opened.");
}
/**
*
* @param message
*/
public OpenedDatabaseException(final String message)
{
super(message);
}
/**
*
* @param message
* @param cause
*/
public OpenedDatabaseException(final String message, final Throwable cause)
{
super(message, cause);
}
/**
*
* @param cause
*/
public OpenedDatabaseException(final Throwable cause)
{
super(cause);
}
}

View file

@ -81,11 +81,11 @@ public class XMLSikevaDB
{
if (out == null)
{
throw new NullPointerException("out is null.");
throw new IllegalArgumentException("out is null.");
}
else if (source == null)
{
throw new NullPointerException("source is null.");
throw new IllegalArgumentException("source is null.");
}
else if (fileName == null)
{
@ -249,11 +249,11 @@ public class XMLSikevaDB
if (out == null)
{
throw new NullPointerException("out is null.");
throw new IllegalArgumentException("out is null.");
}
else if (source == null)
{
throw new NullPointerException("element is null.");
throw new IllegalArgumentException("element is null.");
}
else
{
@ -307,7 +307,7 @@ public class XMLSikevaDB
{
if (out == null)
{
throw new NullPointerException("out is null.");
throw new IllegalArgumentException("out is null.");
}
else if (source == null)
{

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -701,7 +701,7 @@ public class SQLSikevaDBTest
// "12345678");
database = new SQLSikevaDB("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:sikevadb-unittest;sql.syntax_mys=true", "sa", "");
database.open();
database.create();
database.open();
}
}