Skip to content
Snippets Groups Projects
Commit 26030eda authored by Gwenaelle ABEILLE's avatar Gwenaelle ABEILLE
Browse files

check export before writing in file to avoid empty files

parent ed45e4e3
No related branches found
No related tags found
No related merge requests found
......@@ -246,6 +246,7 @@ public class FileTools {
private int attributePerFile;
private Date creationFileDate;
private final long exportPeriod;
public FileTools(final String attributeName, final String tableName, final int dataFormat, final int writable,
final long windowsDuration, final ILogger logger, final DbProxy dbProxy, final String workingDsPath,
final String workingDbPath) throws IOException, ArchivingException {
......@@ -327,7 +328,7 @@ public class FileTools {
String writeValue = scalarEvent.valueToString(1);
final long timeStampValue = scalarEvent.getTimeStamp();
if (isValidLine(timeStampValue)) {
doExport();
if (dbProxy.getDataBase().getDbConn().getDbType() == ConfigConst.TDB_ORACLE) {
if (readValue == null || GlobalConst.ARCHIVER_NULL_VALUE.equalsIgnoreCase(readValue.trim())) {
readValue = GlobalConst.ORACLE_NULL_VALUE;
......@@ -376,36 +377,40 @@ public class FileTools {
switch (scalarEvent.getWritable()) {
case AttrWriteType._READ:
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp())).append(
ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.LINES_LIMIT).toString());
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp()))
.append(ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.LINES_LIMIT)
.toString());
break;
case AttrWriteType._READ_WITH_WRITE:
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp())).append(
ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.FIELDS_LIMIT).append(
writeValue).append(ConfigConst.LINES_LIMIT).toString());
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp()))
.append(ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.FIELDS_LIMIT)
.append(writeValue).append(ConfigConst.LINES_LIMIT).toString());
break;
case AttrWriteType._WRITE:
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp())).append(
ConfigConst.FIELDS_LIMIT).append(writeValue).append(ConfigConst.LINES_LIMIT).toString());
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp()))
.append(ConfigConst.FIELDS_LIMIT).append(writeValue).append(ConfigConst.LINES_LIMIT)
.toString());
break;
case AttrWriteType._READ_WRITE:
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp())).append(
ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.FIELDS_LIMIT).append(
writeValue).append(ConfigConst.LINES_LIMIT).toString());
write(new StringBuffer().append(toDbTimeStringMySQL(scalarEvent.getTimeStamp()))
.append(ConfigConst.FIELDS_LIMIT).append(readValue).append(ConfigConst.FIELDS_LIMIT)
.append(writeValue).append(ConfigConst.LINES_LIMIT).toString());
break;
}
}
doExport();
} else {
logger.trace(ILogger.LEVEL_INFO, "This timestamps has already been inserted : "
+ new Timestamp(timeStampValue) + " in the file " + fileName);
logger.trace(ILogger.LEVEL_INFO,
"This timestamps has already been inserted : " + new Timestamp(timeStampValue)
+ " in the file " + fileName + "for " + scalarEvent.getAttribute_complete_name());
}
} catch (final IOException e) {
e.printStackTrace();
logger.trace(ILogger.LEVEL_ERROR, "ERROR !! " + "\r\n" + "\t Origin : \t " + "FileTools.processEventScalar"
+ "\r\n" + "\t Reason : \t " + e.getClass().getName() + "\r\n" + "\t Description : \t "
+ e.getMessage() + "\r\n" + "\t Additional information : \t " + "File :\t " + fileName + "\r\n");
logger.trace(ILogger.LEVEL_ERROR, "IOException for " + scalarEvent.getAttribute_complete_name());
} catch (Exception e) {
e.printStackTrace();
logger.trace(ILogger.LEVEL_ERROR, "Unknow Exception for " + scalarEvent.getAttribute_complete_name());
}
}
......@@ -423,7 +428,7 @@ public class FileTools {
} else if (attributePerFile > 0) {
writtenAttributes++;
if (writtenAttributes >= attributePerFile || elapseTime >= exportPeriod) {
logger.trace(ILogger.LEVEL_DEBUG, "export because of writtenAttributes " + writtenAttributes
logger.trace(ILogger.LEVEL_DEBUG, "export due to writtenAttributes " + writtenAttributes
+ " - elapseTime " + elapseTime);
switchFile();
writtenAttributes = 0;
......@@ -449,7 +454,7 @@ public class FileTools {
final long timeStampValue = spectrumEvent_ro.getTimeStamp();
if (isValidLine(timeStampValue)) {
doExport();
if (spectrumEvent_ro.getData_type() == TangoConst.Tango_DEV_STRING) {
final String[] value = (String[]) spectrumEvent_ro.getValue();
String[] transformedValue = null;
......@@ -468,10 +473,10 @@ public class FileTools {
if (GlobalConst.ARCHIVER_NULL_VALUE.equals(value)) {
value = GlobalConst.ORACLE_NULL_VALUE;
}
write(new StringBuffer().append("\"").append(
DateUtil.milliToString(spectrumEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN)).append(
"\"").append(",").append("\"").append(Double.toString(spectrumEvent_ro.getDim_x())).append(
"\"").append(",").append("\"").append(value).append("\"").toString());
write(new StringBuffer().append("\"")
.append(DateUtil.milliToString(spectrumEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN))
.append("\"").append(",").append("\"").append(Double.toString(spectrumEvent_ro.getDim_x()))
.append("\"").append(",").append("\"").append(value).append("\"").toString());
write(ConfigConst.NEW_LINE);
} else if (dbProxy.getDataBase().getDbConn().getDbType() == ConfigConst.TDB_MYSQL) {
......@@ -488,7 +493,7 @@ public class FileTools {
buff.append(ConfigConst.LINES_LIMIT);
write(buff.toString());
}
doExport();
} else {
logger.trace(ILogger.LEVEL_INFO, "This timestamps has already been inserted : "
+ new Timestamp(timeStampValue) + " in the file " + fileName);
......@@ -591,6 +596,7 @@ public class FileTools {
public synchronized void processEventImage(final ImageEvent_RO imageEvent_ro) throws ArchivingException {
try {
doExport();
if (imageEvent_ro.getData_type() == TangoConst.Tango_DEV_STRING) {
final String[] value = (String[]) imageEvent_ro.getValue();
String[] transformedValue = null;
......@@ -604,22 +610,23 @@ public class FileTools {
}
if (dbProxy.getDataBase().getDbConn().getDbType() == ConfigConst.TDB_ORACLE) {
write(new StringBuffer().append("\"").append(
DateUtil.milliToString(imageEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN)).append("\"")
.append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_x())).append("\"")
.append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_y())).append("\"")
.append(",").append("\"").append(imageEvent_ro.getValue_AsString()).append("\"").toString());
write(new StringBuffer().append("\"")
.append(DateUtil.milliToString(imageEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN))
.append("\"").append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_x()))
.append("\"").append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_y()))
.append("\"").append(",").append("\"").append(imageEvent_ro.getValue_AsString()).append("\"")
.toString());
write(ConfigConst.NEW_LINE);
} else if (dbProxy.getDataBase().getDbConn().getDbType() == ConfigConst.TDB_MYSQL) {
final long timeStampValue = imageEvent_ro.getTimeStamp();
if (isValidLine(timeStampValue)) {
write(new StringBuffer().append("\"").append(
DateUtil.milliToString(imageEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN))
write(new StringBuffer().append("\"")
.append(DateUtil.milliToString(imageEvent_ro.getTimeStamp(), DateUtil.FR_DATE_PATTERN))
.append("\"").append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_x()))
.append("\"").append(",").append("\"").append(Double.toString(imageEvent_ro.getDim_y()))
.append("\"").append(",").append("\"").append(imageEvent_ro.getValue_AsString()).append(
"\"").toString());
.append("\"").append(",").append("\"").append(imageEvent_ro.getValue_AsString())
.append("\"").toString());
write(ConfigConst.NEW_LINE);
} else {
logger.trace(ILogger.LEVEL_INFO, "This timestamps has already been inserted : "
......@@ -627,7 +634,7 @@ public class FileTools {
}
}
doExport();
} catch (final IOException e) {
Util.out2.println("ERROR !! " + "\r\n" + "\t Origin : \t " + "FileTools.processEventImage" + "\r\n"
+ "\t Reason : \t " + e.getClass().getName() + "\r\n" + "\t Description : \t " + e.getMessage()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment