Search in sources :

Example 1 with Property

use of org.jkiss.dbeaver.model.meta.Property in project dbeaver by serge-rider.

the class OracleDataType method getComponentType.

@Property(viewable = true, order = 8)
public OracleDataType getComponentType(@NotNull DBRProgressMonitor monitor) throws DBCException {
    if (componentType != null) {
        return componentType;
    }
    OracleSchema schema = getSchema();
    if (schema == null || !TYPE_CODE_COLLECTION.equals(typeCode) || !getDataSource().isAtLeastV10()) {
        return null;
    }
    try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load collection types")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT ELEM_TYPE_OWNER,ELEM_TYPE_NAME,ELEM_TYPE_MOD FROM SYS.ALL_COLL_TYPES WHERE OWNER=? AND TYPE_NAME=?")) {
            dbStat.setString(1, schema.getName());
            dbStat.setString(2, getName());
            try (JDBCResultSet dbResults = dbStat.executeQuery()) {
                if (dbResults.next()) {
                    String compTypeSchema = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_OWNER");
                    String compTypeName = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_NAME");
                    //String compTypeMod = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_MOD");
                    componentType = OracleDataType.resolveDataType(monitor, getDataSource(), compTypeSchema, compTypeName);
                } else {
                    log.warn("Can't resolve collection type [" + getName() + "]");
                }
            }
        }
    } catch (Exception e) {
        log.warn("Error reading collection types", e);
    }
    return componentType;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException) Property(org.jkiss.dbeaver.model.meta.Property)

Example 2 with Property

use of org.jkiss.dbeaver.model.meta.Property in project dbeaver by serge-rider.

the class PostgreViewBase method getObjectDefinitionText.

@Override
@Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor) throws DBException {
    if (source == null) {
        if (isPersisted()) {
            try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read view definition")) {
                String definition = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(?, true)", getObjectId());
                this.source = PostgreUtils.getViewDDL(this, definition);
            } catch (SQLException e) {
                throw new DBException("Error reading view definition", e);
            }
        } else {
            source = "";
        }
    }
    return source;
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) Property(org.jkiss.dbeaver.model.meta.Property)

Example 3 with Property

use of org.jkiss.dbeaver.model.meta.Property in project dbeaver by serge-rider.

the class ObjectAttributeDescriptor method extractAnnotations.

static void extractAnnotations(DBPPropertySource source, ObjectPropertyGroupDescriptor parent, Class<?> theClass, List<ObjectPropertyDescriptor> annoProps, IPropertyFilter filter) {
    Method[] methods = theClass.getMethods();
    Map<String, Method> passedNames = new HashMap<>();
    for (Method method : methods) {
        String methodFullName = method.getDeclaringClass().getName() + "." + method.getName();
        final Method prevMethod = passedNames.get(methodFullName);
        if (prevMethod != null) {
            // The same method but probably with another return type
            final Class<?> prevReturnType = prevMethod.getReturnType();
            final Class<?> newReturnType = method.getReturnType();
            if (newReturnType == null || prevReturnType == null || newReturnType == prevReturnType || !prevReturnType.isAssignableFrom(newReturnType)) {
                continue;
            }
        // Let it another chance. New return types seems to be subclass of previous
        }
        final PropertyGroup propGroupInfo = method.getAnnotation(PropertyGroup.class);
        if (propGroupInfo != null && method.getReturnType() != null) {
            // Property group
            ObjectPropertyGroupDescriptor groupDescriptor = new ObjectPropertyGroupDescriptor(source, parent, method, propGroupInfo, filter);
            annoProps.addAll(groupDescriptor.getChildren());
        } else {
            final Property propInfo = method.getAnnotation(Property.class);
            if (propInfo == null || !BeanUtils.isGetterName(method.getName()) || method.getReturnType() == null) {
                continue;
            }
            // Single property
            ObjectPropertyDescriptor desc = new ObjectPropertyDescriptor(source, parent, propInfo, method);
            if (filter != null && !filter.select(desc)) {
                continue;
            }
            if (prevMethod != null) {
                // Remove previous anno
                for (Iterator<ObjectPropertyDescriptor> iter = annoProps.iterator(); iter.hasNext(); ) {
                    if (iter.next().getId().equals(desc.getId())) {
                        iter.remove();
                    }
                }
            }
            annoProps.add(desc);
            passedNames.put(methodFullName, method);
        }
    }
    Collections.sort(annoProps, ATTRIBUTE_DESCRIPTOR_COMPARATOR);
}
Also used : PropertyGroup(org.jkiss.dbeaver.model.meta.PropertyGroup) Method(java.lang.reflect.Method) Property(org.jkiss.dbeaver.model.meta.Property) LazyProperty(org.jkiss.dbeaver.model.meta.LazyProperty)

Aggregations

Property (org.jkiss.dbeaver.model.meta.Property)3 SQLException (java.sql.SQLException)2 DBException (org.jkiss.dbeaver.DBException)2 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)2 Method (java.lang.reflect.Method)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)1 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)1 LazyProperty (org.jkiss.dbeaver.model.meta.LazyProperty)1 PropertyGroup (org.jkiss.dbeaver.model.meta.PropertyGroup)1