@Test void deleteAttribute() { String attrName = "attr"; Attribute attr = when(mock(Attribute.class).getName()).thenReturn(attrName).getMock(); when(attr.getIdentifier()).thenReturn("attrId"); when(attr.getDataType()).thenReturn(STRING); EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock(); when(entityType.getAttribute(attrName)).thenReturn(attr); postgreSqlRepoCollection.deleteAttribute(entityType, attr); verify(jdbcTemplate).execute("ALTER TABLE \"entity#6844280e\" DROP COLUMN \"attr\""); }
@Override public void deleteAttribute(EntityType entityType, Attribute attr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot delete attribute [%s] from abstract entity type [%s].", attr.getName(), entityType.getId())); } if (entityType.getAttribute(attr.getName()) == null) { throw new UnknownAttributeException(entityType, attr.getName()); } if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { dropJunctionTable(entityType, attr); } else { dropColumn(entityType, attr); } }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void deleteAttribute(EntityType entityType, Attribute attr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot delete attribute [%s] from abstract entity type [%s].", attr.getName(), entityType.getId())); } if (entityType.getAttribute(attr.getName()) == null) { throw new UnknownAttributeException(entityType, attr.getName()); } if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { dropJunctionTable(entityType, attr); } else { dropColumn(entityType, attr); } } }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void deleteAttribute(EntityType entityType, Attribute attr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot delete attribute [%s] from abstract entity type [%s].", attr.getName(), entityType.getId())); } if (entityType.getAttribute(attr.getName()) == null) { throw new UnknownAttributeException(entityType, attr.getName()); } if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { dropJunctionTable(entityType, attr); } else { dropColumn(entityType, attr); } } PostgreSqlRepositoryCollection(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      DataSource dataSource,
      JdbcTemplate jdbcTemplate,
      DataService dataService); }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void deleteAttribute(EntityType entityType, Attribute attr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot delete attribute [%s] from abstract entity type [%s].", attr.getName(), entityType.getId())); } if (entityType.getAttribute(attr.getName()) == null) { throw new UnknownAttributeException(entityType, attr.getName()); } if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { dropJunctionTable(entityType, attr); } else { dropColumn(entityType, attr); } } PostgreSqlRepositoryCollection(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      DataSource dataSource,
      JdbcTemplate jdbcTemplate,
      DataService dataService); @Override String getName(); @Override Set<RepositoryCollectionCapability> getCapabilities(); @Override boolean hasRepository(String name); @Override Repository<Entity> createRepository(EntityType entityType); @Override boolean hasRepository(EntityType entityType); @Override Iterable<String> getEntityTypeIds(); @Override Repository<Entity> getRepository(String id); @Override Repository<Entity> getRepository(EntityType entityType); @Override Iterator<Repository<Entity>> iterator(); @Override void deleteRepository(EntityType entityType); @Override void updateRepository(EntityType entityType, EntityType updatedEntityType); @Override void addAttribute(EntityType entityType, Attribute attr); @Override void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr); @Override void deleteAttribute(EntityType entityType, Attribute attr); }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void deleteAttribute(EntityType entityType, Attribute attr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot delete attribute [%s] from abstract entity type [%s].", attr.getName(), entityType.getId())); } if (entityType.getAttribute(attr.getName()) == null) { throw new UnknownAttributeException(entityType, attr.getName()); } if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { dropJunctionTable(entityType, attr); } else { dropColumn(entityType, attr); } } PostgreSqlRepositoryCollection(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      DataSource dataSource,
      JdbcTemplate jdbcTemplate,
      DataService dataService); @Override String getName(); @Override Set<RepositoryCollectionCapability> getCapabilities(); @Override boolean hasRepository(String name); @Override Repository<Entity> createRepository(EntityType entityType); @Override boolean hasRepository(EntityType entityType); @Override Iterable<String> getEntityTypeIds(); @Override Repository<Entity> getRepository(String id); @Override Repository<Entity> getRepository(EntityType entityType); @Override Iterator<Repository<Entity>> iterator(); @Override void deleteRepository(EntityType entityType); @Override void updateRepository(EntityType entityType, EntityType updatedEntityType); @Override void addAttribute(EntityType entityType, Attribute attr); @Override void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr); @Override void deleteAttribute(EntityType entityType, Attribute attr); static final String POSTGRESQL; }