protected boolean canCreatePK(DbEntity entity) { return entity.getPrimaryKeys().size() > 0; }
@Override public String quotedFullyQualifiedName(DbEntity entity) { return quotedIdentifier(entity.getDataMap(), entity.getCatalog(), entity.getSchema(), entity.getName()); }
@Override public boolean isNameInUse(String name) { DbEntity entity = (DbEntity) parent; // check if either attribute or relationship name matches... return entity.getAttribute(name) != null || entity.getRelationship(name) != null; } });
/** * 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()); } }
logObj.debug("Overwrite: " + oldEnt.getName()); map.removeDbEntity(oldEnt.getName(), true); delegate.dbEntityRemoved(oldEnt); logObj.debug("Keep old: " + oldEnt.getName()); DbEntity dbEntity = new DbEntity(); dbEntity.setName(table.getName()); dbEntity.setSchema(table.getSchema()); dbEntity.setCatalog(table.getCatalog()); if (!dbEntity.getName().equals(tableName)) { logObj.info("Incorrectly returned columns for '" + tableName allowNulls); attr.setEntity(dbEntity); dbEntity.addAttribute(attr); while (i.hasNext()) { DbEntity dbEntity = (DbEntity) i.next(); String tableName = dbEntity.getName(); ResultSet rs = metaData.getPrimaryKeys(null, dbEntity.getSchema(), tableName); DbAttribute attribute = (DbAttribute) dbEntity.getAttribute(keyName);
/** * Drops PK sequences for all specified DbEntities. */ @Override public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception { List<String> sequences = getExistingSequences(node); // drop obsolete sequences for (DbEntity dbEntity : dbEntities) { String name; if (dbEntity.getDataMap().isQuotingSQLIdentifiers()) { DbEntity tempEnt = new DbEntity(); DataMap dm = new DataMap(); dm.setQuotingSQLIdentifiers(false); tempEnt.setDataMap(dm); tempEnt.setName(dbEntity.getName()); name = stripSchemaName(sequenceName(tempEnt)); } else { name = stripSchemaName(sequenceName(dbEntity)); } if (sequences.contains(name)) { runUpdate(node, dropSequenceString(dbEntity)); } } }
String oldName = dbEntity.getName(); dbEntity.setName(NameBuilder .builder(dbEntity, dataMap) .baseName(dbEntity.getName()) .dupesPattern(COPY_PATTERN) .name()); if (!oldName.equals(dbEntity.getName())) { renamedDbEntities.put(oldName, dbEntity.getName()); for (DbRelationship rel : dbEntity.getRelationships()) { if (renamedDbEntities.containsKey(rel.getTargetEntityName())) { rel.setTargetEntityName(renamedDbEntities.get(rel dbEntity.setName(NameBuilder .builder(dbEntity, dataMap) .baseName(dbEntity.getName()) .dupesPattern(COPY_PATTERN) .name()); dbEntity.addAttribute(attr); CreateAttributeAction.fireDbAttributeEvent(this, mediator, mediator .getCurrentDataMap(), dbEntity, attr); dbEntity.addRelationship(rel); CreateRelationshipAction.fireDbRelationshipEvent( this,
if (dbEntity.getName() != null && dbEntity.getName().equals(parentExternalName)) { singleTableInheritance = true; if (!singleTableInheritance || dbEntity.getAttribute(dbAttrName) == null) { while (dbEntity.getAttribute(dbAttrName) != null) { dbAttrName = dbAttributeBaseName + i++; .getSqlTypeByJava(javaType), dbEntity); dbAttr.setEoAttributeName(attrName); dbEntity.addAttribute(dbAttr);
/** * Sets the parent entity of this derived DbEntity. */ public void setParentEntity(DbEntity parentEntity) { setParentEntityName(parentEntity != null ? parentEntity.getName() : null); }
/** * Returns SQL string that can generate new (unique and non-repeating) * primary key for specified DbEntity. No actual database operations are * performed. * * @since 1.2 */ protected String newIDString(DbEntity ent) { if (ent.getPrimaryKeys() == null || ent.getPrimaryKeys().size() != 1) { throw new CayenneRuntimeException("Error generating pk for DbEntity %s" + ": pk must be single attribute", ent.getName()); } DbAttribute primaryKeyAttribute = ent.getPrimaryKeys().iterator().next(); return "NEWID FOR " + ent.getName() + ' ' + primaryKeyAttribute.getName(); }
@Override Collection<DbRelationship> getAll() { return container.getRelationships(); }
public void dbEntityRemoved(final DbEntity ent) { ent.getDataMap().removeDbEntity(ent.getName()); removedDbEntities.add(ent); }
public Collection<ObjEntity> mappedObjEntities() { Collection<ObjEntity> objEntities = new HashSet<ObjEntity>(); MappingNamespace mns = getDataMap().getNamespace(); if (mns != null) { for (ObjEntity objEntity : mns.getObjEntities()) { if (equals(objEntity.getDbEntity())) { objEntities.add(objEntity); } } } return objEntities; }
private void addToDbEntity(DbEntity entity, DbAttribute attribute) { attribute.setEntity(entity); // override existing attributes if it comes again if (entity.getAttribute(attribute.getName()) != null) { entity.removeAttribute(attribute.getName()); } entity.addAttribute(attribute); }
@Override void processResultSet(DbEntity dbEntity, DbLoadDataStore map, ResultSet rs) throws SQLException { String columnName = rs.getString("COLUMN_NAME"); DbAttribute attribute = dbEntity.getAttribute(columnName); if (attribute == null) { // why an attribute might be null is not quiet clear // but there is a bug report 731406 indicating that it is // possible so just print the warning, and ignore LOGGER.warn("Can't locate attribute for primary key: " + columnName); return; } attribute.setPrimaryKey(true); ((DetectedDbEntity) dbEntity).setPrimaryKeyName(rs.getString("PK_NAME")); } }
private void processStartDbEntity(Attributes atts) { String name = atts.getValue("", "name"); dbEntity = new DbEntity(name); dbEntity.setSchema(atts.getValue("", "schema")); dbEntity.setCatalog(atts.getValue("", "catalog")); dataMap.addDbEntity(dbEntity); }
@Override public void execute(MergerContext mergerContext) { for (ObjEntity objEntity : getEntity().mappedObjEntities()) { objEntity.getDataMap().removeObjEntity(objEntity.getName(), true); mergerContext.getDelegate().objEntityRemoved(objEntity); } getEntity().getDataMap().removeDbEntity(getEntity().getName(), true); mergerContext.getDelegate().dbEntityRemoved(getEntity()); } }
private Collection<DbRelationship> getIncomingRelationships(DbEntity entity) { Collection<DbRelationship> incoming = new ArrayList<>(); for (DbEntity nextEntity : entity.getDataMap().getDbEntities()) { for (DbRelationship relationship : nextEntity.getRelationships()) { // TODO: PERFORMANCE 'getTargetEntity' is generally slow, called // in this iterator it is showing (e.g. in YourKit profiles).. // perhaps use cheaper 'getTargetEntityName()' or even better - // pre-cache all relationships by target entity to avoid O(n) // search ? // (need to profile to prove the difference) if (entity == relationship.getTargetEntity()) { incoming.add(relationship); } } } return incoming; }
private void processIntermediatePathComponent() { DbRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship == null) { throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for entity '" + currentEntity.getName() + "'"); } this.currentEntity = (DbEntity) relationship.getTargetEntity(); }
private boolean needAutoPkSupport() { DbEntity entity = getEntity(); if(entity.getPrimaryKeyGenerator() != null) { return false; } for(DbAttribute attribute : entity.getPrimaryKeys()) { if(attribute.isGenerated()) { return false; } } return true; }