@Test void updateAttribute() { EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock(); String attrName = "attr"; Attribute attr = when(mock(Attribute.class).getName()).thenReturn(attrName).getMock(); when(entityType.getAttribute(attrName)).thenReturn(attr); when(attr.getLabel()).thenReturn("label"); Attribute updatedAttr = when(mock(Attribute.class).getName()).thenReturn(attrName).getMock(); when(updatedAttr.getLabel()).thenReturn("updated label"); postgreSqlRepoCollection.updateAttribute(entityType, attr, updatedAttr); verifyZeroInteractions(jdbcTemplate); }
@Override public void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot update attribute [%s] for abstract entity type [%s].", attr.getName(), entityType.getId())); } if (!isPersisted(attr) && !isPersisted(updatedAttr)) { return; } if (isPersisted(attr) && !isPersisted(updatedAttr)) { deleteAttribute(entityType, attr); } else if (!isPersisted(attr) && isPersisted(updatedAttr)) { addAttributeInternal(entityType, updatedAttr); } else { updateColumn(entityType, attr, updatedAttr); } }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot update attribute [%s] for abstract entity type [%s].", attr.getName(), entityType.getId())); } if (!isPersisted(attr) && !isPersisted(updatedAttr)) { return; } if (isPersisted(attr) && !isPersisted(updatedAttr)) { deleteAttribute(entityType, attr); } else if (!isPersisted(attr) && isPersisted(updatedAttr)) { addAttributeInternal(entityType, updatedAttr); } else { updateColumn(entityType, attr, updatedAttr); } } }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot update attribute [%s] for abstract entity type [%s].", attr.getName(), entityType.getId())); } if (!isPersisted(attr) && !isPersisted(updatedAttr)) { return; } if (isPersisted(attr) && !isPersisted(updatedAttr)) { deleteAttribute(entityType, attr); } else if (!isPersisted(attr) && isPersisted(updatedAttr)) { addAttributeInternal(entityType, updatedAttr); } else { updateColumn(entityType, attr, updatedAttr); } } PostgreSqlRepositoryCollection(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      DataSource dataSource,
      JdbcTemplate jdbcTemplate,
      DataService dataService); }
PostgreSqlRepositoryCollection extends AbstractRepositoryCollection { @Override public void updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot update attribute [%s] for abstract entity type [%s].", attr.getName(), entityType.getId())); } if (!isPersisted(attr) && !isPersisted(updatedAttr)) { return; } if (isPersisted(attr) && !isPersisted(updatedAttr)) { deleteAttribute(entityType, attr); } else if (!isPersisted(attr) && isPersisted(updatedAttr)) { addAttributeInternal(entityType, updatedAttr); } else { updateColumn(entityType, attr, updatedAttr); } } 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 updateAttribute(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (entityType.isAbstract()) { throw new MolgenisDataException( format( "Cannot update attribute [%s] for abstract entity type [%s].", attr.getName(), entityType.getId())); } if (!isPersisted(attr) && !isPersisted(updatedAttr)) { return; } if (isPersisted(attr) && !isPersisted(updatedAttr)) { deleteAttribute(entityType, attr); } else if (!isPersisted(attr) && isPersisted(updatedAttr)) { addAttributeInternal(entityType, updatedAttr); } else { updateColumn(entityType, attr, updatedAttr); } } 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; }