@Override Collection<DbAttribute> getAll() { return container.getAttributes(); } }
/** * Creates new InsertBatchQuery for a given DbEntity and estimated capacity. */ public InsertBatchQuery(DbEntity entity, int batchCapacity) { super(entity, new ArrayList<>(entity.getAttributes()), batchCapacity); }
public DbAttributeTableModel(DbEntity entity, ProjectController mediator, Object eventSource) { this(entity, mediator, eventSource, new ArrayList<DbAttribute>(entity .getAttributes())); this.entity = entity; }
/** * Creates new InsertBatchQuery for a given DbEntity and estimated capacity. */ public InsertBatchQuery(DbEntity entity, int batchCapacity) { super(entity); this.objectSnapshots = new ArrayList(batchCapacity); this.objectIds = new ArrayList(batchCapacity); this.dbAttributes = new ArrayList(getDbEntity().getAttributes()); }
/** * Returns attributes used in GROUP BY as an unmodifiable list. */ public List getGroupByAttributes() { List list = new ArrayList(); Iterator it = super.getAttributes().iterator(); while (it.hasNext()) { DerivedDbAttribute attr = (DerivedDbAttribute) it.next(); if (attr.isGroupBy()) { list.add(attr); } } return list; }
/** * case insensitive search for a {@link DbAttribute} in a {@link DbEntity} * by name */ private DbAttribute findDbAttribute(DbEntity entity, String caseInsensitiveName) { if (entity == null) { return null; } for (DbAttribute a : entity.getAttributes()) { if (a.getName().equalsIgnoreCase(caseInsensitiveName)) { return a; } } return null; }
/** * Returns a list of attributes that will be included in the results of this query. */ public List getCustomDbAttributes() { // if query root is DbEntity, and no custom attributes // are defined, return DbEntity attributes. if ((customDbAttributes == null || customDbAttributes.isEmpty()) && (root instanceof DbEntity)) { Collection attributes = ((DbEntity) root).getAttributes(); List attributeNames = new ArrayList(attributes.size()); Iterator it = attributes.iterator(); while (it.hasNext()) { DbAttribute attribute = (DbAttribute) it.next(); attributeNames.add(attribute.getName()); } return attributeNames; } else { return (customDbAttributes != null) ? customDbAttributes : Collections.EMPTY_LIST; } }
/** * Tables must have columns. */ void validateAttributes(DbEntity entity, ValidationResult validationResult) { if (entity.getAttributes().size() == 0) { addFailure( validationResult, entity, "DbEntity '%s' has no attributes defined", entity.getName()); } }
protected DbAttribute getJoinAttribute(DbEntity sEntity, DbEntity tEntity) { if (sEntity.getAttributes().size() == 1) { return sEntity.getAttributes().iterator().next(); } else { for (DbAttribute attr : sEntity.getAttributes()) { if (attr.getName().equalsIgnoreCase(tEntity.getName() + "_ID")) { return attr; } } for (DbAttribute attr : sEntity.getAttributes()) { if ((attr.getName().equalsIgnoreCase(sEntity.getName() + "_ID")) && (!attr.isPrimaryKey())) { return attr; } } for (DbAttribute attr : sEntity.getAttributes()) { if (attr.isPrimaryKey()) { return attr; } } } return null; }
/** * Tables must have columns. */ protected void validateAttributes( DbEntity ent, ProjectPath path, Validator validator) { if (ent.getAttributes().size() == 0) { // complain about missing attributes validator.registerWarning( "DbEntity \"" + ent.getName() + "\" has no attributes defined.", path); } }
<T> List<ColumnDescriptor> appendDbEntityColumns(List<ColumnDescriptor> columns, SelectQuery<T> query) { Set<ColumnTracker> attributes = new HashSet<>(); DbEntity table = getQueryMetadata().getDbEntity(); for (DbAttribute dba : table.getAttributes()) { appendColumn(columns, null, dba, attributes, null); } return columns; }
/** * Returns a list of attributes that exist in the DbEntity, but are missing * from the ObjEntity. */ private List<DbAttribute> getAttributesToAdd(ObjEntity objEntity) { DbEntity dbEntity = objEntity.getDbEntity(); List<DbAttribute> missing = new ArrayList<>(); Collection<DbRelationship> incomingRels = getIncomingRelationships(dbEntity); for (DbAttribute dba : dbEntity.getAttributes()) { if (shouldAddToObjEntity(objEntity, dba, incomingRels)) { missing.add(dba); } } return missing; }
/** * Validates the presence of the primary key. A warning is given only if the parent * map also contains an ObjEntity mapped to this entity, since unmapped primary key is * ok if working with data rows. */ void validatePK(DbEntity entity, ValidationResult validationResult) { if (entity.getAttributes().size() > 0 && entity.getPrimaryKeys().size() == 0) { DataMap map = entity.getDataMap(); if (map != null && map.getMappedEntities(entity).size() > 0) { addFailure( validationResult, entity, "DbEntity '%s' has no primary key attributes defined", entity.getName()); } } }
public ValidationResult visitDbEntity(DbEntity entity) { dbEntityValidator.validate(entity, validationResult); for (DbAttribute attr : entity.getAttributes()) { visitDbAttribute(attr); } for (DbRelationship rel : entity.getRelationships()) { visitDbRelationship(rel); } return validationResult; }
private String getDBAttrType(String dbAttributeName) { DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity(); if (currentEnt != null && currentEnt.getAttributes() != null && dbAttributeName != null) { DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(dbAttributeName); if (dbAttr != null) { return TypesMapping.getSqlNameByType(dbAttr.getType()); } } return null; }
@Override public void execute(MergerContext mergerContext) { DbEntity e = getEntity(); for (DbAttribute attr : e.getAttributes()) { boolean wasPrimaryKey = attr.isPrimaryKey(); boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr .getName() .toUpperCase()); if (wasPrimaryKey != willBePrimaryKey) { attr.setPrimaryKey(willBePrimaryKey); e.dbAttributeChanged(new AttributeEvent(this, attr, e)); mergerContext.getDelegate().dbAttributeModified(attr); } } } }
@Override protected void processTerminatingRelationship(ObjRelationship relationship) { Collection<DbAttribute> dbAttr = ((ObjEntity) relationship.getTargetEntity()).getDbEntity() .getAttributes(); DbRelationship dbRelationship = relationship.getDbRelationships().get(0); DbEntity table = (DbEntity) dbRelationship.getTargetEntity(); Iterator<DbAttribute> it = dbAttr.iterator(); String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context .getQuotingStrategy().quotedFullyQualifiedName(table)); boolean first = true; while (it.hasNext()) { context.append(!first ? ", " : " "); DbAttribute dbAttribute = it.next(); context.append(alias).append('.').append(context.getQuotingStrategy().quotedName(dbAttribute)); first = false; } }
@Override protected void processTerminatingRelationship(ObjRelationship relationship) { Collection<DbAttribute> dbAttr = relationship.getTargetEntity().getDbEntity().getAttributes(); if (dbAttr.size() > 0) { resolveJoin(); } DbAttribute pk = getPk(relationship.getTargetEntity().getDbEntity()); context.append(lastAlias).append('.').append(context.getQuotingStrategy().quotedName(pk)); } }
/** * Returns whether a table has identity columns. */ protected boolean expectsToOverrideIdentityColumns() { // jTDS driver supports identity columns, no need for tricks... if (dataNode.getAdapter().supportsGeneratedKeys()) { return false; } if (!(query instanceof InsertBatchQuery) || query.getDbEntity() == null) { return false; } // find identity attributes for (DbAttribute attribute : query.getDbEntity().getAttributes()) { if (attribute.isGenerated()) { return true; } } return false; } }
private void searchInDbEntities(Pattern pattern, List<SearchResultEntry> result, DataMap dataMap) { for (DbEntity ent : dataMap.getDbEntities()) { if (match(ent.getName(), pattern)) { result.add(new SearchResultEntry(ent, ent.getName())); } for (DbAttribute attr : ent.getAttributes()) { if (match(attr.getName(), pattern)) { result.add(new SearchResultEntry(attr, ent.getName() + "." + attr.getName())); } } for (DbRelationship rel : ent.getRelationships()) { if (match(rel.getName(), pattern)) { result.add(new SearchResultEntry(rel, ent.getName() + "." + rel.getName())); } } checkCatalogOrSchema(pattern, result, ent, ent.getCatalog()); checkCatalogOrSchema(pattern, result, ent, ent.getSchema()); } }