提交 2b9acf68 编写于 作者: S Serge Rider

Merge remote-tracking branch 'origin/devel' into devel

......@@ -140,7 +140,7 @@ public class ResultSetUtils
// Init row identifiers
monitor.subTask("Detect unique identifiers");
for (DBDAttributeBindingMeta binding : bindings) {
monitor.subTask("Find attribute '" + binding.getName() + "' identifier");
//monitor.subTask("Find attribute '" + binding.getName() + "' identifier");
DBSEntityAttribute attr = binding.getEntityAttribute();
if (attr == null) {
continue;
......@@ -253,18 +253,9 @@ public class ResultSetUtils
} else if (identifiers.isEmpty()) {
// Check constraints
Collection<? extends DBSEntityConstraint> constraints = table.getConstraints(monitor);
if (constraints != null) {
for (DBSEntityConstraint constraint : constraints) {
if (constraint instanceof DBSEntityReferrer && constraint.getConstraintType().isUnique()) {
identifiers.add((DBSEntityReferrer)constraint);
}
}
}
if (identifiers.isEmpty() && table instanceof DBSTable) {
// Check indexes first.
if (table instanceof DBSTable) {
try {
// Check indexes only if no unique constraints found
Collection<? extends DBSTableIndex> indexes = ((DBSTable)table).getIndexes(monitor);
if (!CommonUtils.isEmpty(indexes)) {
for (DBSTableIndex index : indexes) {
......@@ -280,6 +271,18 @@ public class ResultSetUtils
log.debug(e);
}
}
if (identifiers.isEmpty()) {
// Check constraints
Collection<? extends DBSEntityConstraint> constraints = table.getConstraints(monitor);
if (constraints != null) {
for (DBSEntityConstraint constraint : constraints) {
if (constraint instanceof DBSEntityReferrer && constraint.getConstraintType().isUnique()) {
identifiers.add((DBSEntityReferrer) constraint);
}
}
}
}
}
if (CommonUtils.isEmpty(identifiers)) {
// No physical identifiers
......
......@@ -565,29 +565,6 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
{
String objectName = DBUtils.getObjectFullName(object);
StringBuilder info = new StringBuilder();
PropertyCollector collector = new PropertyCollector(object, false);
collector.collectProperties();
for (DBPPropertyDescriptor descriptor : collector.getPropertyDescriptors2()) {
if (descriptor.isRemote()) {
// Skip lazy properties
continue;
}
Object propValue = collector.getPropertyValue(monitor, descriptor.getId());
if (propValue == null) {
continue;
}
String propString;
if (propValue instanceof DBPNamedObject) {
propString = ((DBPNamedObject) propValue).getName();
} else {
propString = DBUtils.getDefaultValueDisplayString(propValue, DBDDisplayFormat.UI);
}
info.append("<b>").append(descriptor.getDisplayName()).append(": </b>");
info.append(propString);
info.append("<br>");
}
boolean isSingleObject = true;
String replaceString = null;
DBPDataSource dataSource = editor.getDataSource();
......@@ -619,12 +596,38 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
return createCompletionProposal(
replaceString,
objectName,
info.toString(),
null,
objectIcon,
isSingleObject,
object);
}
public static String makeObjectDescription(DBRProgressMonitor monitor, DBPNamedObject object) {
StringBuilder info = new StringBuilder();
PropertyCollector collector = new PropertyCollector(object, false);
collector.collectProperties();
for (DBPPropertyDescriptor descriptor : collector.getPropertyDescriptors2()) {
if (descriptor.isRemote()) {
// Skip lazy properties
continue;
}
Object propValue = collector.getPropertyValue(monitor, descriptor.getId());
if (propValue == null) {
continue;
}
String propString;
if (propValue instanceof DBPNamedObject) {
propString = ((DBPNamedObject) propValue).getName();
} else {
propString = DBUtils.getDefaultValueDisplayString(propValue, DBDDisplayFormat.UI);
}
info.append("<b>").append(descriptor.getDisplayName()).append(": </b>");
info.append(propString);
info.append("<br>");
}
return info.toString();
}
private DBPPreferenceStore getPreferences() {
DBPPreferenceStore store = null;
DBPDataSource dataSource = editor.getDataSource();
......
......@@ -29,6 +29,7 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectReference;
......@@ -144,6 +145,9 @@ public class SQLCompletionProposal implements ICompletionProposal, ICompletionPr
@Override
public String getAdditionalProposalInfo()
{
if (additionalProposalInfo == null && object != null) {
additionalProposalInfo = SQLCompletionProcessor.makeObjectDescription(VoidProgressMonitor.INSTANCE, object);
}
return additionalProposalInfo;
}
......
......@@ -31,11 +31,13 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCCompositeCache;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectLookup;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache;
import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import org.jkiss.utils.ArrayUtils;
......@@ -351,7 +353,7 @@ public class OracleSchema extends OracleGlobalObject implements DBSSchema, DBPRe
return tableColumn;
}
public static class TableCache extends JDBCStructCache<OracleSchema, OracleTableBase, OracleTableColumn> {
public static class TableCache extends JDBCStructCache<OracleSchema, OracleTableBase, OracleTableColumn> implements JDBCObjectLookup {
private static final Comparator<? super OracleTableColumn> ORDER_COMPARATOR = new Comparator<OracleTableColumn>() {
@Override
......@@ -370,17 +372,25 @@ public class OracleSchema extends OracleGlobalObject implements DBSSchema, DBPRe
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull OracleSchema owner)
throws SQLException
{
return prepareObjectsStatement(session, owner, null);
}
@Override
public JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull DBSObject owner, @Nullable String objectName) throws SQLException {
final JDBCPreparedStatement dbStat = session.prepareStatement(
"\tSELECT /*+RULE*/ t.OWNER,t.TABLE_NAME as TABLE_NAME,'TABLE' as OBJECT_TYPE,'VALID' as STATUS,t.TABLE_TYPE_OWNER,t.TABLE_TYPE,t.TABLESPACE_NAME,t.PARTITIONED,t.IOT_TYPE,t.IOT_NAME,t.TEMPORARY,t.SECONDARY,t.NESTED,t.NUM_ROWS \n" +
"\tFROM SYS.ALL_ALL_TABLES t\n" +
"\tWHERE t.OWNER=? AND NESTED='NO'\n" +
"\tWHERE t.OWNER=? AND NESTED='NO'" + (objectName == null ? "": " AND t.TABLE_NAME=?") + "\n" +
"UNION ALL\n" +
"\tSELECT /*+RULE*/ o.OWNER,o.OBJECT_NAME as TABLE_NAME,'VIEW' as OBJECT_TYPE,o.STATUS,NULL,NULL,NULL,NULL,NULL,NULL,o.TEMPORARY,o.SECONDARY,NULL,NULL \n" +
"\tFROM SYS.ALL_OBJECTS o \n" +
"\tWHERE o.OWNER=? AND o.OBJECT_TYPE='VIEW'\n"
"\tWHERE o.OWNER=? AND o.OBJECT_TYPE='VIEW'" + (objectName == null ? "": " AND o.OBJECT_NAME=?") + "\n"
);
dbStat.setString(1, owner.getName());
dbStat.setString(2, owner.getName());
int index = 1;
dbStat.setString(index++, owner.getName());
if (objectName != null) dbStat.setString(index++, objectName);
dbStat.setString(index++, owner.getName());
if (objectName != null) dbStat.setString(index, objectName);
return dbStat;
}
......@@ -436,6 +446,7 @@ public class OracleSchema extends OracleGlobalObject implements DBSSchema, DBPRe
Collections.sort(oracleTableColumns, ORDER_COMPARATOR);
super.cacheChildren(parent, oracleTableColumns);
}
}
/**
......@@ -458,7 +469,7 @@ public class OracleSchema extends OracleGlobalObject implements DBSSchema, DBPRe
"c.TABLE_NAME, c.CONSTRAINT_NAME,c.CONSTRAINT_TYPE,c.STATUS,c.SEARCH_CONDITION," +
"col.COLUMN_NAME,col.POSITION\n" +
"FROM SYS.ALL_CONSTRAINTS c\n" +
"LEFT OUTER JOIN SYS.ALL_CONS_COLUMNS col ON c.OWNER=col.OWNER AND c.CONSTRAINT_NAME=col.CONSTRAINT_NAME\n" +
"JOIN SYS.ALL_CONS_COLUMNS col ON c.OWNER=col.OWNER AND c.CONSTRAINT_NAME=col.CONSTRAINT_NAME\n" +
"WHERE c.CONSTRAINT_TYPE<>'R' AND c.OWNER=?");
if (forTable != null) {
sql.append(" AND c.TABLE_NAME=?");
......@@ -531,7 +542,7 @@ public class OracleSchema extends OracleGlobalObject implements DBSSchema, DBPRe
"col.COLUMN_NAME,col.POSITION\r\n" +
"FROM SYS.ALL_CONSTRAINTS c\n" +
"JOIN SYS.ALL_CONS_COLUMNS col ON c.OWNER=col.OWNER AND c.CONSTRAINT_NAME=col.CONSTRAINT_NAME\n" +
"LEFT OUTER JOIN SYS.ALL_CONSTRAINTS ref ON ref.OWNER=c.r_OWNER AND ref.CONSTRAINT_NAME=c.R_CONSTRAINT_NAME \n" +
"JOIN SYS.ALL_CONSTRAINTS ref ON ref.OWNER=c.r_OWNER AND ref.CONSTRAINT_NAME=c.R_CONSTRAINT_NAME \n" +
"WHERE c.CONSTRAINT_TYPE='R' AND c.OWNER=?");
if (forTable != null) {
sql.append(" AND c.TABLE_NAME=?");
......
......@@ -40,7 +40,7 @@ import java.util.*;
*/
public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DBSObject> extends AbstractObjectCache<OWNER, OBJECT>
{
public static final int DEFAULT_MAX_CACHE_SIZE = 100000;
public static final int DEFAULT_MAX_CACHE_SIZE = 1000000;
static final Log log = Log.getLog(AbstractObjectCache.class);
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.model.impl.jdbc.cache;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.impl.AbstractObjectCache;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.sql.SQLException;
import java.util.*;
/**
* Extension of {@link JDBCObjectCache} - support object lookup by name
*/
public interface JDBCObjectLookup<OWNER extends DBSObject>
{
JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull OWNER owner, @Nullable String objectName)
throws SQLException;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册