use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class JDBCTableColumn method getValueEnumeration.
@NotNull
@Override
public Collection<DBDLabelValuePair> getValueEnumeration(@NotNull DBCSession session, @Nullable Object valuePattern, int maxResults) throws DBException {
DBDValueHandler valueHandler = DBUtils.findValueHandler(session, this);
StringBuilder query = new StringBuilder();
query.append("SELECT ").append(DBUtils.getQuotedIdentifier(this)).append(", count(*)");
// Do not use description columns because they duplicate distinct value
// String descColumns = DBVUtils.getDictionaryDescriptionColumns(session.getProgressMonitor(), this);
// if (descColumns != null) {
// query.append(", ").append(descColumns);
// }
query.append("\nFROM ").append(DBUtils.getObjectFullName(getTable(), DBPEvaluationContext.DML));
if (valuePattern instanceof String) {
query.append("\nWHERE ").append(DBUtils.getQuotedIdentifier(this)).append(" LIKE ?");
}
query.append("\nGROUP BY ").append(DBUtils.getQuotedIdentifier(this));
try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, query.toString(), false, false, false)) {
if (valuePattern instanceof String) {
valueHandler.bindValueObject(session, dbStat, this, 0, "%" + valuePattern + "%");
}
dbStat.setLimit(0, maxResults);
if (dbStat.executeStatement()) {
try (DBCResultSet dbResult = dbStat.openResultSet()) {
return DBVUtils.readDictionaryRows(session, this, valueHandler, dbResult);
}
} else {
return Collections.emptyList();
}
}
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class DBVUtils method readDictionaryRows.
@NotNull
public static List<DBDLabelValuePair> readDictionaryRows(DBCSession session, DBSEntityAttribute valueAttribute, DBDValueHandler valueHandler, DBCResultSet dbResult) throws DBCException {
List<DBDLabelValuePair> values = new ArrayList<>();
List<DBCAttributeMetaData> metaColumns = dbResult.getMeta().getAttributes();
List<DBDValueHandler> colHandlers = new ArrayList<>(metaColumns.size());
for (DBCAttributeMetaData col : metaColumns) {
colHandlers.add(DBUtils.findValueHandler(session, col));
}
// Extract enumeration values and (optionally) their descriptions
while (dbResult.nextRow()) {
// Check monitor
if (session.getProgressMonitor().isCanceled()) {
break;
}
// Get value and description
Object keyValue = valueHandler.fetchValueObject(session, dbResult, valueAttribute, 0);
if (keyValue == null) {
continue;
}
String keyLabel = valueHandler.getValueDisplayString(valueAttribute, keyValue, DBDDisplayFormat.NATIVE);
if (metaColumns.size() > 1) {
keyLabel = "";
for (int i = 1; i < colHandlers.size(); i++) {
Object descValue = colHandlers.get(i).fetchValueObject(session, dbResult, metaColumns.get(i), i);
if (!keyLabel.isEmpty()) {
keyLabel += " ";
}
keyLabel += colHandlers.get(i).getValueDisplayString(metaColumns.get(i), descValue, DBDDisplayFormat.NATIVE);
}
}
values.add(new DBDLabelValuePair(keyLabel, keyValue));
}
return values;
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class SQLUtils method generateScript.
@NotNull
public static String generateScript(DBPDataSource dataSource, DBEPersistAction[] persistActions, boolean addComments) {
SQLDialect sqlDialect = dataSource instanceof SQLDataSource ? ((SQLDataSource) dataSource).getSQLDialect() : null;
String lineSeparator = GeneralUtils.getDefaultLineSeparator();
StringBuilder script = new StringBuilder(64);
if (addComments) {
script.append(DBEAVER_DDL_COMMENT).append(Platform.getProduct().getName()).append(lineSeparator).append(DBEAVER_DDL_WARNING).append(lineSeparator);
}
if (persistActions != null) {
String redefiner = null;
if (sqlDialect != null) {
redefiner = sqlDialect.getScriptDelimiterRedefiner();
}
for (DBEPersistAction action : persistActions) {
String scriptLine = action.getScript();
if (CommonUtils.isEmpty(scriptLine)) {
continue;
}
String delimiter = sqlDialect == null ? SQLConstants.DEFAULT_STATEMENT_DELIMITER : sqlDialect.getScriptDelimiter();
if (action.isComplex() && redefiner != null) {
script.append(lineSeparator).append(redefiner).append(" ").append(DBEAVER_SCRIPT_DELIMITER).append(lineSeparator);
delimiter = DBEAVER_SCRIPT_DELIMITER;
script.append(delimiter).append(lineSeparator);
}
script.append(scriptLine);
script.append(" ").append(delimiter).append(lineSeparator);
if (action.isComplex() && redefiner != null) {
script.append(redefiner).append(" ").append(sqlDialect.getScriptDelimiter()).append(lineSeparator);
}
}
}
return script.toString();
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class GeneralUtils method getProductReleaseDate.
@NotNull
public static Date getProductReleaseDate() {
final IProduct product = Platform.getProduct();
if (product != null) {
Bundle definingBundle = product.getDefiningBundle();
final Dictionary<String, String> headers = definingBundle.getHeaders();
final String releaseDate = headers.get("Bundle-Release-Date");
if (releaseDate != null) {
try {
return new SimpleDateFormat(DEFAULT_DATE_PATTERN).parse(releaseDate);
} catch (ParseException e) {
log.debug(e);
}
}
final String buildTime = headers.get("Build-Time");
if (buildTime != null) {
try {
return new SimpleDateFormat(DEFAULT_TIMESTAMP_PATTERN).parse(buildTime);
} catch (ParseException e) {
log.debug(e);
}
}
}
// Failed to get valid date from product bundle
final Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2017);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return calendar.getTime();
}
use of org.jkiss.code.NotNull in project dbeaver by serge-rider.
the class SharedTextColors method getColor.
@NotNull
public Color getColor(String rgbString) {
RGB rgb;
synchronized (rgbMap) {
rgb = rgbMap.get(rgbString);
if (rgb == null) {
rgb = StringConverter.asRGB(rgbString);
rgbMap.put(rgbString, rgb);
}
}
return getColor(rgb);
}
Aggregations