/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.virtual;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.utils.CommonUtils;
import java.util.*;
/**
* Virtual attribute
*/
public class DBVEntityAttribute implements DBSEntityAttribute
{
private final DBVEntity entity;
private final DBVEntityAttribute parent;
private final List<DBVEntityAttribute> children = new ArrayList<>();
private String name;
private String defaultValue;
private String description;
private DBVTransformSettings transformSettings;
public DBVEntityAttribute(DBVEntity entity, DBVEntityAttribute parent, String name) {
this.entity = entity;
this.parent = parent;
this.name = name;
}
public DBVEntityAttribute(DBVEntity entity, DBVEntityAttribute parent, DBVEntityAttribute copy) {
this.entity = entity;
this.parent = parent;
this.name = copy.name;
for (DBVEntityAttribute child : copy.children) {
this.children.add(new DBVEntityAttribute(entity, this, child));
}
}
@NotNull
@Override
public DBVEntity getParentObject() {
return entity;
}
@NotNull
public DBVEntity getEntity() {
return entity;
}
@Nullable
public DBVEntityAttribute getParent() {
return parent;
}
@NotNull
@Override
public DBPDataSource getDataSource() {
return entity.getDataSource();
}
@NotNull
@Override
public String getName() {
return name;
}
@Override
public String getTypeName() {
return "void";
}
@Override
public String getFullTypeName() {
return getTypeName();
}
@Override
public int getTypeID() {
return -1;
}
@Override
public DBPDataKind getDataKind() {
return DBPDataKind.UNKNOWN;
}
@Override
public int getScale() {
return -1;
}
@Override
public int getPrecision() {
return -1;
}
@Override
public long getMaxLength() {
return -1;
}
@Override
public boolean isPersisted() {
return true;
}
@Override
public int getOrdinalPosition() {
return 0;
}
@Override
public boolean isRequired() {
return false;
}
@Override
public boolean isAutoGenerated() {
return false;
}
@Nullable
@Override
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
@Nullable
@Override
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<DBVEntityAttribute> getChildren() {
return children;
}
public DBVEntityAttribute getChild(String name) {
return DBUtils.findObject(children, name);
}
public void addChild(DBVEntityAttribute child) {
this.children.add(child);
}
public DBVTransformSettings getTransformSettings() {
return transformSettings;
}
public void setTransformSettings(DBVTransformSettings transformSettings) {
this.transformSettings = transformSettings;
}
public boolean hasValuableData() {
if (!CommonUtils.isEmpty(defaultValue) || !CommonUtils.isEmpty(description)) {
return true;
}
if (!children.isEmpty()) {
for (DBVEntityAttribute child : children) {
if (child.hasValuableData()) {
return true;
}
}
}
return transformSettings != null && transformSettings.hasValuableData();
}
}