org.beigesoft.replicator.service.SrvClearDatabase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beige-replicator Show documentation
Show all versions of beige-replicator Show documentation
It replicate/persist any entity according XML settings and user's requirements with a file or network (HTTP).
Right now it has implemented XML format of stored/transferred data.
The newest version!
package org.beigesoft.replicator.service;
/*
* Beigesoft ™
*
* Licensed under the Apache License, Version 2.0
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
import java.util.Date;
import java.util.Map;
import java.util.ArrayList;
import java.io.Writer;
import org.beigesoft.log.ILogger;
import org.beigesoft.delegate.IDelegator;
import org.beigesoft.settings.IMngSettings;
import org.beigesoft.orm.service.ISrvDatabase;
/**
* Service that clear database
* before get identical copy of another one.
* This is transactional service.
*
*
* @param platform dependent record set type
* @author Yury Demidenko
*/
public class SrvClearDatabase implements IDelegator {
/**
* Replicators settings manager.
**/
private IMngSettings mngSettings;
/**
* Database service.
**/
private ISrvDatabase srvDatabase;
/**
* Logger.
**/
private ILogger logger;
/**
* It will clear current database.
* @param pAddParams additional params
* @throws Exception - an exception
**/
@Override
public final void make(
final Map pAddParams) throws Exception {
ArrayList> classesArr =
new ArrayList>(this.mngSettings.getClasses());
try {
this.srvDatabase.setIsAutocommit(false);
this.srvDatabase.
setTransactionIsolation(ISrvDatabase.TRANSACTION_READ_UNCOMMITTED);
this.srvDatabase.beginTransaction();
this.logger.info(SrvClearDatabase.class, "Start clear database.");
for (int i = classesArr.size() - 1; i >= 0; i--) {
Class> entityClass = classesArr.get(i);
this.srvDatabase.executeDelete(entityClass.getSimpleName()
.toUpperCase(), null);
}
this.srvDatabase.commitTransaction();
Writer htmlWriter = (Writer) pAddParams.get("htmlWriter");
if (htmlWriter != null) {
htmlWriter.write("" + new Date().toString() + ", "
+ SrvClearDatabase.class.getSimpleName()
+ ", database has been cleared" + "
");
}
this.logger.info(SrvClearDatabase.class, "Finish clear database.");
} catch (Exception ex) {
this.srvDatabase.rollBackTransaction();
throw ex;
} finally {
this.srvDatabase.releaseResources();
}
}
//Simple getters and setters:
/**
* Getter for mngSettings.
* @return IMngSettings
**/
public final IMngSettings getMngSettings() {
return this.mngSettings;
}
/**
* Setter for mngSettings.
* @param pMngSettings reference
**/
public final void setMngSettings(final IMngSettings pMngSettings) {
this.mngSettings = pMngSettings;
}
/**
* Getter for srvDatabase.
* @return ISrvDatabase
**/
public final ISrvDatabase getSrvDatabase() {
return this.srvDatabase;
}
/**
* Setter for srvDatabase.
* @param pSrvDatabase reference
**/
public final void setSrvDatabase(final ISrvDatabase pSrvDatabase) {
this.srvDatabase = pSrvDatabase;
}
/**
* Getter for logger.
* @return ILogger
**/
public final ILogger getLogger() {
return this.logger;
}
/**
* Setter for logger.
* @param pLogger reference
**/
public final void setLogger(final ILogger pLogger) {
this.logger = pLogger;
}
}