@Test void testMrefValueTooLong() { Attribute attr = mock(Attribute.class); when(attr.getName()).thenReturn("mref_attr"); Attribute idAttr = mock(Attribute.class); when(idAttr.getName()).thenReturn("id"); when(entityType.getIdAttribute()).thenReturn(idAttr); when(entityType.getId()).thenReturn("test_entity"); MolgenisValidationException mve = new MolgenisValidationException(new ConstraintViolation(VALUE_TOO_LONG_MSG)); when(jdbcTemplate.batchUpdate(any(), any(BatchPreparedStatementSetter.class))).thenThrow(mve); HashMap<String, Object> value = newHashMap(); value.put("mref_attr", "TOOLONG"); Exception exception = assertThrows( MolgenisValidationException.class, () -> postgreSqlRepo.addMrefs(newArrayList(value), attr)); assertThat(exception.getMessage()) .containsPattern( "One of the mref values in entity type \\[test_entity\\] attribute \\[mref_attr\\] is too long."); }
void addMrefs(final List<Map<String, Object>> mrefs, final Attribute attr) { if (!attr.isNillable() && mrefs.isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Entity [%s] attribute [%s] value cannot be null", entityType.getId(), attr.getName()))); } final Attribute idAttr = entityType.getIdAttribute(); String insertMrefSql = getSqlInsertJunction(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Adding junction table entries for entity [{}] attribute [{}]", getName(), attr.getName()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", insertMrefSql); } } try { jdbcTemplate.batchUpdate( insertMrefSql, new BatchJunctionTableAddPreparedStatementSetter(mrefs, attr, idAttr)); } catch (MolgenisValidationException mve) { if (mve.getMessage().equals(VALUE_TOO_LONG_MSG)) { mve = new MolgenisValidationException( new ConstraintViolation( format( "One of the mref values in entity type [%s] attribute [%s] is too long.", getEntityType().getId(), attr.getName()))); } throw mve; } }
PostgreSqlRepository extends AbstractRepository { void addMrefs(final List<Map<String, Object>> mrefs, final Attribute attr) { if (!attr.isNillable() && mrefs.isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Entity [%s] attribute [%s] value cannot be null", entityType.getId(), attr.getName()))); } final Attribute idAttr = entityType.getIdAttribute(); String insertMrefSql = getSqlInsertJunction(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Adding junction table entries for entity [{}] attribute [{}]", getName(), attr.getName()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", insertMrefSql); } } try { jdbcTemplate.batchUpdate( insertMrefSql, new BatchJunctionTableAddPreparedStatementSetter(mrefs, attr, idAttr)); } catch (MolgenisValidationException mve) { if (mve.getMessage().equals(VALUE_TOO_LONG_MSG)) { mve = new MolgenisValidationException( new ConstraintViolation( format( "One of the mref values in entity type [%s] attribute [%s] is too long.", getEntityType().getId(), attr.getName()))); } throw mve; } } }
PostgreSqlRepository extends AbstractRepository { void addMrefs(final List<Map<String, Object>> mrefs, final Attribute attr) { if (!attr.isNillable() && mrefs.isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Entity [%s] attribute [%s] value cannot be null", entityType.getId(), attr.getName()))); } final Attribute idAttr = entityType.getIdAttribute(); String insertMrefSql = getSqlInsertJunction(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Adding junction table entries for entity [{}] attribute [{}]", getName(), attr.getName()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", insertMrefSql); } } try { jdbcTemplate.batchUpdate( insertMrefSql, new BatchJunctionTableAddPreparedStatementSetter(mrefs, attr, idAttr)); } catch (MolgenisValidationException mve) { if (mve.getMessage().equals(VALUE_TOO_LONG_MSG)) { mve = new MolgenisValidationException( new ConstraintViolation( format( "One of the mref values in entity type [%s] attribute [%s] is too long.", getEntityType().getId(), attr.getName()))); } throw mve; } } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); }
PostgreSqlRepository extends AbstractRepository { void addMrefs(final List<Map<String, Object>> mrefs, final Attribute attr) { if (!attr.isNillable() && mrefs.isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Entity [%s] attribute [%s] value cannot be null", entityType.getId(), attr.getName()))); } final Attribute idAttr = entityType.getIdAttribute(); String insertMrefSql = getSqlInsertJunction(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Adding junction table entries for entity [{}] attribute [{}]", getName(), attr.getName()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", insertMrefSql); } } try { jdbcTemplate.batchUpdate( insertMrefSql, new BatchJunctionTableAddPreparedStatementSetter(mrefs, attr, idAttr)); } catch (MolgenisValidationException mve) { if (mve.getMessage().equals(VALUE_TOO_LONG_MSG)) { mve = new MolgenisValidationException( new ConstraintViolation( format( "One of the mref values in entity type [%s] attribute [%s] is too long.", getEntityType().getId(), attr.getName()))); } throw mve; } } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); @Override Iterator<Entity> iterator(); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override EntityType getEntityType(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); }
PostgreSqlRepository extends AbstractRepository { void addMrefs(final List<Map<String, Object>> mrefs, final Attribute attr) { if (!attr.isNillable() && mrefs.isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Entity [%s] attribute [%s] value cannot be null", entityType.getId(), attr.getName()))); } final Attribute idAttr = entityType.getIdAttribute(); String insertMrefSql = getSqlInsertJunction(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Adding junction table entries for entity [{}] attribute [{}]", getName(), attr.getName()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", insertMrefSql); } } try { jdbcTemplate.batchUpdate( insertMrefSql, new BatchJunctionTableAddPreparedStatementSetter(mrefs, attr, idAttr)); } catch (MolgenisValidationException mve) { if (mve.getMessage().equals(VALUE_TOO_LONG_MSG)) { mve = new MolgenisValidationException( new ConstraintViolation( format( "One of the mref values in entity type [%s] attribute [%s] is too long.", getEntityType().getId(), attr.getName()))); } throw mve; } } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); @Override Iterator<Entity> iterator(); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override EntityType getEntityType(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize);  }