use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryClusterSchemaDelegate method insertCluster.
private synchronized ObjectId insertCluster(ClusterSchema clusterSchema) throws KettleException {
if (getClusterID(clusterSchema.getName()) != null) {
// This cluster schema name is already in use. Throw an exception.
throw new KettleObjectExistsException("Failed to create object in repository. Object [" + clusterSchema.getName() + "] already exists.");
}
ObjectId id = repository.connectionDelegate.getNextClusterID();
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CLUSTER_ID_CLUSTER), id);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_NAME), clusterSchema.getName());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_BASE_PORT), clusterSchema.getBasePort());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_BUFFER_SIZE), clusterSchema.getSocketsBufferSize());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_FLUSH_INTERVAL), clusterSchema.getSocketsFlushInterval());
table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_COMPRESSED), Boolean.valueOf(clusterSchema.isSocketsCompressed()));
table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CLUSTER_DYNAMIC), Boolean.valueOf(clusterSchema.isDynamic()));
repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_CLUSTER);
repository.connectionDelegate.getDatabase().setValuesInsert(table);
repository.connectionDelegate.getDatabase().insertRow();
repository.connectionDelegate.getDatabase().closeInsert();
return id;
}
use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositorySlaveServerDelegate method saveSlaveServer.
public void saveSlaveServer(SlaveServer slaveServer, ObjectId id_transformation, boolean isUsedByTransformation, boolean overwrite) throws KettleException {
if (slaveServer.getObjectId() == null) {
// See if the slave doesn't exist already (just for safety and PDI-5102
//
slaveServer.setObjectId(getSlaveID(slaveServer.getName()));
}
if (slaveServer.getObjectId() == null) {
// New Slave Server
slaveServer.setObjectId(insertSlave(slaveServer));
} else {
ObjectId existingSlaveId = slaveServer.getObjectId();
if (existingSlaveId != null && slaveServer.getObjectId() != null && !slaveServer.getObjectId().equals(existingSlaveId)) {
// A slave with this name already exists
if (overwrite) {
// Proceed with save, removing the original version from the repository first
repository.deleteSlave(existingSlaveId);
updateSlave(slaveServer);
} else {
throw new KettleObjectExistsException("Failed to save object to repository. Object [" + slaveServer.getName() + "] already exists.");
}
} else {
// There are no naming collisions (either it is the same object or the name is unique)
updateSlave(slaveServer);
}
}
// Save the trans-slave relationship too.
if (id_transformation != null && isUsedByTransformation) {
repository.insertTransformationSlave(id_transformation, slaveServer.getObjectId());
}
}
use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.
the class SharedDatabaseUtil method addSharedDatabase.
/**
* Add a database to the list of shared databases in ~/.kettle/shared.xml
*
* @param databaseMeta
* @throws KettleException in case there is an error
* @throws KettleObjectExistsException if a database with the same name already exists
*/
public static void addSharedDatabase(DatabaseMeta databaseMeta) throws KettleObjectExistsException, KettleException {
// First verify existence...
//
List<DatabaseMeta> sharedDatabases = loadSharedDatabases();
DatabaseMeta found = DatabaseMeta.findDatabase(sharedDatabases, databaseMeta.getName());
if (found != null) {
throw new KettleObjectExistsException("A database with name '" + databaseMeta.getName() + "' already exists in the shared databases list.");
}
try {
SharedObjects sharedObjects = new SharedObjects();
sharedObjects.storeObject(databaseMeta);
sharedObjects.saveToFile();
} catch (Exception e) {
throw new KettleException("It was not possible to add database '" + databaseMeta.getName() + "' to the shared.xml file");
}
}
Aggregations