use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class NodeEditorInputFactory method createElement.
@Override
public IAdaptable createElement(IMemento memento) {
// Get the node path.
final String nodePath = memento.getString(TAG_NODE);
if (nodePath == null) {
return null;
}
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
try {
final DBNNode node = navigatorModel.getNodeByPath(VoidProgressMonitor.INSTANCE, nodePath);
if (node != null) {
return new NodeEditorInput(node);
}
} catch (DBException e) {
log.error("Error opening node '" + nodePath + "'", e);
return null;
}
return null;
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class AbstractSearchPage method loadTreeState.
protected static List<DBNNode> loadTreeState(DBRProgressMonitor monitor, DBPPreferenceStore store, String propName) {
final List<DBNNode> result = new ArrayList<>();
final String sources = store.getString(propName);
if (!CommonUtils.isEmpty(sources)) {
// Keep broken datasources to make connect attempt only once
Set<DBNDataSource> brokenDataSources = new HashSet<>();
// Find all nodes
//$NON-NLS-1$
StringTokenizer st = new StringTokenizer(sources, "|");
while (st.hasMoreTokens()) {
String nodePath = st.nextToken();
try {
DBNDataSource dsNode = DBeaverCore.getInstance().getNavigatorModel().getDataSourceByPath(nodePath);
if (dsNode == null || brokenDataSources.contains(dsNode)) {
continue;
}
DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByPath(monitor, dsNode.getOwnerProject(), nodePath);
if (node != null) {
result.add(node);
} else {
brokenDataSources.add(dsNode);
}
} catch (DBException e) {
log.error(e);
}
}
}
return result;
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class SearchDataQuery method findRows.
private DBCStatistics findRows(@NotNull DBCSession session, @NotNull DBSDataContainer dataContainer, @NotNull TestDataReceiver dataReceiver) throws DBCException {
DBSEntity entity;
if (dataContainer instanceof DBSEntity) {
entity = (DBSEntity) dataContainer;
} else {
log.warn("Data container " + dataContainer + " isn't entity");
return null;
}
try {
List<DBDAttributeConstraint> constraints = new ArrayList<>();
for (DBSEntityAttribute attribute : CommonUtils.safeCollection(entity.getAttributes(session.getProgressMonitor()))) {
if (params.fastSearch) {
if (!DBUtils.isIndexedAttribute(session.getProgressMonitor(), attribute)) {
continue;
}
}
if (DBUtils.isPseudoAttribute(attribute) || DBUtils.isHiddenObject(attribute)) {
continue;
}
DBCLogicalOperator[] supportedOperators = DBUtils.getAttributeOperators(attribute);
DBCLogicalOperator operator;
Object value;
switch(attribute.getDataKind()) {
case BOOLEAN:
continue;
case NUMERIC:
if (!params.searchNumbers) {
continue;
}
if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
continue;
}
operator = DBCLogicalOperator.EQUALS;
try {
value = new Integer(params.searchString);
} catch (NumberFormatException e) {
try {
value = new Long(params.searchString);
} catch (NumberFormatException e1) {
try {
value = new Double(params.searchString);
} catch (NumberFormatException e2) {
try {
value = new BigDecimal(params.searchString);
} catch (Exception e3) {
// Not a number
continue;
}
}
}
}
break;
case CONTENT:
case BINARY:
if (!params.searchLOBs) {
continue;
}
case STRING:
if (attribute.getMaxLength() > 0 && attribute.getMaxLength() < params.searchString.length()) {
continue;
}
if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.LIKE)) {
operator = DBCLogicalOperator.LIKE;
value = "%" + params.searchString + "%";
} else if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
operator = DBCLogicalOperator.EQUALS;
value = params.searchString;
} else {
continue;
}
break;
default:
{
// On success search by exact match
if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
continue;
}
String typeName = attribute.getTypeName();
if (typeName.equals(DBConstants.TYPE_NAME_UUID) || typeName.equals(DBConstants.TYPE_NAME_UUID2)) {
try {
UUID uuid = UUID.fromString(params.searchString);
operator = DBCLogicalOperator.EQUALS;
value = "'" + uuid.toString() + "'";
} catch (Exception e) {
// No a UUID
continue;
}
} else {
continue;
}
}
}
DBDAttributeConstraint constraint = new DBDAttributeConstraint(attribute, constraints.size());
constraint.setOperator(operator);
constraint.setValue(value);
constraint.setVisible(true);
constraints.add(constraint);
}
if (constraints.isEmpty()) {
return null;
}
dataReceiver.filter = new DBDDataFilter(constraints);
dataReceiver.filter.setAnyConstraint(true);
DBCExecutionSource searchSource = new AbstractExecutionSource(dataContainer, session.getExecutionContext(), this);
return dataContainer.readData(searchSource, session, dataReceiver, dataReceiver.filter, -1, -1, 0);
} catch (DBException e) {
throw new DBCException("Error finding rows", e);
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class SearchMetadataQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
List<DBSObjectType> objectTypes = params.getObjectTypes();
String objectNameMask = params.getObjectNameMask();
if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_STARTS_WITH) {
if (!objectNameMask.endsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
} else if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_CONTAINS) {
if (!objectNameMask.startsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = "%" + objectNameMask;
}
if (!objectNameMask.endsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
}
DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
Collection<DBSObjectReference> objects = structureAssistant.findObjectsByMask(localMonitor, params.getParentObject(), objectTypes.toArray(new DBSObjectType[objectTypes.size()]), objectNameMask, params.isCaseSensitive(), true, params.getMaxResults());
for (DBSObjectReference reference : objects) {
if (monitor.isCanceled()) {
break;
}
try {
DBSObject object = reference.resolveObject(localMonitor);
if (object != null) {
DBNNode node = navigatorModel.getNodeByObject(localMonitor, object, false);
if (node != null) {
searchResult.addObjects(Collections.singletonList(node));
}
}
} catch (DBException e) {
log.error(e);
}
}
return Status.OK_STATUS;
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DB2DataSource method initialize.
// -----------------------
// Initialisation/Structure
// -----------------------
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
super.initialize(monitor);
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load data source meta info")) {
// First try to get active schema from special register 'CURRENT SCHEMA'
this.activeSchemaName = determineActiveSchema(session);
this.db2CurrentUserPrivileges = new DB2CurrentUserPrivileges(monitor, session, activeSchemaName, this);
} catch (SQLException e) {
LOG.warn("Error reading active schema", e);
}
try {
this.dataTypeCache.getAllObjects(monitor, this);
} catch (DBException e) {
LOG.warn("Error reading types info", e);
this.dataTypeCache.setCache(Collections.<DB2DataType>emptyList());
}
}
Aggregations