use of com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider in project ats-framework by Axway.
the class CassandraEnvironmentHandler method restore.
public void restore(String backupFileName) throws DatabaseEnvironmentCleanupException {
BufferedReader backupReader = null;
try {
log.debug("Starting restoring db backup from file '" + backupFileName + "'");
backupReader = new BufferedReader(new FileReader(new File(backupFileName)));
StringBuilder sql = new StringBuilder();
String line = backupReader.readLine();
while (line != null) {
sql.append(line);
if (line.endsWith(EOL_MARKER)) {
// remove the EOL marker
sql.delete(sql.length() - EOL_MARKER.length(), sql.length());
dbProvider.executeUpdate(sql.toString());
sql.delete(0, sql.length());
} else {
//add a new line
//FIXME: this code will add the system line ending - it
//is not guaranteed that this was the actual line ending
sql.append(AtsSystemProperties.SYSTEM_LINE_SEPARATOR);
}
line = backupReader.readLine();
}
log.debug("Finished restoring db backup from file '" + backupFileName + "'");
} catch (IOException ioe) {
throw new DatabaseEnvironmentCleanupException(ERROR_RESTORING_BACKUP + backupFileName, ioe);
} catch (DbException dbe) {
throw new DatabaseEnvironmentCleanupException(ERROR_RESTORING_BACKUP + backupFileName, dbe);
} finally {
try {
if (backupReader != null) {
backupReader.close();
}
} catch (IOException ioe) {
log.error(ERROR_RESTORING_BACKUP + backupFileName, ioe);
}
((CassandraDbProvider) dbProvider).disconnect();
}
}
use of com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider in project ats-framework by Axway.
the class CassandraEnvironmentHandler method getColumnsToSelect.
@Override
protected List<ColumnDescription> getColumnsToSelect(DbTable table, String userName) throws DbException, ColumnHasNoDefaultValueException {
Map<String, String> columnInfo = ((CassandraDbProvider) this.dbProvider).getColumnInfo(table.getTableName());
ArrayList<ColumnDescription> columnsToSelect = new ArrayList<ColumnDescription>();
for (Entry<String, String> columnEntry : columnInfo.entrySet()) {
//check if the column should be skipped in the backup
if (!table.getColumnsToExclude().contains(columnEntry.getKey())) {
String dataTypes = columnEntry.getValue();
ColumnDescription colDescription;
if (!dataTypes.contains("|")) {
colDescription = new ColumnDescription(columnEntry.getKey(), columnEntry.getValue());
} else {
String[] dataTypesArray = dataTypes.split("\\|");
String[] subDataTypesArray = new String[dataTypesArray.length - 1];
for (int i = 0; i < subDataTypesArray.length; i++) {
subDataTypesArray[i] = dataTypesArray[i + 1];
}
colDescription = new ColumnDescription(columnEntry.getKey(), dataTypesArray[0], subDataTypesArray);
}
columnsToSelect.add(colDescription);
}
}
return columnsToSelect;
}
use of com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider in project ats-framework by Axway.
the class DatabaseProviderFactory method getDatabaseProvider.
/**
* Creates a database provider suitable for the given input arguments
*
* @param dbType
* @param dbHost
* @param dbName
* @param dbUser
* @param dbPass
* @param dbPort
* @param customProperties
* @return
*/
public static synchronized DbProvider getDatabaseProvider(String dbType, String dbHost, String dbName, String dbUser, String dbPass, int dbPort, Map<String, Object> customProperties) {
DbProvider dbProvider;
if (dbType == null) {
throw new IllegalArgumentException("Database type is not provided");
}
if (dbName == null) {
if ("MSSQL".equals(dbType)) {
log.warn("Database name is empty! The connection will be made to the admin database!");
} else {
throw new IllegalArgumentException("Database name is not provided");
}
}
// eventual custom property value
if (dbPort > 0) {
if (customProperties == null) {
customProperties = new HashMap<String, Object>();
}
customProperties.put(DbKeys.PORT_KEY, dbPort);
}
// load a custom data provider
if (dbProviders.containsKey(dbType)) {
String[] classNames = dbProviders.get(dbType);
DbConnection dbConnection = loadDbConnection(classNames[0], dbType, dbHost, dbName, dbUser, dbPass, dbPort, customProperties);
return loadCustomDbProvider(classNames[1], dbConnection);
}
// load a common ATS supported data provider
switch(dbType) {
case DbConnSQLServer.DATABASE_TYPE:
dbProvider = new MssqlDbProvider((DbConnSQLServer) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
break;
case DbConnMySQL.DATABASE_TYPE:
dbProvider = new MysqlDbProvider((DbConnMySQL) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
break;
case DbConnOracle.DATABASE_TYPE:
dbProvider = new OracleDbProvider((DbConnOracle) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
break;
case DbConnCassandra.DATABASE_TYPE:
dbProvider = new CassandraDbProvider((DbConnCassandra) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
break;
default:
{
// should never happen
throw new IllegalArgumentException("Database type " + dbType + " not supported");
}
}
return dbProvider;
}
use of com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider in project ats-framework by Axway.
the class DatabaseOperations method updateValue.
/**
* Run update query.
*
* @param sqlQuery the SQL query to run
* @return the number of updated rows
*/
@PublicAtsApi
public int updateValue(String sqlQuery) {
int rowsUpdated;
try {
log.debug("Executing update query: '" + sqlQuery + "'");
rowsUpdated = dbProvider.executeUpdate(sqlQuery);
if (!(dbProvider instanceof CassandraDbProvider)) {
if (rowsUpdated == 0) {
log.warn("SQL query '" + sqlQuery + "' updated 0 rows");
} else {
log.debug("SQL query '" + sqlQuery + "' updated '" + rowsUpdated + "' rows");
}
}
} catch (DbException e) {
throw new DatabaseOperationsException("Error executing update query '" + sqlQuery + "'", e);
}
return rowsUpdated;
}
Aggregations