diff --git a/pom.xml b/pom.xml
index e3c745ba7..fbf0b0e47 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
WaarpR66
Waarp OpenR66
- 3.1.0
+ 3.1.1
OpenR66 is a File Transfer Monitor to be used in real production to transfer files between servers.
It allows to start/restart a transfer, check the remote MD5, check status, make pre or post
@@ -75,7 +75,7 @@
Waarp
WaarpCommon
- 3.1.0
+ 3.1.1
xml-apis
@@ -115,13 +115,13 @@
Waarp
WaarpExec
- 3.0.5
+ 3.1.0
true
Waarp
WaarpSnmp
- 3.0.7
+ 3.1.0
true
@@ -137,7 +137,7 @@
Waarp
WaarpThrift
- 3.0.7
+ 3.1.0
true
@@ -167,12 +167,12 @@
Waarp
WaarpGatewayKernel
- 3.1.0
+ 3.1.1
Waarp
WaarpFtpClient
- 3.0.7
+ 3.1.0
junit
diff --git a/src/main/java/org/waarp/openr66/client/AbstractTransfer.java b/src/main/java/org/waarp/openr66/client/AbstractTransfer.java
index ae449d2a9..4609e01ee 100644
--- a/src/main/java/org/waarp/openr66/client/AbstractTransfer.java
+++ b/src/main/java/org/waarp/openr66/client/AbstractTransfer.java
@@ -21,7 +21,9 @@
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import org.waarp.common.command.exception.CommandAbstractException;
import org.waarp.common.database.data.AbstractDbData.UpdatedInfo;
@@ -34,6 +36,7 @@
import org.waarp.openr66.context.ErrorCode;
import org.waarp.openr66.context.R66Result;
import org.waarp.openr66.context.R66Session;
+import org.waarp.openr66.context.filesystem.R66Dir;
import org.waarp.openr66.context.filesystem.R66File;
import org.waarp.openr66.context.task.exception.OpenR66RunnerErrorException;
import org.waarp.openr66.database.DbConstant;
@@ -43,7 +46,10 @@
import org.waarp.openr66.protocol.configuration.Messages;
import org.waarp.openr66.protocol.configuration.PartnerConfiguration;
import org.waarp.openr66.protocol.exception.OpenR66DatabaseGlobalException;
+import org.waarp.openr66.protocol.localhandler.packet.InformationPacket;
import org.waarp.openr66.protocol.localhandler.packet.RequestPacket;
+import org.waarp.openr66.protocol.localhandler.packet.ValidPacket;
+import org.waarp.openr66.protocol.networkhandler.NetworkTransaction;
import org.waarp.openr66.protocol.utils.FileUtils;
import org.waarp.openr66.protocol.utils.R66Future;
@@ -340,4 +346,72 @@ protected void finalizeInErrorTransferRequest(ClientRunner runner, DbTaskRunner
runner.changeUpdatedInfo(UpdatedInfo.INERROR, code, true);
}
}
+
+
+ public List getRemoteFiles(DbRule dbrule, String[] localfilenames, String requested,
+ NetworkTransaction networkTransaction) {
+ List files = new ArrayList();
+ for (String filename : localfilenames) {
+ if (!(filename.contains("*") || filename.contains("?") || filename.contains("~"))) {
+ files.add(filename);
+ } else {
+ // remote query
+ R66Future futureInfo = new R66Future(true);
+ logger.info(Messages.getString("Transfer.3") + filename + " to " + requested); //$NON-NLS-1$
+ RequestInformation info = new RequestInformation(
+ futureInfo, requested, rulename, filename,
+ (byte) InformationPacket.ASKENUM.ASKLIST.ordinal(), -1, false, networkTransaction);
+ info.run();
+ futureInfo.awaitUninterruptibly();
+ if (futureInfo.isSuccess()) {
+ ValidPacket valid = (ValidPacket) futureInfo.getResult().getOther();
+ if (valid != null) {
+ String line = valid.getSheader();
+ String[] lines = line.split("\n");
+ for (String string : lines) {
+ File tmpFile = new File(string);
+ files.add(tmpFile.getPath());
+ }
+ }
+ } else {
+ logger.error(Messages.getString("Transfer.6") + filename + " to " + requested + ": " +
+ (futureInfo.getCause() == null ? "" : futureInfo.getCause().getMessage())); //$NON-NLS-1$
+ }
+ }
+ }
+ return files;
+ }
+
+ public List getLocalFiles(DbRule dbrule, String[] localfilenames) {
+ List files = new ArrayList();
+ R66Session session = new R66Session();
+ session.getAuth().specialNoSessionAuth(false, Configuration.configuration.getHOST_ID());
+ R66Dir dir = new R66Dir(session);
+ try {
+ dir.changeDirectory(dbrule.getSendPath());
+ } catch (CommandAbstractException e) {
+ }
+ if (localfilenames != null) {
+ for (String filename : localfilenames) {
+ if (!(filename.contains("*") || filename.contains("?") || filename.contains("~"))) {
+ logger.info("Direct add: " + filename);
+ files.add(filename);
+ } else {
+ // local: must check
+ logger.info("Local Ask for " + filename + " from " + dir.getFullPath());
+ List list;
+ try {
+ list = dir.list(filename);
+ if (list != null) {
+ files.addAll(list);
+ }
+ } catch (CommandAbstractException e) {
+ logger.warn(Messages.getString("Transfer.14") + filename + " : " + e.getMessage()); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ return files;
+ }
+
}
diff --git a/src/main/java/org/waarp/openr66/client/MultipleDirectTransfer.java b/src/main/java/org/waarp/openr66/client/MultipleDirectTransfer.java
index a34dc4978..2ee6350d6 100644
--- a/src/main/java/org/waarp/openr66/client/MultipleDirectTransfer.java
+++ b/src/main/java/org/waarp/openr66/client/MultipleDirectTransfer.java
@@ -17,11 +17,9 @@
*/
package org.waarp.openr66.client;
-import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import org.waarp.common.command.exception.CommandAbstractException;
import org.waarp.common.database.exception.WaarpDatabaseException;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
@@ -30,14 +28,10 @@
import org.waarp.openr66.client.utils.OutputFormat.FIELDS;
import org.waarp.openr66.context.ErrorCode;
import org.waarp.openr66.context.R66Result;
-import org.waarp.openr66.context.R66Session;
-import org.waarp.openr66.context.filesystem.R66Dir;
import org.waarp.openr66.database.DbConstant;
import org.waarp.openr66.database.data.DbRule;
import org.waarp.openr66.protocol.configuration.Configuration;
import org.waarp.openr66.protocol.configuration.Messages;
-import org.waarp.openr66.protocol.localhandler.packet.InformationPacket;
-import org.waarp.openr66.protocol.localhandler.packet.ValidPacket;
import org.waarp.openr66.protocol.networkhandler.NetworkTransaction;
import org.waarp.openr66.protocol.utils.ChannelUtils;
import org.waarp.openr66.protocol.utils.R66Future;
@@ -72,71 +66,6 @@ public MultipleDirectTransfer(R66Future future, String remoteHost,
super(future, remoteHost, filename, rulename, fileinfo, isMD5, blocksize, id, networkTransaction);
}
- public static List getRemoteFiles(DbRule dbrule, String[] localfilenames, String requested,
- NetworkTransaction networkTransaction) {
- List files = new ArrayList();
- for (String filename : localfilenames) {
- if (!(filename.contains("*") || filename.contains("?") || filename.contains("~"))) {
- files.add(filename);
- } else {
- // remote query
- R66Future futureInfo = new R66Future(true);
- logger.info(Messages.getString("Transfer.3") + filename + " to " + requested); //$NON-NLS-1$
- RequestInformation info = new RequestInformation(futureInfo, requested, rule, filename,
- (byte) InformationPacket.ASKENUM.ASKLIST.ordinal(), -1, false, networkTransaction);
- info.run();
- futureInfo.awaitUninterruptibly();
- if (futureInfo.isSuccess()) {
- ValidPacket valid = (ValidPacket) futureInfo.getResult().getOther();
- if (valid != null) {
- String line = valid.getSheader();
- String[] lines = line.split("\n");
- for (String string : lines) {
- File tmpFile = new File(string);
- files.add(tmpFile.getPath());
- }
- }
- } else {
- logger.error(Messages.getString("Transfer.6") + filename + " to " + requested + ": " +
- (futureInfo.getCause() == null ? "" : futureInfo.getCause().getMessage())); //$NON-NLS-1$
- }
- }
- }
- return files;
- }
-
- public static List getLocalFiles(DbRule dbrule, String[] localfilenames) {
- List files = new ArrayList();
- R66Session session = new R66Session();
- session.getAuth().specialNoSessionAuth(false, Configuration.configuration.getHOST_ID());
- R66Dir dir = new R66Dir(session);
- try {
- dir.changeDirectory(dbrule.getSendPath());
- } catch (CommandAbstractException e) {
- }
- if (localfilenames != null) {
- for (String filename : localfilenames) {
- if (!(filename.contains("*") || filename.contains("?") || filename.contains("~"))) {
- logger.info("Direct add: " + filename);
- files.add(filename);
- } else {
- // local: must check
- logger.info("Local Ask for " + filename + " from " + dir.getFullPath());
- List list;
- try {
- list = dir.list(filename);
- if (list != null) {
- files.addAll(list);
- }
- } catch (CommandAbstractException e) {
- logger.warn(Messages.getString("Transfer.14") + filename + " : " + e.getMessage()); //$NON-NLS-1$
- }
- }
- }
- }
- return files;
- }
-
@Override
public void run() {
String[] localfilenames = filename.split(",");
@@ -169,7 +98,7 @@ public void run() {
long time1 = System.currentTimeMillis();
R66Future future = new R66Future(true);
DirectTransfer transaction = new DirectTransfer(future,
- host, filename, rule, fileInfo, ismd5, block, idt,
+ host, filename, rulename, fileinfo, isMD5, blocksize, id,
networkTransaction);
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.debug("rhost: " + host + ":" + transaction.remoteHost);
diff --git a/src/main/java/org/waarp/openr66/client/MultipleSubmitTransfer.java b/src/main/java/org/waarp/openr66/client/MultipleSubmitTransfer.java
index 722ffed14..6d2feee0b 100644
--- a/src/main/java/org/waarp/openr66/client/MultipleSubmitTransfer.java
+++ b/src/main/java/org/waarp/openr66/client/MultipleSubmitTransfer.java
@@ -83,7 +83,7 @@ public void run() {
try {
dbrule = new DbRule(rulename);
} catch (WaarpDatabaseException e) {
- logger.error(Messages.getString("SubmitTransfer.2") + rule); //$NON-NLS-1$
+ logger.error(Messages.getString("SubmitTransfer.2") + rulename); //$NON-NLS-1$
if (DetectionUtils.isJunit()) {
return;
}
@@ -100,7 +100,7 @@ public void run() {
}
List files = null;
if (dbrule.isSendMode()) {
- files = MultipleDirectTransfer.getLocalFiles(dbrule, localfilenames);
+ files = getLocalFiles(dbrule, localfilenames);
} else if (submit) {
files = new ArrayList();
for (String string : localfilenames) {
@@ -111,15 +111,15 @@ public void run() {
host = host.trim();
if (host != null && !host.isEmpty()) {
if (!submit && dbrule.isRecvMode()) {
- files = MultipleDirectTransfer.getRemoteFiles(dbrule, localfilenames, host, networkTransaction);
+ files = getRemoteFiles(dbrule, localfilenames, host, networkTransaction);
}
for (String filename : files) {
filename = filename.trim();
if (filename != null && !filename.isEmpty()) {
R66Future future = new R66Future(true);
- SubmitTransfer transaction = new SubmitTransfer(future,
- host, filename, rule, fileInfo, ismd5, block, idt,
- ttimestart);
+ SubmitTransfer transaction = new SubmitTransfer(
+ future, host, filename, rulename, fileinfo,
+ isMD5, blocksize, id, startTime);
transaction.normalInfoAsWarn = normalInfoAsWarn;
transaction.run();
future.awaitUninterruptibly();
diff --git a/src/main/java/org/waarp/openr66/client/RequestTransfer.java b/src/main/java/org/waarp/openr66/client/RequestTransfer.java
index 5dca54fee..03e82d48f 100644
--- a/src/main/java/org/waarp/openr66/client/RequestTransfer.java
+++ b/src/main/java/org/waarp/openr66/client/RequestTransfer.java
@@ -231,148 +231,223 @@ public RequestTransfer(R66Future future, long specialId, String requested, Strin
}
public void run() {
- if (logger == null) {
- logger = WaarpLoggerFactory.getLogger(RequestTransfer.class);
- }
DbTaskRunner runner = null;
try {
- runner = new DbTaskRunner(null, null,
- specialId, requester, requested);
- logger.info("Found previous Runner: " + runner.toString());
- } catch (WaarpDatabaseException e) {
- // Maybe we can ask to the remote
- R66Future futureInfo = new R66Future(true);
- RequestInformation requestInformation = new RequestInformation(futureInfo, requested, null, null,
- (byte) -1, specialId, true, networkTransaction);
- requestInformation.normalInfoAsWarn = normalInfoAsWarn;
- requestInformation.run();
- futureInfo.awaitUninterruptibly();
- if (futureInfo.isSuccess()) {
- R66Result r66result = futureInfo.getResult();
- ValidPacket info = (ValidPacket) r66result.getOther();
- String xml = info.getSheader();
- try {
- runner = DbTaskRunner.fromStringXml(xml, true);
- runner.changeUpdatedInfo(UpdatedInfo.TOSUBMIT);
- // useful ?
- CommanderNoDb.todoList.add(runner);
+ if (logger == null) {
+ logger = WaarpLoggerFactory.getLogger(RequestTransfer.class);
+ }
+ try {
+ runner = new DbTaskRunner(null, null,
+ specialId, requester, requested);
+ logger.info("Found previous Runner: " + runner.toString());
+ } catch (WaarpDatabaseException e) {
+ // Maybe we can ask to the remote
+ R66Future futureInfo = new R66Future(true);
+ RequestInformation requestInformation =
+ new RequestInformation(futureInfo, requested, null, null,
+ (byte) -1, specialId, true,
+ networkTransaction);
+ requestInformation.normalInfoAsWarn = normalInfoAsWarn;
+ requestInformation.run();
+ futureInfo.awaitUninterruptibly();
+ if (futureInfo.isSuccess()) {
+ R66Result r66result = futureInfo.getResult();
+ ValidPacket info = (ValidPacket) r66result.getOther();
+ String xml = info.getSheader();
+ try {
+ runner = DbTaskRunner.fromStringXml(xml, true);
+ runner.changeUpdatedInfo(UpdatedInfo.TOSUBMIT);
+ // useful ?
+ CommanderNoDb.todoList.add(runner);
- logger.info("Get Runner from remote: " + runner.toString());
- if (runner.getSpecialId() == DbConstant.ILLEGALVALUE || !runner.isSender()) {
- logger.error(Messages.getString("RequestTransfer.18")); //$NON-NLS-1$
- future.setResult(new R66Result(new OpenR66DatabaseGlobalException(e), null, true,
+ logger.info(
+ "Get Runner from remote: " + runner.toString());
+ if (runner.getSpecialId() == DbConstant.ILLEGALVALUE ||
+ !runner.isSender()) {
+ logger.error(Messages.getString(
+ "RequestTransfer.18")); //$NON-NLS-1$
+ future.setResult(new R66Result(
+ new OpenR66DatabaseGlobalException(e), null,
+ true,
ErrorCode.Internal, null));
- future.setFailure(e);
- return;
- }
- if (runner.isAllDone()) {
- logger.error(Messages.getString("RequestTransfer.21")); //$NON-NLS-1$
- future.setResult(new R66Result(new OpenR66DatabaseGlobalException(e), null, true,
+ future.setFailure(e);
+ return;
+ }
+ if (runner.isAllDone()) {
+ logger.error(Messages.getString(
+ "RequestTransfer.21")); //$NON-NLS-1$
+ future.setResult(new R66Result(
+ new OpenR66DatabaseGlobalException(e), null,
+ true,
ErrorCode.Internal, null));
+ future.setFailure(e);
+ return;
+ }
+ } catch (OpenR66ProtocolBusinessException e1) {
+ logger.error(Messages.getString(
+ "RequestTransfer.18")); //$NON-NLS-1$
+ future.setResult(new R66Result(
+ new OpenR66DatabaseGlobalException(e1), null, true,
+ ErrorCode.Internal, null));
future.setFailure(e);
return;
}
- } catch (OpenR66ProtocolBusinessException e1) {
- logger.error(Messages.getString("RequestTransfer.18")); //$NON-NLS-1$
- future.setResult(new R66Result(new OpenR66DatabaseGlobalException(e1), null, true,
- ErrorCode.Internal, null));
+ } else {
+ logger.error(
+ Messages.getString("RequestTransfer.18")); //$NON-NLS-1$
+ future.setResult(
+ new R66Result(new OpenR66DatabaseGlobalException(e),
+ null, true,
+ ErrorCode.Internal, null));
future.setFailure(e);
return;
}
- } else {
- logger.error(Messages.getString("RequestTransfer.18")); //$NON-NLS-1$
- future.setResult(new R66Result(new OpenR66DatabaseGlobalException(e), null, true,
- ErrorCode.Internal, null));
- future.setFailure(e);
- return;
}
- }
- if (cancel || stop || restart) {
- if (cancel) {
- // Cancel the task and delete any file if in retrieve
- if (runner.isAllDone()) {
- // nothing to do since already finished
- setDone(runner);
- logger.info("Transfer already finished: " + runner.toString());
- future.setResult(new R66Result(null, true, ErrorCode.TransferOk, runner));
- future.getResult().setRunner(runner);
- future.setSuccess();
- return;
- } else {
- // Send a request of cancel
- ErrorCode code = sendStopOrCancel(runner, LocalPacketFactory.CANCELPACKET);
- switch (code) {
+ if (cancel || stop || restart) {
+ if (cancel) {
+ // Cancel the task and delete any file if in retrieve
+ if (runner.isAllDone()) {
+ // nothing to do since already finished
+ setDone(runner);
+ logger.info(
+ "Transfer already finished: " + runner.toString());
+ future.setResult(
+ new R66Result(null, true, ErrorCode.TransferOk,
+ runner));
+ future.getResult().setRunner(runner);
+ future.setSuccess();
+ return;
+ } else {
+ // Send a request of cancel
+ ErrorCode code = sendStopOrCancel(runner,
+ LocalPacketFactory.CANCELPACKET);
+ future.setResult(
+ new R66Result(null, true, code,
+ runner));
+ future.getResult().setRunner(runner);
+ switch (code) {
case CompleteOk:
- logger.info("Transfer cancel requested and done: {}",
- runner);
+ logger
+ .info("Transfer cancel requested and done: {}",
+ runner);
+ future.setSuccess();
break;
case TransferOk:
- logger.info("Transfer cancel requested but already finished: {}",
- runner);
+ logger.info(
+ "Transfer cancel requested but already finished: {}",
+ runner);
+ future.setSuccess();
break;
default:
- logger.info("Transfer cancel requested but internal error: {}",
- runner);
+ logger.info(
+ "Transfer cancel requested but internal error: {}",
+ runner);
+ future.setFailure(new WaarpDatabaseException("Transfer cancel requested but internal error"));
break;
+ }
}
- }
- } else if (stop) {
- // Just stop the task
- // Send a request
- ErrorCode code = sendStopOrCancel(runner, LocalPacketFactory.STOPPACKET);
- switch (code) {
+ } else if (stop) {
+ // Just stop the task
+ // Send a request
+ ErrorCode code =
+ sendStopOrCancel(runner, LocalPacketFactory.STOPPACKET);
+ future.setResult(
+ new R66Result(null, true, code,
+ runner));
+ future.getResult().setRunner(runner);
+ switch (code) {
case CompleteOk:
- logger.info("Transfer stop requested and done: {}", runner);
+ logger.info("Transfer stop requested and done: {}",
+ runner);
+ future.setSuccess();
break;
case TransferOk:
- logger.info("Transfer stop requested but already finished: {}",
- runner);
+ logger.info(
+ "Transfer stop requested but already finished: {}",
+ runner);
+ future.setSuccess();
break;
default:
- logger.info("Transfer stop requested but internal error: {}",
- runner);
+ logger.info(
+ "Transfer stop requested but internal error: {}",
+ runner);
+ future.setFailure(new WaarpDatabaseException("Transfer stop requested but internal error"));
break;
- }
- } else if (restart) {
- // Restart if already stopped and not finished
- ErrorCode code = sendValid(runner, LocalPacketFactory.VALIDPACKET);
- switch (code) {
+ }
+ } else if (restart) {
+ // Restart if already stopped and not finished
+ ErrorCode code =
+ sendValid(runner, LocalPacketFactory.VALIDPACKET);
+ future.setResult(
+ new R66Result(null, true, code,
+ runner));
+ future.getResult().setRunner(runner);
+ switch (code) {
case QueryStillRunning:
logger.info(
- "Transfer restart requested but already active and running: {}",
- runner);
+ "Transfer restart requested but already active and running: {}",
+ runner);
+ future.setSuccess();
break;
case Running:
- logger.info("Transfer restart requested but already running: {}",
- runner);
+ logger.info(
+ "Transfer restart requested but already running: {}",
+ runner);
+ future.setSuccess();
break;
case PreProcessingOk:
- logger.info("Transfer restart requested and restarted: {}",
- runner);
+ logger.info(
+ "Transfer restart requested and restarted: {}",
+ runner);
+ future.setSuccess();
break;
case CompleteOk:
- logger.info("Transfer restart requested but already finished: {}",
- runner);
+ logger.info(
+ "Transfer restart requested but already finished: {}",
+ runner);
+ future.setSuccess();
break;
case RemoteError:
- logger.info("Transfer restart requested but remote error: {}",
- runner);
+ logger.info(
+ "Transfer restart requested but remote error: {}",
+ runner);
+ future.setSuccess();
break;
case PassThroughMode:
- logger.info("Transfer not restarted since it is in PassThrough mode: {}",
- runner);
+ logger.info(
+ "Transfer not restarted since it is in PassThrough mode: {}",
+ runner);
+ future.setSuccess();
break;
default:
- logger.info("Transfer restart requested but internal error: {}",
- runner);
+ logger.info(
+ "Transfer restart requested but internal error: {}",
+ runner);
+ future.setFailure(new WaarpDatabaseException("Transfer restart requested but internal error"));
break;
+ }
+ }
+ } else {
+ // Only request
+ logger.info(
+ "Transfer information: {} " + runner.toShortString(),
+ future.isDone());
+ future.setResult(
+ new R66Result(null, true, runner.getErrorInfo(), runner));
+ future.setSuccess();
+ }
+ } finally {
+ if (!future.isDone()) {
+ if (runner != null) {
+ // Default set to success
+ future.setResult(
+ new R66Result(null, true, runner.getErrorInfo(),
+ runner));
+ future.setSuccess();
+ } else {
+ future.setFailure(new WaarpDatabaseException("Transfer requested but internal error"));
}
}
- } else {
- // Only request
- logger.info("Transfer information: " + runner.toShortString());
- future.setResult(new R66Result(null, true, runner.getErrorInfo(), runner));
- future.setSuccess();
}
}
diff --git a/src/main/java/org/waarp/openr66/configuration/FileBasedConfiguration.java b/src/main/java/org/waarp/openr66/configuration/FileBasedConfiguration.java
index 500b4f9f7..95b72c54b 100644
--- a/src/main/java/org/waarp/openr66/configuration/FileBasedConfiguration.java
+++ b/src/main/java/org/waarp/openr66/configuration/FileBasedConfiguration.java
@@ -1801,6 +1801,7 @@ private static boolean loadDatabase(Configuration config, boolean initdb) {
}
DbConstant.admin = new DbAdmin(); // no database support
DbConstant.noCommitAdmin = DbConstant.admin;
+ DAOFactory.initialize();
} else {
String dbdriver = value.getString();
value = hashConfig.get(XML_DBSERVER);
diff --git a/src/main/java/org/waarp/openr66/configuration/RuleFileBasedConfiguration.java b/src/main/java/org/waarp/openr66/configuration/RuleFileBasedConfiguration.java
index 348ee767d..7b9174c12 100644
--- a/src/main/java/org/waarp/openr66/configuration/RuleFileBasedConfiguration.java
+++ b/src/main/java/org/waarp/openr66/configuration/RuleFileBasedConfiguration.java
@@ -150,6 +150,7 @@ public static void importRules(File configDirectory)
File[] files = FileUtils.getFiles(configDirectory,
new ExtensionFilter(EXT_RULE));
for (File file : files) {
+ logger.info("Load rule from {}", file.getAbsolutePath());
DbRule rule = getFromFile(file);
logger.debug(rule.toString());
}
@@ -238,7 +239,8 @@ public static String[] getHostIds(XmlValue value) {
String[] idsArray = new String[0];
if (value == null || (value.getList() == null) || value.getList().isEmpty()) {
logger
- .info("Unable to find the Hostid for Rule, setting to the default");
+ .debug("Unable to find the Hostid for Rule, setting to " +
+ "the default");
} else {
@SuppressWarnings("unchecked")
List ids = (List) value.getList();
@@ -588,7 +590,9 @@ private static void addToElement(Element element, DbRule rule) {
task.add(newElement(DbRule.TASK_TYPE, array[rank][0]));
task.add(newElement(DbRule.TASK_PATH, array[rank][1]));
task.add(newElement(DbRule.TASK_DELAY, array[rank][2]));
- task.add(newElement(DbRule.TASK_COMMENT, array[rank][3]));
+ if (array[rank].length > 3) {
+ task.add(newElement(DbRule.TASK_COMMENT, array[rank][3]));
+ }
roottasks.add(task);
}
}
diff --git a/src/main/java/org/waarp/openr66/dao/BusinessDAO.java b/src/main/java/org/waarp/openr66/dao/BusinessDAO.java
index bdbc7d027..c09bcf9c8 100644
--- a/src/main/java/org/waarp/openr66/dao/BusinessDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/BusinessDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Business;
/**
@@ -13,27 +14,29 @@ public interface BusinessDAO {
/**
* Retrieve all Business objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all Business objects corresponding to the given filters
* in a List from the persistance layer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws DAOConnectionException;
/**
* Retrieve the Business object with the specified hostid from the
* persistance layer
*
* @param hostid Hostid of the Business object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- Business select(String hostid) throws DAOException;
+ Business select(String hostid)
+ throws DAOConnectionException, DAONoDataException;
/**
* Verify if a Business object with the specified hostid exists in
@@ -42,40 +45,44 @@ public interface BusinessDAO {
* @param hostid Hostid of the Business object verified
* @return true if a Business object with the specified hostid exist; false
* if no Business object correspond to the specified hostid.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- boolean exist(String hostid) throws DAOException;
+ boolean exist(String hostid) throws DAOConnectionException;
/**
* Insert the specified Business object in the persistance layer
*
* @param business Business object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(Business business) throws DAOException;
+ void insert(Business business) throws DAOConnectionException;
/**
* Update the specified Business object in the persistance layer
*
* @param business Business object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(Business business) throws DAOException;
+ void update(Business business)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified Business object from the persistance layer
*
* @param business Business object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(Business business) throws DAOException;
+ void delete(Business business)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove all Business objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/DAOFactory.java b/src/main/java/org/waarp/openr66/dao/DAOFactory.java
index 707155054..91cf827b7 100644
--- a/src/main/java/org/waarp/openr66/dao/DAOFactory.java
+++ b/src/main/java/org/waarp/openr66/dao/DAOFactory.java
@@ -1,8 +1,9 @@
package org.waarp.openr66.dao;
import org.waarp.common.database.ConnectionFactory;
+import org.waarp.common.utility.DetectionUtils;
import org.waarp.openr66.dao.database.DBDAOFactory;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
import org.waarp.openr66.dao.xml.XMLDAOFactory;
@@ -33,48 +34,48 @@ public static DAOFactory getInstance() {
* Return a BusinessDAO
*
* @return a ready to use BusinessDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
- public abstract BusinessDAO getBusinessDAO() throws DAOException;
+ public abstract BusinessDAO getBusinessDAO() throws DAOConnectionException;
/**
* Return a HostDAO
*
* @return a ready to use HostDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
- public abstract HostDAO getHostDAO() throws DAOException;
+ public abstract HostDAO getHostDAO() throws DAOConnectionException;
/**
* Return a LimitDAO
*
* @return a ready to use LimitDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
- public abstract LimitDAO getLimitDAO() throws DAOException;
+ public abstract LimitDAO getLimitDAO() throws DAOConnectionException;
/**
* Return a MultipleMonitorDAO
*
* @return a ready to use MultipleMonitorDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
public abstract MultipleMonitorDAO getMultipleMonitorDAO()
- throws DAOException;
+ throws DAOConnectionException;
/**
* Return a RuleDAO
*
* @return a ready to use RuleDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
- public abstract RuleDAO getRuleDAO() throws DAOException;
+ public abstract RuleDAO getRuleDAO() throws DAOConnectionException;
/**
* Return a TransferDAO
*
* @return a ready to use TramsferDAO
- * @throws DAOException if cannot create the DAO
+ * @throws DAOConnectionException if cannot create the DAO
*/
- public abstract TransferDAO getTransferDAO() throws DAOException;
+ public abstract TransferDAO getTransferDAO() throws DAOConnectionException;
}
diff --git a/src/main/java/org/waarp/openr66/dao/HostDAO.java b/src/main/java/org/waarp/openr66/dao/HostDAO.java
index 845847bdb..52006466b 100644
--- a/src/main/java/org/waarp/openr66/dao/HostDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/HostDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Host;
/**
@@ -13,25 +14,27 @@ public interface HostDAO {
/**
* Retrieve all Host objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all Host objects corresponding to the given filters
* in a List from the persistance lsayer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws DAOConnectionException;
/**
* Retrieve the Host object with the specified hostid from the persistance layer
*
* @param hostid Hostid of the Host object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- Host select(String hostid) throws DAOException;
+ Host select(String hostid) throws DAOConnectionException,
+ DAONoDataException;
/**
* Verify if a Host object with the specified hostid exists in
@@ -40,40 +43,42 @@ public interface HostDAO {
* @param hostid Hostid of the Host object verified
* @return true if a Host object with the specified hostid exist; false
* if no Host object correspond to the specified hostid.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- boolean exist(String hostid) throws DAOException;
+ boolean exist(String hostid) throws DAOConnectionException;
/**
* Insert the specified Host object in the persistance layer
*
* @param host Host object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(Host host) throws DAOException;
+ void insert(Host host) throws DAOConnectionException;
/**
* Update the specified Host object in the persistance layer
*
* @param host Host object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(Host host) throws DAOException;
+ void update(Host host) throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified Host object from the persistance layer
*
* @param host Host object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(Host host) throws DAOException;
+ void delete(Host host) throws DAOConnectionException, DAONoDataException;
/**
* Remove all Host objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/LimitDAO.java b/src/main/java/org/waarp/openr66/dao/LimitDAO.java
index d9e3fbb63..212953eca 100644
--- a/src/main/java/org/waarp/openr66/dao/LimitDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/LimitDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Limit;
/**
@@ -13,25 +14,27 @@ public interface LimitDAO {
/**
* Retrieve all Limit objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all Limit objects correspondig to the given filters
* in a List from the persistance layer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws DAOConnectionException;
/**
* Retrieve the Limit object with the specified hostid from the persistance layer
*
* @param hostid Hostid of the Limit object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- Limit select(String hostid) throws DAOException;
+ Limit select(String hostid)
+ throws DAOConnectionException, DAONoDataException;
/**
* Verify if a Limit object with the specified hostid exists in
@@ -40,40 +43,42 @@ public interface LimitDAO {
* @param hostid Hostid of the Limit object verified
* @return true if a Limit object with the specified hostid exist; false
* if no Limit object correspond to the specified hostid.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- boolean exist(String hostid) throws DAOException;
+ boolean exist(String hostid) throws DAOConnectionException;
/**
* Insert the specified Limit object in the persistance layer
*
* @param limit Limit object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(Limit limit) throws DAOException;
+ void insert(Limit limit) throws DAOConnectionException;
/**
* Update the specified Limit object in the persistance layer
*
* @param limit Limit object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(Limit limit) throws DAOException;
+ void update(Limit limit) throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified Limit object from the persistance layer
*
* @param limit Limit object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(Limit limit) throws DAOException;
+ void delete(Limit limit) throws DAOConnectionException, DAONoDataException;
/**
* Remove all Limit objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/MultipleMonitorDAO.java b/src/main/java/org/waarp/openr66/dao/MultipleMonitorDAO.java
index d3e634a19..34196cf17 100644
--- a/src/main/java/org/waarp/openr66/dao/MultipleMonitorDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/MultipleMonitorDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.MultipleMonitor;
/**
@@ -13,26 +14,29 @@ public interface MultipleMonitorDAO {
/**
* Retrieve all MultipleMonitor objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all MultipleMonitor objects corresponding to the given filters
* in a List from the persistance layer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws
+ DAOConnectionException;
/**
* Retrieve the MultipleMonitor object with the specified hostid from the persistance layer
*
* @param hostid Hostid of the MultipleMonitor object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- MultipleMonitor select(String hostid) throws DAOException;
+ MultipleMonitor select(String hostid)
+ throws DAOConnectionException, DAONoDataException;
/**
* Verify if a MultipleMonitor object with the specified hostid exists in
@@ -41,40 +45,44 @@ public interface MultipleMonitorDAO {
* @param hostid Hostid of the MultipleMonitor object verified
* @return true if a MultipleMonitor object with the specified hostid exist; false
* if no MultipleMonitor object correspond to the specified hostid.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- boolean exist(String hostid) throws DAOException;
+ boolean exist(String hostid) throws DAOConnectionException;
/**
* Insert the specified MultipleMonitor object in the persistance layer
*
* @param multipleMonitor MultipleMonitor object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(MultipleMonitor multipleMonitor) throws DAOException;
+ void insert(MultipleMonitor multipleMonitor) throws DAOConnectionException;
/**
* Update the specified MultipleMonitor object in the persistance layer
*
* @param multipleMonitor MultipleMonitor object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(MultipleMonitor multipleMonitor) throws DAOException;
+ void update(MultipleMonitor multipleMonitor)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified MultipleMonitor object from the persistance layer
*
* @param multipleMonitor MultipleMonitor object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(MultipleMonitor multipleMonitor) throws DAOException;
+ void delete(MultipleMonitor multipleMonitor)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove all MultipleMonitor objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/RuleDAO.java b/src/main/java/org/waarp/openr66/dao/RuleDAO.java
index f054c1d58..77d86b435 100644
--- a/src/main/java/org/waarp/openr66/dao/RuleDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/RuleDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Rule;
/**
@@ -13,27 +14,29 @@ public interface RuleDAO {
/**
* Retrieve all Rule objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all Rule objects corresponding to the given filters
* a List from the persistance layer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws DAOConnectionException;
/**
* Retrieve the Rule object with the specified Rulename from the
* persistance layer
*
* @param rulename rulename of the Rule object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- Rule select(String rulename) throws DAOException;
+ Rule select(String rulename)
+ throws DAOConnectionException, DAONoDataException;
/**
* Verify if a Rule object with the specified Rulename exists in
@@ -42,40 +45,42 @@ public interface RuleDAO {
* @param rulename rulename of the Rule object verified
* @return true if a Rule object with the specified Rulename exist; false
* if no Rule object correspond to the specified Rulename.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- boolean exist(String rulename) throws DAOException;
+ boolean exist(String rulename) throws DAOConnectionException;
/**
* Insert the specified Rule object in the persistance layer
*
* @param rule Rule object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(Rule rule) throws DAOException;
+ void insert(Rule rule) throws DAOConnectionException;
/**
* Update the specified Rule object in the persistance layer
*
* @param rule Rule object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(Rule rule) throws DAOException;
+ void update(Rule rule) throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified Rule object from the persistance layer
*
* @param rule Rule object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(Rule rule) throws DAOException;
+ void delete(Rule rule) throws DAOConnectionException, DAONoDataException;
/**
* Remove all Rule objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/TransferDAO.java b/src/main/java/org/waarp/openr66/dao/TransferDAO.java
index 711f110b0..68a43ebd8 100644
--- a/src/main/java/org/waarp/openr66/dao/TransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/TransferDAO.java
@@ -2,7 +2,8 @@
import java.util.List;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Transfer;
/**
@@ -13,43 +14,80 @@ public interface TransferDAO {
/**
* Retrieve all Transfer objects in a List from the persistance layer
*
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List getAll() throws DAOException;
+ List getAll() throws DAOConnectionException;
/**
* Retrieve all Transfer objects to the given filters
* in a List from the persistance layer
*
* @param filters List of filter
- * @throws DAOException If data access error occurs
+ * @throws DAOConnectionException If data access error occurs
*/
- List find(List filters) throws DAOException;
+ List find(List filters) throws DAOConnectionException;
- List find(List filters, int limit) throws DAOException;
+ /**
+ * Retrieve all Transfer objects to the given filters
+ * in a List from the persistance layer
+ *
+ * @param filters List of filter
+ * @throws DAOConnectionException If data access error occurs
+ */
+ List find(List filters, int limit) throws
+ DAOConnectionException;
+ /**
+ * Retrieve all Transfer objects to the given filters
+ * in a List from the persistance layer
+ *
+ * @param filters List of filter
+ * @throws DAOConnectionException If data access error occurs
+ */
List find(List filters, int limit, int offset)
- throws DAOException;
+ throws DAOConnectionException;
+ /**
+ * Retrieve all Transfer objects to the given filters
+ * in a List from the persistance layer
+ *
+ * @param filters List of filter
+ * @throws DAOConnectionException If data access error occurs
+ */
List find(List filters, String column, boolean ascend)
- throws DAOException;
+ throws DAOConnectionException;
+ /**
+ * Retrieve all Transfer objects to the given filters
+ * in a List from the persistance layer
+ *
+ * @param filters List of filter
+ * @throws DAOConnectionException If data access error occurs
+ */
List find(List filters, String column, boolean ascend,
- int limit) throws DAOException;
+ int limit) throws DAOConnectionException;
+ /**
+ * Retrieve all Transfer objects to the given filters
+ * in a List from the persistance layer
+ *
+ * @param filters List of filter
+ * @throws DAOConnectionException If data access error occurs
+ */
List find(List filters, String column, boolean ascend,
- int limit, int offset) throws DAOException;
+ int limit, int offset) throws DAOConnectionException;
/**
* Retrieve the Transfer object with the specified Special ID from the persistance layer
*
* @param id special ID of the Transfer object requested
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
Transfer select(long id, String requester, String requested, String owner)
- throws DAOException;
+ throws DAOConnectionException, DAONoDataException;
/**
* Verify if a Transfer object with the specified Special ID exists in
@@ -58,41 +96,45 @@ Transfer select(long id, String requester, String requested, String owner)
* @param id special ID of the Transfer object verified
* @return true if a Transfer object with the specified Special ID exist; false
* if no Transfer object correspond to the specified Special ID.
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
boolean exist(long id, String requester, String requested, String owner)
- throws DAOException;
+ throws DAOConnectionException;
/**
* Insert the specified Transfer object in the persistance layer
*
* @param transfer Transfer object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void insert(Transfer transfer) throws DAOException;
+ void insert(Transfer transfer) throws DAOConnectionException;
/**
* Update the specified Transfer object in the persistance layer
*
* @param transfer Transfer object to update
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void update(Transfer transfer) throws DAOException;
+ void update(Transfer transfer)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove the specified Transfer object from the persistance layer
*
* @param transfer Transfer object to insert
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
+ * @throws DAONoDataException if no data are available
*/
- void delete(Transfer transfer) throws DAOException;
+ void delete(Transfer transfer)
+ throws DAOConnectionException, DAONoDataException;
/**
* Remove all Transfer objects from the persistance layer
*
- * @throws DAOException If a data access error occurs
+ * @throws DAOConnectionException If a data access error occurs
*/
- void deleteAll() throws DAOException;
+ void deleteAll() throws DAOConnectionException;
void close();
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBBusinessDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBBusinessDAO.java
index 78dd2d2b8..18e1440a8 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBBusinessDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBBusinessDAO.java
@@ -12,7 +12,8 @@
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.BusinessDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Business;
import org.waarp.openr66.pojo.UpdatedInfo;
@@ -71,34 +72,39 @@ public void close() {
}
@Override
- public void delete(Business business) throws DAOException {
+ public void delete(Business business)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE);
setParameters(stm, business.getHostid());
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE_ALL);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList businesses = new ArrayList();
PreparedStatement stm = null;
ResultSet res = null;
@@ -109,7 +115,7 @@ public List getAll() throws DAOException {
businesses.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -118,7 +124,8 @@ public List getAll() throws DAOException {
}
@Override
- public List find(List filters) throws DAOException {
+ public List find(List filters) throws
+ DAOConnectionException {
ArrayList businesses = new ArrayList();
// Create the SQL query
StringBuilder query = new StringBuilder(SQL_GET_ALL);
@@ -148,7 +155,7 @@ public List find(List filters) throws DAOException {
businesses.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -157,7 +164,7 @@ public List find(List filters) throws DAOException {
}
@Override
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -166,7 +173,7 @@ public boolean exist(String hostid) throws DAOException {
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -174,7 +181,8 @@ public boolean exist(String hostid) throws DAOException {
}
@Override
- public Business select(String hostid) throws DAOException {
+ public Business select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -183,18 +191,19 @@ public Business select(String hostid) throws DAOException {
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
}
- return null;
}
@Override
- public void insert(Business business) throws DAOException {
+ public void insert(Business business) throws DAOConnectionException {
Object[] params = {
business.getHostid(),
business.getBusiness(),
@@ -210,14 +219,15 @@ public void insert(Business business) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(Business business) throws DAOException {
+ public void update(Business business)
+ throws DAOConnectionException, DAONoDataException {
Object[] params = {
business.getHostid(),
business.getBusiness(),
@@ -232,9 +242,13 @@ public void update(Business business) throws DAOException {
try {
stm = connection.prepareStatement(SQL_UPDATE);
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBDAOFactory.java b/src/main/java/org/waarp/openr66/dao/database/DBDAOFactory.java
index 5ad8c3dd7..929de96f8 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBDAOFactory.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBDAOFactory.java
@@ -11,7 +11,7 @@
import org.waarp.openr66.dao.database.mariadb.MariaDBTransferDAO;
import org.waarp.openr66.dao.database.oracle.OracleTransferDAO;
import org.waarp.openr66.dao.database.postgres.PostgreSQLTransferDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
/**
* DAOFactory for standard SQL databases
@@ -27,52 +27,53 @@ public DBDAOFactory(ConnectionFactory factory) {
}
@Override
- public DBBusinessDAO getBusinessDAO() throws DAOException {
+ public DBBusinessDAO getBusinessDAO() throws DAOConnectionException {
try {
return new DBBusinessDAO(connectionFactory.getConnection());
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
@Override
- public DBHostDAO getHostDAO() throws DAOException {
+ public DBHostDAO getHostDAO() throws DAOConnectionException {
try {
return new DBHostDAO(connectionFactory.getConnection());
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
@Override
- public DBLimitDAO getLimitDAO() throws DAOException {
+ public DBLimitDAO getLimitDAO() throws DAOConnectionException {
try {
return new DBLimitDAO(connectionFactory.getConnection());
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
@Override
- public DBMultipleMonitorDAO getMultipleMonitorDAO() throws DAOException {
+ public DBMultipleMonitorDAO getMultipleMonitorDAO() throws
+ DAOConnectionException {
try {
return new DBMultipleMonitorDAO(connectionFactory.getConnection());
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
@Override
- public DBRuleDAO getRuleDAO() throws DAOException {
+ public DBRuleDAO getRuleDAO() throws DAOConnectionException {
try {
return new DBRuleDAO(connectionFactory.getConnection());
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
@Override
- public DBTransferDAO getTransferDAO() throws DAOException {
+ public DBTransferDAO getTransferDAO() throws DAOConnectionException {
try {
DbProperties prop = connectionFactory.getProperties();
if (prop instanceof H2Properties) {
@@ -86,10 +87,10 @@ public DBTransferDAO getTransferDAO() throws DAOException {
} else if (prop instanceof PostgreSQLProperties) {
return new PostgreSQLTransferDAO(connectionFactory.getConnection());
} else {
- throw new DAOException("Unsupported database");
+ throw new DAOConnectionException("Unsupported database");
}
} catch (SQLException e) {
- throw new DAOException("data access error", e);
+ throw new DAOConnectionException("data access error", e);
}
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBHostDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBHostDAO.java
index 53b0ac058..9d6a41c78 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBHostDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBHostDAO.java
@@ -12,7 +12,8 @@
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.HostDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Host;
import org.waarp.openr66.pojo.UpdatedInfo;
@@ -69,7 +70,7 @@ public class DBHostDAO extends StatementExecutor implements HostDAO {
protected Connection connection;
- public DBHostDAO(Connection con) throws DAOException {
+ public DBHostDAO(Connection con) throws DAOConnectionException {
this.connection = con;
}
@@ -83,34 +84,39 @@ public void close() {
}
@Override
- public void delete(Host host) throws DAOException {
+ public void delete(Host host)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE);
setParameters(stm, host.getHostid());
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE_ALL);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList hosts = new ArrayList();
PreparedStatement stm = null;
ResultSet res = null;
@@ -121,7 +127,7 @@ public List getAll() throws DAOException {
hosts.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -130,7 +136,7 @@ public List getAll() throws DAOException {
}
@Override
- public List find(List filters) throws DAOException {
+ public List find(List filters) throws DAOConnectionException {
ArrayList hosts = new ArrayList();
// Create the SQL query
StringBuilder query = new StringBuilder(SQL_GET_ALL);
@@ -160,7 +166,7 @@ public List find(List filters) throws DAOException {
hosts.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -169,7 +175,7 @@ public List find(List filters) throws DAOException {
}
@Override
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -178,7 +184,7 @@ public boolean exist(String hostid) throws DAOException {
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -186,7 +192,8 @@ public boolean exist(String hostid) throws DAOException {
}
@Override
- public Host select(String hostid) throws DAOException {
+ public Host select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -195,18 +202,19 @@ public Host select(String hostid) throws DAOException {
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
}
- return null;
}
@Override
- public void insert(Host host) throws DAOException {
+ public void insert(Host host) throws DAOConnectionException {
Object[] params = {
host.getHostid(),
host.getAddress(),
@@ -226,14 +234,15 @@ public void insert(Host host) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(Host host) throws DAOException {
+ public void update(Host host)
+ throws DAOConnectionException, DAONoDataException {
Object[] params = {
host.getHostid(),
host.getAddress(),
@@ -252,9 +261,13 @@ public void update(Host host) throws DAOException {
try {
stm = connection.prepareStatement(SQL_UPDATE);
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBLimitDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBLimitDAO.java
index 9d4e4f922..8ffd69519 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBLimitDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBLimitDAO.java
@@ -12,7 +12,8 @@
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.LimitDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Limit;
import org.waarp.openr66.pojo.UpdatedInfo;
@@ -76,34 +77,39 @@ public void close() {
}
@Override
- public void delete(Limit limit) throws DAOException {
+ public void delete(Limit limit)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE);
setParameters(stm, limit.getHostid());
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE_ALL);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList limits = new ArrayList();
ResultSet res = null;
PreparedStatement stm = null;
@@ -114,7 +120,7 @@ public List getAll() throws DAOException {
limits.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
closeResultSet(res);
@@ -123,7 +129,8 @@ public List getAll() throws DAOException {
}
@Override
- public List find(List filters) throws DAOException {
+ public List find(List filters) throws
+ DAOConnectionException {
ArrayList limits = new ArrayList();
// Create the SQL query
StringBuilder query = new StringBuilder(SQL_GET_ALL);
@@ -153,7 +160,7 @@ public List find(List filters) throws DAOException {
limits.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
closeResultSet(res);
@@ -162,7 +169,7 @@ public List find(List filters) throws DAOException {
}
@Override
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -171,7 +178,7 @@ public boolean exist(String hostid) throws DAOException {
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
closeResultSet(res);
@@ -179,7 +186,8 @@ public boolean exist(String hostid) throws DAOException {
}
@Override
- public Limit select(String hostid) throws DAOException {
+ public Limit select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -188,18 +196,19 @@ public Limit select(String hostid) throws DAOException {
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
closeResultSet(res);
}
- return null;
}
@Override
- public void insert(Limit limit) throws DAOException {
+ public void insert(Limit limit) throws DAOConnectionException {
Object[] params = {
limit.getHostid(),
limit.getReadGlobalLimit(),
@@ -216,14 +225,15 @@ public void insert(Limit limit) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(Limit limit) throws DAOException {
+ public void update(Limit limit)
+ throws DAOConnectionException, DAONoDataException {
Object[] params = {
limit.getHostid(),
limit.getReadGlobalLimit(),
@@ -239,9 +249,13 @@ public void update(Limit limit) throws DAOException {
try {
stm = connection.prepareStatement(SQL_UPDATE);
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBMultipleMonitorDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBMultipleMonitorDAO.java
index 3aff4b635..17aa71207 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBMultipleMonitorDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBMultipleMonitorDAO.java
@@ -12,7 +12,8 @@
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.MultipleMonitorDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.MultipleMonitor;
/**
@@ -66,34 +67,40 @@ public void close() {
}
@Override
- public void delete(MultipleMonitor multipleMonitor) throws DAOException {
+ public void delete(MultipleMonitor multipleMonitor) throws
+ DAOConnectionException,
+ DAONoDataException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE);
setParameters(stm, multipleMonitor.getHostid());
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE_ALL);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList monitors = new ArrayList();
PreparedStatement stm = null;
ResultSet res = null;
@@ -104,7 +111,7 @@ public List getAll() throws DAOException {
monitors.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -114,7 +121,7 @@ public List getAll() throws DAOException {
@Override
public List find(List filters)
- throws DAOException {
+ throws DAOConnectionException {
ArrayList monitors = new ArrayList();
// Create the SQL query
StringBuilder query = new StringBuilder(SQL_GET_ALL);
@@ -144,7 +151,7 @@ public List find(List filters)
monitors.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -153,7 +160,7 @@ public List find(List filters)
}
@Override
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -162,7 +169,7 @@ public boolean exist(String hostid) throws DAOException {
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -170,7 +177,8 @@ public boolean exist(String hostid) throws DAOException {
}
@Override
- public MultipleMonitor select(String hostid) throws DAOException {
+ public MultipleMonitor select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -179,18 +187,20 @@ public MultipleMonitor select(String hostid) throws DAOException {
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
}
- return null;
}
@Override
- public void insert(MultipleMonitor multipleMonitor) throws DAOException {
+ public void insert(MultipleMonitor multipleMonitor) throws
+ DAOConnectionException {
Object[] params = {
multipleMonitor.getHostid(),
multipleMonitor.getCountConfig(),
@@ -204,14 +214,16 @@ public void insert(MultipleMonitor multipleMonitor) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(MultipleMonitor multipleMonitor) throws DAOException {
+ public void update(MultipleMonitor multipleMonitor) throws
+ DAOConnectionException,
+ DAONoDataException {
Object[] params = {
multipleMonitor.getHostid(),
multipleMonitor.getCountConfig(),
@@ -224,9 +236,13 @@ public void update(MultipleMonitor multipleMonitor) throws DAOException {
try {
stm = connection.prepareStatement(SQL_UPDATE);
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBRuleDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBRuleDAO.java
index 8f2cb3dd7..aac93621a 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBRuleDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBRuleDAO.java
@@ -17,13 +17,14 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.UpdatedInfo;
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.RuleDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
import org.waarp.openr66.pojo.Rule;
import org.waarp.openr66.pojo.RuleTask;
@@ -107,34 +108,39 @@ public void close() {
}
@Override
- public void delete(Rule rule) throws DAOException {
+ public void delete(Rule rule)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE);
setParameters(stm, rule.getName());
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(SQL_DELETE_ALL);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList rules = new ArrayList();
PreparedStatement stm = null;
ResultSet res = null;
@@ -145,7 +151,7 @@ public List getAll() throws DAOException {
rules.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -154,7 +160,7 @@ public List getAll() throws DAOException {
}
@Override
- public List find(List filters) throws DAOException {
+ public List find(List filters) throws DAOConnectionException {
ArrayList rules = new ArrayList();
// Create the SQL query
StringBuilder query = new StringBuilder(SQL_GET_ALL);
@@ -184,7 +190,7 @@ public List find(List filters) throws DAOException {
rules.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -193,7 +199,7 @@ public List find(List filters) throws DAOException {
}
@Override
- public boolean exist(String ruleName) throws DAOException {
+ public boolean exist(String ruleName) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -202,7 +208,7 @@ public boolean exist(String ruleName) throws DAOException {
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -210,7 +216,8 @@ public boolean exist(String ruleName) throws DAOException {
}
@Override
- public Rule select(String ruleName) throws DAOException {
+ public Rule select(String ruleName)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
try {
@@ -219,18 +226,19 @@ public Rule select(String ruleName) throws DAOException {
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
}
- return null;
}
@Override
- public void insert(Rule rule) throws DAOException {
+ public void insert(Rule rule) throws DAOConnectionException {
Object[] params = {
rule.getName(),
rule.getXMLHostids(),
@@ -254,14 +262,15 @@ public void insert(Rule rule) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(Rule rule) throws DAOException {
+ public void update(Rule rule)
+ throws DAOConnectionException, DAONoDataException {
Object[] params = {
rule.getName(),
rule.getXMLHostids(),
@@ -284,16 +293,20 @@ public void update(Rule rule) throws DAOException {
try {
stm = connection.prepareStatement(SQL_UPDATE);
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
protected Rule getFromResultSet(ResultSet set) throws SQLException,
- DAOException {
+ DAOConnectionException {
return new Rule(
set.getString(ID_FIELD),
set.getInt(MODE_TRANS_FIELD),
@@ -311,7 +324,8 @@ protected Rule getFromResultSet(ResultSet set) throws SQLException,
UpdatedInfo.valueOf(set.getInt(UPDATED_INFO_FIELD)));
}
- private List retrieveHostids(String xml) throws DAOException {
+ private List retrieveHostids(String xml) throws
+ DAOConnectionException {
ArrayList res = new ArrayList();
if ((xml == null) || xml.equals("")) {
return res;
@@ -322,7 +336,7 @@ private List retrieveHostids(String xml) throws DAOException {
document = DocumentBuilderFactory.newInstance().
newDocumentBuilder().parse(stream);
} catch (Exception e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
document.getDocumentElement().normalize();
@@ -333,7 +347,8 @@ private List retrieveHostids(String xml) throws DAOException {
return res;
}
- private List retrieveTasks(String xml) throws DAOException {
+ private List retrieveTasks(String xml) throws
+ DAOConnectionException {
ArrayList res = new ArrayList();
if ((xml == null) || xml.equals("")) {
return res;
@@ -344,7 +359,7 @@ private List retrieveTasks(String xml) throws DAOException {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(stream);
} catch (Exception e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
document.getDocumentElement().normalize();
diff --git a/src/main/java/org/waarp/openr66/dao/database/DBTransferDAO.java b/src/main/java/org/waarp/openr66/dao/database/DBTransferDAO.java
index d115ed145..759f5d9e9 100644
--- a/src/main/java/org/waarp/openr66/dao/database/DBTransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/DBTransferDAO.java
@@ -4,7 +4,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -12,13 +11,13 @@
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.context.ErrorCode;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.database.DbConstant;
import org.waarp.openr66.dao.TransferDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
import org.waarp.openr66.pojo.Transfer;
import org.waarp.openr66.pojo.UpdatedInfo;
-import org.waarp.openr66.protocol.configuration.Configuration;
/**
* Implementation of TransferDAO for a standard SQL database
@@ -159,7 +158,8 @@ public DBTransferDAO(Connection con) {
}
@Override
- public void delete(Transfer transfer) throws DAOException {
+ public void delete(Transfer transfer)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
Object[] params = {
transfer.getId(),
@@ -170,29 +170,33 @@ public void delete(Transfer transfer) throws DAOException {
try {
stm = connection.prepareStatement(getDeleteRequest());
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void deleteAll() throws DAOException {
+ public void deleteAll() throws DAOConnectionException {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement(getDeleteAllRequest());
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
ArrayList transfers = new ArrayList();
PreparedStatement stm = null;
ResultSet res = null;
@@ -203,7 +207,7 @@ public List getAll() throws DAOException {
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -231,7 +235,8 @@ private String prepareFindQuery(List filters, Object[] params) {
}
@Override
- public List find(List filters) throws DAOException {
+ public List find(List filters) throws
+ DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -247,7 +252,7 @@ public List find(List filters) throws DAOException {
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -256,7 +261,8 @@ public List find(List filters) throws DAOException {
}
@Override
- public List find(List filters, int limit) throws DAOException {
+ public List find(List filters, int limit) throws
+ DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -277,7 +283,7 @@ public List find(List filters, int limit) throws DAOException
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -287,7 +293,7 @@ public List find(List filters, int limit) throws DAOException
@Override
public List find(List filters, int limit, int offset)
- throws DAOException {
+ throws DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -312,7 +318,7 @@ public List find(List filters, int limit, int offset)
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -322,7 +328,7 @@ public List find(List filters, int limit, int offset)
@Override
public List find(List filters, String column,
- boolean ascend) throws DAOException {
+ boolean ascend) throws DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -347,7 +353,7 @@ public List find(List filters, String column,
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -357,7 +363,8 @@ public List find(List filters, String column,
@Override
public List find(List filters, String column,
- boolean ascend, int limit) throws DAOException {
+ boolean ascend, int limit) throws
+ DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -385,7 +392,7 @@ public List find(List filters, String column,
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -396,7 +403,7 @@ public List find(List filters, String column,
@Override
public List find(List filters, String column,
boolean ascend, int limit, int offset)
- throws DAOException {
+ throws DAOConnectionException {
ArrayList transfers = new ArrayList();
// Create the SQL query
Object[] params = new Object[filters.size()];
@@ -426,7 +433,7 @@ public List find(List filters, String column,
transfers.add(getFromResultSet(res));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -436,7 +443,7 @@ public List find(List filters, String column,
@Override
public boolean exist(long id, String requester, String requested,
- String owner) throws DAOException {
+ String owner) throws DAOConnectionException {
PreparedStatement stm = null;
ResultSet res = null;
Object[] params = {
@@ -451,7 +458,7 @@ public boolean exist(long id, String requester, String requested,
res = executeQuery(stm);
return res.next();
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
@@ -460,7 +467,8 @@ public boolean exist(long id, String requester, String requested,
@Override
public Transfer select(long id, String requester, String requested,
- String owner) throws DAOException {
+ String owner)
+ throws DAOConnectionException, DAONoDataException {
PreparedStatement stm = null;
ResultSet res = null;
Object[] params = {
@@ -475,20 +483,21 @@ public Transfer select(long id, String requester, String requested,
res = executeQuery(stm);
if (res.next()) {
return getFromResultSet(res);
+ } else {
+ throw new DAONoDataException(("No " + getClass().getName() + " found"));
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeResultSet(res);
closeStatement(stm);
}
- return null;
}
- abstract protected long getNextId() throws DAOException;
+ abstract protected long getNextId() throws DAOConnectionException;
@Override
- public void insert(Transfer transfer) throws DAOException {
+ public void insert(Transfer transfer) throws DAOConnectionException {
if (transfer.getId() == DbConstant.ILLEGALVALUE) {
transfer.setId(getNextId());
}
@@ -524,14 +533,15 @@ public void insert(Transfer transfer) throws DAOException {
setParameters(stm, params);
executeUpdate(stm);
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
}
@Override
- public void update(Transfer transfer) throws DAOException {
+ public void update(Transfer transfer)
+ throws DAOConnectionException, DAONoDataException {
Object[] params = {
transfer.getId(),
transfer.getGlobalStep().ordinal(),
@@ -565,9 +575,13 @@ public void update(Transfer transfer) throws DAOException {
try {
stm = connection.prepareStatement(getUpdateRequest());
setParameters(stm, params);
- executeUpdate(stm);
+ try {
+ executeUpdate(stm);
+ } catch (SQLException e2) {
+ throw new DAONoDataException(e2);
+ }
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(stm);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/StatementExecutor.java b/src/main/java/org/waarp/openr66/dao/database/StatementExecutor.java
index 681cc2570..67938c053 100644
--- a/src/main/java/org/waarp/openr66/dao/database/StatementExecutor.java
+++ b/src/main/java/org/waarp/openr66/dao/database/StatementExecutor.java
@@ -26,7 +26,7 @@ public void executeUpdate(PreparedStatement stm) throws SQLException {
if (res < 1) {
logger.warn("Update failed, no record updated.");
} else {
- logger.info(res + " records updated.");
+ logger.debug(res + " records updated.");
}
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/h2/H2TransferDAO.java b/src/main/java/org/waarp/openr66/dao/database/h2/H2TransferDAO.java
index 32bd9cff0..b1ff75a0e 100644
--- a/src/main/java/org/waarp/openr66/dao/database/h2/H2TransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/h2/H2TransferDAO.java
@@ -6,18 +6,18 @@
import java.sql.SQLException;
import org.waarp.openr66.dao.database.DBTransferDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
public class H2TransferDAO extends DBTransferDAO {
protected static String SQL_GET_ID = "SELECT NEXTVAL('RUNSEQ')";
- public H2TransferDAO(Connection con) throws DAOException {
+ public H2TransferDAO(Connection con) throws DAOConnectionException {
super(con);
}
@Override
- protected long getNextId() throws DAOException {
+ protected long getNextId() throws DAOConnectionException {
PreparedStatement ps = null;
try {
ps = connection.prepareStatement(SQL_GET_ID);
@@ -25,11 +25,11 @@ protected long getNextId() throws DAOException {
if (rs.next()) {
return rs.getLong(1);
} else {
- throw new DAOException(
+ throw new DAOConnectionException(
"Error no id available, you should purge the database.");
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(ps);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/mariadb/MariaDBTransferDAO.java b/src/main/java/org/waarp/openr66/dao/database/mariadb/MariaDBTransferDAO.java
index 2b01364a7..3460ab6a5 100644
--- a/src/main/java/org/waarp/openr66/dao/database/mariadb/MariaDBTransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/mariadb/MariaDBTransferDAO.java
@@ -1,7 +1,7 @@
package org.waarp.openr66.dao.database.mariadb;
import org.waarp.openr66.dao.database.DBTransferDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -15,12 +15,12 @@ public class MariaDBTransferDAO extends DBTransferDAO {
private static String SQL_UPDATE_ID = "UPDATE Sequences SET seq = ? " +
"WHERE name='RUNSEQ'";
- public MariaDBTransferDAO(Connection con) throws DAOException {
+ public MariaDBTransferDAO(Connection con) throws DAOConnectionException {
super(con);
}
@Override
- protected long getNextId() throws DAOException {
+ protected long getNextId() throws DAOConnectionException {
PreparedStatement ps = null;
PreparedStatement ps2 = null;
try {
@@ -34,11 +34,11 @@ protected long getNextId() throws DAOException {
ps2.executeUpdate();
return res;
} else {
- throw new DAOException(
+ throw new DAOConnectionException(
"Error no id available, you should purge the database.");
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(ps);
closeStatement(ps2);
diff --git a/src/main/java/org/waarp/openr66/dao/database/oracle/OracleTransferDAO.java b/src/main/java/org/waarp/openr66/dao/database/oracle/OracleTransferDAO.java
index d8e49d089..e577c4c1e 100644
--- a/src/main/java/org/waarp/openr66/dao/database/oracle/OracleTransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/oracle/OracleTransferDAO.java
@@ -6,18 +6,18 @@
import java.sql.SQLException;
import org.waarp.openr66.dao.database.DBTransferDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
public class OracleTransferDAO extends DBTransferDAO {
protected static String SQL_GET_ID = "SELECT runseq.nextval FROM DUAL";
- public OracleTransferDAO(Connection con) throws DAOException {
+ public OracleTransferDAO(Connection con) throws DAOConnectionException {
super(con);
}
@Override
- protected long getNextId() throws DAOException {
+ protected long getNextId() throws DAOConnectionException {
PreparedStatement ps = null;
try {
ps = connection.prepareStatement(SQL_GET_ID);
@@ -25,11 +25,11 @@ protected long getNextId() throws DAOException {
if (rs.next()) {
return rs.getLong(1);
} else {
- throw new DAOException(
+ throw new DAOConnectionException(
"Error no id available, you should purge the database.");
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(ps);
}
diff --git a/src/main/java/org/waarp/openr66/dao/database/postgres/PostgreSQLTransferDAO.java b/src/main/java/org/waarp/openr66/dao/database/postgres/PostgreSQLTransferDAO.java
index 05b7895de..a9fd834d2 100644
--- a/src/main/java/org/waarp/openr66/dao/database/postgres/PostgreSQLTransferDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/database/postgres/PostgreSQLTransferDAO.java
@@ -6,18 +6,18 @@
import java.sql.SQLException;
import org.waarp.openr66.dao.database.DBTransferDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
public class PostgreSQLTransferDAO extends DBTransferDAO {
protected static String SQL_GET_ID = "SELECT NEXTVAL('runseq')";
- public PostgreSQLTransferDAO(Connection con) throws DAOException {
+ public PostgreSQLTransferDAO(Connection con) throws DAOConnectionException {
super(con);
}
@Override
- protected long getNextId() throws DAOException {
+ protected long getNextId() throws DAOConnectionException {
PreparedStatement ps = null;
try {
ps = connection.prepareStatement(SQL_GET_ID);
@@ -25,11 +25,11 @@ protected long getNextId() throws DAOException {
if (rs.next()) {
return rs.getLong(1);
} else {
- throw new DAOException(
+ throw new DAOConnectionException(
"Error no id available, you should purge the database.");
}
} catch (SQLException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} finally {
closeStatement(ps);
}
diff --git a/src/main/java/org/waarp/openr66/dao/exception/DAOConnectionException.java b/src/main/java/org/waarp/openr66/dao/exception/DAOConnectionException.java
new file mode 100644
index 000000000..038a1723c
--- /dev/null
+++ b/src/main/java/org/waarp/openr66/dao/exception/DAOConnectionException.java
@@ -0,0 +1,22 @@
+package org.waarp.openr66.dao.exception;
+
+import java.lang.Exception;
+import java.lang.Throwable;
+
+/**
+ * Connection DAO Exception
+ */
+public class DAOConnectionException extends DAOException {
+
+ public DAOConnectionException(String message) {
+ super(message);
+ }
+
+ public DAOConnectionException(Throwable cause) {
+ super(cause);
+ }
+
+ public DAOConnectionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/org/waarp/openr66/dao/exception/DAOException.java b/src/main/java/org/waarp/openr66/dao/exception/DAOException.java
index 2f4b9a811..2b9ab21f7 100644
--- a/src/main/java/org/waarp/openr66/dao/exception/DAOException.java
+++ b/src/main/java/org/waarp/openr66/dao/exception/DAOException.java
@@ -1,8 +1,8 @@
package org.waarp.openr66.dao.exception;
-import java.lang.Exception;
-import java.lang.Throwable;
-
+/**
+ * Parent Exception of DAO
+ */
public class DAOException extends Exception {
public DAOException(String message) {
diff --git a/src/main/java/org/waarp/openr66/dao/exception/DAONoDataException.java b/src/main/java/org/waarp/openr66/dao/exception/DAONoDataException.java
new file mode 100644
index 000000000..ca6122ec5
--- /dev/null
+++ b/src/main/java/org/waarp/openr66/dao/exception/DAONoDataException.java
@@ -0,0 +1,19 @@
+package org.waarp.openr66.dao.exception;
+
+/**
+ * Exception when no data found in select or update
+ */
+public class DAONoDataException extends DAOException {
+
+ public DAONoDataException(String message) {
+ super(message);
+ }
+
+ public DAONoDataException(Throwable cause) {
+ super(cause);
+ }
+
+ public DAONoDataException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/org/waarp/openr66/dao/xml/XMLBusinessDAO.java b/src/main/java/org/waarp/openr66/dao/xml/XMLBusinessDAO.java
index 9216af623..5cab3efdf 100644
--- a/src/main/java/org/waarp/openr66/dao/xml/XMLBusinessDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/xml/XMLBusinessDAO.java
@@ -1,15 +1,16 @@
package org.waarp.openr66.dao.xml;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.BusinessDAO;
import org.waarp.openr66.dao.Filter;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Business;
+import org.waarp.openr66.pojo.Host;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
@@ -17,16 +18,23 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
//TODO
public class XMLBusinessDAO implements BusinessDAO {
private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(XMLBusinessDAO.class);
+ /**
+ * HashTable in case of lack of database
+ */
+ private static final ConcurrentHashMap
+ dbR66BusinessHashMap =
+ new ConcurrentHashMap();
+
public static final String HOSTID_FIELD = "hostid";
private static final String XML_SELECT = "/authent/entry[hostid=$hostid]";
@@ -34,23 +42,23 @@ public class XMLBusinessDAO implements BusinessDAO {
private File file;
- public XMLBusinessDAO(String filePath) throws DAOException {
+ public XMLBusinessDAO(String filePath) throws DAOConnectionException {
this.file = new File(filePath);
}
public void close() {}
- public void delete(Business business) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void delete(Business business) throws DAOConnectionException {
+ dbR66BusinessHashMap.remove(business.getHostid());
}
- public void deleteAll() throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void deleteAll() throws DAOConnectionException {
+ dbR66BusinessHashMap.clear();
}
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -64,23 +72,28 @@ public List getAll() throws DAOException {
List res = new ArrayList(listNode.getLength());
for (int i = 0; i < listNode.getLength(); i++) {
Node node = listNode.item(i);
- res.add(getFromNode(node));
+ Business business = getFromNode(node);
+ res.add(business);
+ dbR66BusinessHashMap.put(business.getHostid(), business);
}
return res;
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
+ if (dbR66BusinessHashMap.containsKey(hostid)) {
+ return true;
+ }
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -95,27 +108,33 @@ public boolean exist(String hostid) throws DAOException {
// Query will return "" if nothing is found
return(!"".equals(xpe.evaluate(document)));
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public List find(List fitlers) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public List find(List fitlers) throws
+ DAOConnectionException {
+ throw new DAOConnectionException("Operation not supported on XML DAO");
}
- public void insert(Business business) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void insert(Business business) throws DAOConnectionException {
+ dbR66BusinessHashMap.put(business.getHostid(), business);
}
- public Business select(String hostid) throws DAOException {
+ public Business select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
+ Business business = dbR66BusinessHashMap.get(hostid);
+ if (business != null) {
+ return business;
+ }
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -130,22 +149,24 @@ public Business select(String hostid) throws DAOException {
// Retrieve node and instantiate object
Node node = (Node) xpe.evaluate(document, XPathConstants.NODE);
if (node != null) {
- return getFromNode(node);
+ business = getFromNode(node);
+ dbR66BusinessHashMap.put(business.getHostid(), business);
+ return business;
}
- return null;
+ throw new DAONoDataException("Business not found");
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public void update(Business business) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void update(Business business) throws DAOConnectionException {
+ dbR66BusinessHashMap.put(business.getHostid(), business);
}
private Business getFromNode(Node parent) {
diff --git a/src/main/java/org/waarp/openr66/dao/xml/XMLDAOFactory.java b/src/main/java/org/waarp/openr66/dao/xml/XMLDAOFactory.java
index cbe480714..77ad26e5b 100644
--- a/src/main/java/org/waarp/openr66/dao/xml/XMLDAOFactory.java
+++ b/src/main/java/org/waarp/openr66/dao/xml/XMLDAOFactory.java
@@ -1,7 +1,7 @@
package org.waarp.openr66.dao.xml;
import org.waarp.openr66.dao.*;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
import org.waarp.openr66.protocol.configuration.Configuration;
public class XMLDAOFactory extends DAOFactory {
@@ -18,32 +18,33 @@ public XMLDAOFactory() {}
@Override
- public BusinessDAO getBusinessDAO() throws DAOException {
+ public BusinessDAO getBusinessDAO() throws DAOConnectionException {
return new XMLBusinessDAO(businessFile);
}
@Override
- public HostDAO getHostDAO() throws DAOException {
+ public HostDAO getHostDAO() throws DAOConnectionException {
return new XMLHostDAO(hostFile);
}
@Override
- public LimitDAO getLimitDAO() throws DAOException {
- return new XMLimitDAO(limitFile);
+ public LimitDAO getLimitDAO() throws DAOConnectionException {
+ return new XMLLimitDAO(limitFile);
}
@Override
- public MultipleMonitorDAO getMultipleMonitorDAO() throws DAOException {
- throw new DAOException("MultipleMonitor is not supported on XML DAO");
+ public MultipleMonitorDAO getMultipleMonitorDAO() throws
+ DAOConnectionException {
+ throw new DAOConnectionException("MultipleMonitor is not supported on XML DAO");
}
@Override
- public RuleDAO getRuleDAO() throws DAOException {
+ public RuleDAO getRuleDAO() throws DAOConnectionException {
return new XMLRuleDAO(ruleFile);
}
@Override
- public TransferDAO getTransferDAO() throws DAOException {
+ public TransferDAO getTransferDAO() throws DAOConnectionException {
return new XMLTransferDAO(transferFile);
}
}
diff --git a/src/main/java/org/waarp/openr66/dao/xml/XMLHostDAO.java b/src/main/java/org/waarp/openr66/dao/xml/XMLHostDAO.java
index bc85b788e..879d980ab 100644
--- a/src/main/java/org/waarp/openr66/dao/xml/XMLHostDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/xml/XMLHostDAO.java
@@ -1,14 +1,15 @@
package org.waarp.openr66.dao.xml;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.Filter;
import org.waarp.openr66.dao.HostDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
+import org.waarp.openr66.database.data.DbHostAuth;
import org.waarp.openr66.pojo.Host;
import org.xml.sax.SAXException;
@@ -17,16 +18,23 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
public class XMLHostDAO implements HostDAO {
private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(XMLHostDAO.class);
+ /**
+ * HashTable in case of lack of database
+ */
+ private static final ConcurrentHashMap
+ dbR66HostAuthHashMap =
+ new ConcurrentHashMap();
+
public static final String HOSTID_FIELD = "hostid";
public static final String ADDRESS_FIELD = "address";
public static final String PORT_FIELD = "port";
@@ -48,17 +56,17 @@ public XMLHostDAO(String filePath) {
public void close() {}
- public void delete(Host host) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void delete(Host host) throws DAOConnectionException {
+ dbR66HostAuthHashMap.remove(host.getHostid());
}
- public void deleteAll() throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void deleteAll() throws DAOConnectionException {
+ dbR66HostAuthHashMap.clear();
}
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -72,23 +80,28 @@ public List getAll() throws DAOException {
List res = new ArrayList(listNode.getLength());
for (int i = 0; i < listNode.getLength(); i++) {
Node node = listNode.item(i);
- res.add(getFromNode(node));
+ Host host = getFromNode(node);
+ res.add(host);
+ dbR66HostAuthHashMap.put(host.getHostid(), host);
}
return res;
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
+ if (dbR66HostAuthHashMap.containsKey(hostid)) {
+ return true;
+ }
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -103,27 +116,32 @@ public boolean exist(String hostid) throws DAOException {
// Query will return "" if nothing is found
return(!"".equals(xpe.evaluate(document)));
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public List find(List fitlers) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public List find(List fitlers) throws DAOConnectionException {
+ throw new DAOConnectionException("Operation not supported on XML DAO");
}
- public void insert(Host host) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void insert(Host host) throws DAOConnectionException {
+ dbR66HostAuthHashMap.put(host.getHostid(), host);
}
- public Host select(String hostid) throws DAOException {
+ public Host select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
+ Host host = dbR66HostAuthHashMap.get(hostid);
+ if (host != null) {
+ return host;
+ }
if (!file.exists()) {
- throw new DAOException("File " + file.getPath() + " doesn't exist");
+ throw new DAOConnectionException("File " + file.getPath() + " doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -138,22 +156,24 @@ public Host select(String hostid) throws DAOException {
// Retrieve node and instantiate object
Node node = (Node) xpe.evaluate(document, XPathConstants.NODE);
if (node != null) {
- return getFromNode(node);
+ host = getFromNode(node);
+ dbR66HostAuthHashMap.put(host.getHostid(), host);
+ return host;
}
- return null;
+ throw new DAONoDataException("Host not found");
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public void update(Host host) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void update(Host host) throws DAOConnectionException {
+ dbR66HostAuthHashMap.put(host.getHostid(), host);
}
private Host getFromNode(Node parent) {
diff --git a/src/main/java/org/waarp/openr66/dao/xml/XMLimitDAO.java b/src/main/java/org/waarp/openr66/dao/xml/XMLLimitDAO.java
similarity index 61%
rename from src/main/java/org/waarp/openr66/dao/xml/XMLimitDAO.java
rename to src/main/java/org/waarp/openr66/dao/xml/XMLLimitDAO.java
index cd2f2f347..0074bc9c8 100644
--- a/src/main/java/org/waarp/openr66/dao/xml/XMLimitDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/xml/XMLLimitDAO.java
@@ -1,14 +1,14 @@
package org.waarp.openr66.dao.xml;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.dao.Filter;
import org.waarp.openr66.dao.LimitDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
import org.waarp.openr66.pojo.Limit;
import org.xml.sax.SAXException;
@@ -17,15 +17,22 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
//TODO
-public class XMLimitDAO implements LimitDAO {
+public class XMLLimitDAO implements LimitDAO {
- private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(XMLimitDAO.class);
+ private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(
+ XMLLimitDAO.class);
+
+ /**
+ * HashTable in case of lack of database
+ */
+ private static final ConcurrentHashMap dbR66ConfigurationHashMap =
+ new ConcurrentHashMap();
public static final String HOSTID_FIELD = "hostid";
public static final String SESSION_LIMIT_FILED = "sessionlimit";
@@ -39,44 +46,49 @@ public class XMLimitDAO implements LimitDAO {
private File file;
- public XMLimitDAO(String filePath) throws DAOException {
+ public XMLLimitDAO(String filePath) throws DAOConnectionException {
this.file = new File(filePath);
}
public void close() {}
- public void delete(Limit limit) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void delete(Limit limit) throws DAOConnectionException {
+ dbR66ConfigurationHashMap.remove(limit.getHostid());
}
- public void deleteAll() throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void deleteAll() throws DAOConnectionException {
+ dbR66ConfigurationHashMap.clear();
}
- public List getAll() throws DAOException {
+ public List getAll() throws DAOConnectionException {
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document document = dbf.newDocumentBuilder().parse(file);
// File contains only 1 entry
List res = new ArrayList(1);
- res.add(getFromNode(document.getDocumentElement()));
+ Limit limit = getFromNode(document.getDocumentElement());
+ res.add(limit);
+ dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
// Iterate through all found nodes
return res;
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public boolean exist(String hostid) throws DAOException {
+ public boolean exist(String hostid) throws DAOConnectionException {
+ if (dbR66ConfigurationHashMap.containsKey(hostid)) {
+ return true;
+ }
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -91,27 +103,33 @@ public boolean exist(String hostid) throws DAOException {
// Query will return "" if nothing is found
return(!"".equals(xpe.evaluate(document)));
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public List find(List fitlers) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public List find(List fitlers) throws
+ DAOConnectionException {
+ throw new DAOConnectionException("Operation not supported on XML DAO");
}
- public void insert(Limit limit) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void insert(Limit limit) throws DAOConnectionException {
+ dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
}
- public Limit select(String hostid) throws DAOException {
+ public Limit select(String hostid)
+ throws DAOConnectionException, DAONoDataException {
+ Limit limit = dbR66ConfigurationHashMap.get(hostid);
+ if (limit != null) {
+ return limit;
+ }
if (!file.exists()) {
- throw new DAOException("File doesn't exist");
+ throw new DAOConnectionException("File doesn't exist");
}
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -126,22 +144,24 @@ public Limit select(String hostid) throws DAOException {
// Retrieve node and instantiate object
Node node = (Node) xpe.evaluate(document, XPathConstants.NODE);
if (node != null) {
- return getFromNode(document.getDocumentElement());
+ limit = getFromNode(document.getDocumentElement());
+ dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
+ return limit;
}
- return null;
+ throw new DAONoDataException("Limit not found");
} catch (SAXException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (XPathExpressionException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (ParserConfigurationException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
} catch (IOException e) {
- throw new DAOException(e);
+ throw new DAOConnectionException(e);
}
}
- public void update(Limit limit) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void update(Limit limit) throws DAOConnectionException {
+ dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
}
private Limit getFromNode(Node parent) {
diff --git a/src/main/java/org/waarp/openr66/dao/xml/XMLRuleDAO.java b/src/main/java/org/waarp/openr66/dao/xml/XMLRuleDAO.java
index 97e2d5b89..6f486c096 100644
--- a/src/main/java/org/waarp/openr66/dao/xml/XMLRuleDAO.java
+++ b/src/main/java/org/waarp/openr66/dao/xml/XMLRuleDAO.java
@@ -7,15 +7,15 @@
import org.waarp.common.logging.WaarpLogger;
import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.openr66.configuration.ExtensionFilter;
-import org.waarp.openr66.dao.DAOFactory;
import org.waarp.openr66.dao.Filter;
import org.waarp.openr66.dao.RuleDAO;
-import org.waarp.openr66.dao.exception.DAOException;
+import org.waarp.openr66.dao.exception.DAOConnectionException;
+import org.waarp.openr66.dao.exception.DAONoDataException;
+import org.waarp.openr66.database.data.DbRule;
import org.waarp.openr66.pojo.Rule;
import org.waarp.openr66.pojo.RuleTask;
import org.waarp.openr66.protocol.configuration.Configuration;
import org.xml.sax.SAXException;
-import sun.security.krb5.Config;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -25,11 +25,18 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
public class XMLRuleDAO implements RuleDAO {
private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(XMLRuleDAO.class);
+ /**
+ * HashTable in case of lack of database
+ */
+ private static final ConcurrentHashMap dbR66RuleHashMap =
+ new ConcurrentHashMap();
+
public static final String ROOT_LIST = "rules";
public static final String ROOT_ELEMENT = "rule";
@@ -74,15 +81,15 @@ private File[] getRuleFiles() {
return res.toArray(new File[0]);
}
- public void delete(Rule rule) throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void delete(Rule rule) throws DAOConnectionException {
+ dbR66RuleHashMap.remove(rule.getName());
}
- public void deleteAll() throws DAOException {
- throw new DAOException("Operation not supported on XML DAO");
+ public void deleteAll() throws DAOConnectionException {
+ dbR66RuleHashMap.clear();
}
- public List