use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class SQLCompletionProcessor method makeTemplateProposals.
@NotNull
private ICompletionProposal[] makeTemplateProposals(ITextViewer viewer, SQLCompletionAnalyzer.CompletionRequest request) {
String wordPart = request.wordPart.toLowerCase();
final List<SQLTemplateCompletionProposal> templateProposals = new ArrayList<>();
// Templates
for (Template template : editor.getTemplatesPage().getTemplateStore().getTemplates()) {
if (template.getName().toLowerCase().startsWith(wordPart)) {
templateProposals.add(new SQLTemplateCompletionProposal(template, new SQLContext(SQLTemplatesRegistry.getInstance().getTemplateContextRegistry().getContextType(template.getContextTypeId()), viewer.getDocument(), new Position(request.wordDetector.getStartOffset(), request.wordDetector.getLength()), editor), new Region(request.documentOffset, 0), null));
}
}
Collections.sort(templateProposals, new Comparator<SQLTemplateCompletionProposal>() {
@Override
public int compare(SQLTemplateCompletionProposal o1, SQLTemplateCompletionProposal o2) {
return o1.getDisplayString().compareTo(o2.getDisplayString());
}
});
return templateProposals.toArray(new ICompletionProposal[templateProposals.size()]);
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class JDBCCollection method makeCollectionFromString.
@NotNull
public static DBDCollection makeCollectionFromString(@NotNull JDBCSession session, String value) throws DBCException {
String stringType = DBUtils.getDefaultDataTypeName(session.getDataSource(), DBPDataKind.STRING);
if (stringType == null) {
throw new DBCException("String data type not supported by database");
}
DBSDataType dataType = DBUtils.getLocalDataType(session.getDataSource(), stringType);
if (dataType == null) {
throw new DBCException("String data type '" + stringType + "' not supported by database");
}
DBDValueHandler valueHandler = DBUtils.findValueHandler(session, dataType);
// Try to divide on string elements
if (!CommonUtils.isEmpty(value)) {
if (value.startsWith("[") && value.endsWith("]")) {
// FIXME: use real parser (nested arrays, quotes escape, etc)
String arrayString = value.substring(1, value.length() - 1);
List<Object> items = new ArrayList<>();
StringTokenizer st = new StringTokenizer(arrayString, ",", false);
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
if (token.startsWith("\"") && token.endsWith("\"")) {
token = token.substring(1, token.length() - 1);
}
items.add(token);
}
return new JDBCCollectionString(dataType, valueHandler, value, items.toArray());
}
}
return new JDBCCollectionString(dataType, valueHandler, value);
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class JDBCCollection method makeCollectionFromJavaArray.
@NotNull
private static JDBCCollection makeCollectionFromJavaArray(@NotNull JDBCSession session, @NotNull DBSDataType elementType, @NotNull DBDValueHandler elementValueHandler, @Nullable Object arrObject) throws DBCException {
int arrLength = arrObject == null ? 0 : java.lang.reflect.Array.getLength(arrObject);
Object[] contents = new Object[arrLength];
Object itemValue;
for (int i = 0; i < arrLength; i++) {
Object item = java.lang.reflect.Array.get(arrObject, i);
if (item != null && item.getClass().isArray() && elementType.getDataKind() != DBPDataKind.ARRAY) {
// This may happen in case of multidimensional array
itemValue = makeCollectionFromJavaArray(session, elementType, elementValueHandler, item);
} else {
itemValue = elementValueHandler.getValueFromObject(session, elementType, item, false);
}
contents[i] = itemValue;
}
return new JDBCCollection(elementType, elementValueHandler, contents);
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class JDBCCollection method makeCollectionFromArray.
@NotNull
private static JDBCCollection makeCollectionFromArray(@NotNull JDBCSession session, @Nullable Array array, @NotNull DBSDataType elementType) throws SQLException, DBCException {
final DBDValueHandler elementValueHandler = DBUtils.findValueHandler(session, elementType);
if (array == null) {
return new JDBCCollection(elementType, elementValueHandler, null);
}
Object arrObject = array.getArray();
return makeCollectionFromJavaArray(session, elementType, elementValueHandler, arrObject);
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class JDBCCollection method makeCollectionFromArray.
/////////////////////////////////////////////////////////////////////////////////////
// Utilities
/////////////////////////////////////////////////////////////////////////////////////
@NotNull
public static JDBCCollection makeCollectionFromArray(@NotNull JDBCSession session, @NotNull DBSTypedObject column, Array array) throws DBCException {
DBRProgressMonitor monitor = session.getProgressMonitor();
DBSDataType elementType = null;
if (column instanceof DBSTypedObjectEx) {
DBSDataType arrayType = ((DBSTypedObjectEx) column).getDataType();
if (arrayType != null) {
elementType = arrayType.getComponentType(monitor);
}
}
if (elementType == null) {
try {
if (array == null) {
String arrayTypeName = column.getTypeName();
DBSDataType arrayType = session.getDataSource().resolveDataType(monitor, arrayTypeName);
if (arrayType != null) {
elementType = arrayType.getComponentType(monitor);
}
} else {
String baseTypeName = array.getBaseTypeName();
elementType = session.getDataSource().resolveDataType(monitor, baseTypeName);
}
} catch (Exception e) {
throw new DBCException("Error resolving data type", e);
}
}
try {
if (elementType == null) {
if (array == null) {
throw new DBCException("Can't resolve NULL array data type");
}
try {
return makeCollectionFromResultSet(session, array, null);
} catch (SQLException e) {
//$NON-NLS-1$
throw new DBCException(e, session.getDataSource());
}
}
try {
return makeCollectionFromArray(session, array, elementType);
} catch (SQLException e) {
if (array == null) {
//$NON-NLS-1$
throw new DBCException(e, session.getDataSource());
}
try {
return makeCollectionFromResultSet(session, array, elementType);
} catch (SQLException e1) {
//$NON-NLS-1$
throw new DBCException(e1, session.getDataSource());
}
}
} catch (DBException e) {
//$NON-NLS-1$
throw new DBCException("Can't extract array data from JDBC array", e);
}
}
Aggregations