use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method deleteElement.
@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
try {
IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
if (type == null) {
throw new MetaStoreException("Unable to find element type with name '" + elementType.getName() + "'");
}
delegate.deleteElement(new LongObjectId(new StringObjectId(elementId)));
repository.commit();
} catch (Exception e) {
repository.rollback();
throw new MetaStoreException("Unable to delete element with id '" + elementId + "' of type '" + elementType.getName() + "'", e);
}
}
use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method getElementTypes.
@Override
public List<IMetaStoreElementType> getElementTypes(String namespace) throws MetaStoreException {
try {
LongObjectId namespaceId = delegate.getNamespaceId(namespace);
if (namespaceId == null) {
return new ArrayList<IMetaStoreElementType>();
}
Collection<RowMetaAndData> elementTypeRows = delegate.getElementTypes(namespaceId);
List<IMetaStoreElementType> list = new ArrayList<IMetaStoreElementType>();
for (RowMetaAndData elementTypeRow : elementTypeRows) {
KDBRMetaStoreElementType elementType = delegate.parseElementType(namespace, namespaceId, elementTypeRow);
list.add(elementType);
}
return list;
} catch (Exception e) {
throw new MetaStoreException("Unable to get list of element types for namespace '" + namespace + "'", e);
}
}
use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getIDWithValue.
public synchronized LongObjectId getIDWithValue(String tablename, String idfield, String lookupfield, String value, String[] lookupkey, ObjectId[] key) throws KettleException {
RowMetaAndData par = new RowMetaAndData();
par.addValue(new ValueMetaString(lookupfield), value);
String sql = "SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? ";
for (int i = 0; i < lookupkey.length; i++) {
par.addValue(new ValueMetaInteger(lookupkey[i]), new LongObjectId(key[i]));
sql += "AND " + lookupkey[i] + " = ? ";
}
RowMetaAndData result = getOneRow(sql, par.getRowMeta(), par.getData());
if (result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric(0)) {
return new LongObjectId(result.getInteger(0, 0));
}
return null;
}
use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getNextID.
public synchronized LongObjectId getNextID(String tableName, String fieldName) throws KettleException {
String counterName = tableName + "." + fieldName;
Counter counter = Counters.getInstance().getCounter(counterName);
if (counter == null) {
LongObjectId id = getNextTableID(tableName, fieldName);
counter = new Counter(id.longValue());
Counters.getInstance().setCounter(counterName, counter);
return new LongObjectId(counter.next());
} else {
return new LongObjectId(counter.next());
}
}
use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getRepositoryObjects.
/**
* @param id_directory
* @return A list of RepositoryObjects
*
* @throws KettleException
*/
public synchronized List<RepositoryElementMetaInterface> getRepositoryObjects(String tableName, RepositoryObjectType objectType, ObjectId id_directory) throws KettleException {
try {
String idField;
if (RepositoryObjectType.TRANSFORMATION.equals(objectType)) {
idField = KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION;
} else {
idField = KettleDatabaseRepository.FIELD_JOB_ID_JOB;
}
if (id_directory == null) {
// root!
id_directory = new LongObjectId(0L);
}
RepositoryDirectoryInterface repositoryDirectory = repository.directoryDelegate.loadPathToRoot(id_directory);
// RepositoryDirectoryInterface repositoryDirectory =
// repository.loadRepositoryDirectoryTree().findDirectory(id_directory);
String sql = "SELECT " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION) + ", " + quote(idField) + " " + "FROM " + tableName + " " + "WHERE " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY) + " = ? ";
RowMetaAndData directoryIdRow = getParameterMetaData(id_directory);
return callRead(new Callable<List<RepositoryElementMetaInterface>>() {
@Override
public List<RepositoryElementMetaInterface> call() throws Exception {
List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
ResultSet rs = database.openQuery(sql, directoryIdRow.getRowMeta(), directoryIdRow.getData());
if (rs != null) {
List<Object[]> rows = database.getRows(rs, -1, null);
if (rs != null) {
database.closeQuery(rs);
}
RowMetaInterface rowMeta = database.getReturnRowMeta();
for (Object[] r : rows) {
ObjectId id = new LongObjectId(rowMeta.getInteger(r, 4));
repositoryObjects.add(new RepositoryObject(id, rowMeta.getString(r, 0), repositoryDirectory, rowMeta.getString(r, 1), rowMeta.getDate(r, 2), objectType, rowMeta.getString(r, 3), false));
}
}
return repositoryObjects;
}
});
} catch (Exception e) {
throw new KettleException("Unable to get list of repository objects", e);
}
}
Aggregations