Critical Bug Fix for SQL inserts
This commit is contained in:
		
							parent
							
								
									acd4f06d9c
								
							
						
					
					
						commit
						a2cc974865
					
				@ -143,31 +143,32 @@ public abstract class AttributeKvInsertRepository {
 | 
			
		||||
                int[] result = jdbcTemplate.batchUpdate(BATCH_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                        ps.setString(1, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                        AttributeKvEntity kvEntity = entities.get(i);
 | 
			
		||||
                        ps.setString(1, replaceNullChars(kvEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(2, entities.get(i).getLongValue());
 | 
			
		||||
                        if (kvEntity.getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(2, kvEntity.getLongValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(2, Types.BIGINT);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(3, entities.get(i).getDoubleValue());
 | 
			
		||||
                        if (kvEntity.getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(3, kvEntity.getDoubleValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(3, Types.DOUBLE);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(4, entities.get(i).getBooleanValue());
 | 
			
		||||
                        if (kvEntity.getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(4, kvEntity.getBooleanValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(4, Types.BOOLEAN);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ps.setLong(5, entities.get(i).getLastUpdateTs());
 | 
			
		||||
                        ps.setString(6, entities.get(i).getId().getEntityType().name());
 | 
			
		||||
                        ps.setString(7, entities.get(i).getId().getEntityId());
 | 
			
		||||
                        ps.setString(8, entities.get(i).getId().getAttributeType());
 | 
			
		||||
                        ps.setString(9, entities.get(i).getId().getAttributeKey());
 | 
			
		||||
                        ps.setLong(5, kvEntity.getLastUpdateTs());
 | 
			
		||||
                        ps.setString(6, kvEntity.getId().getEntityType().name());
 | 
			
		||||
                        ps.setString(7, kvEntity.getId().getEntityId());
 | 
			
		||||
                        ps.setString(8, kvEntity.getId().getAttributeType());
 | 
			
		||||
                        ps.setString(9, kvEntity.getId().getAttributeKey());
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    @Override
 | 
			
		||||
@ -193,39 +194,40 @@ public abstract class AttributeKvInsertRepository {
 | 
			
		||||
                jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                        ps.setString(1, insertEntities.get(i).getId().getEntityType().name());
 | 
			
		||||
                        ps.setString(2, insertEntities.get(i).getId().getEntityId());
 | 
			
		||||
                        ps.setString(3, insertEntities.get(i).getId().getAttributeType());
 | 
			
		||||
                        ps.setString(4, insertEntities.get(i).getId().getAttributeKey());
 | 
			
		||||
                        ps.setString(5, replaceNullChars(insertEntities.get(i).getStrValue()));
 | 
			
		||||
                        ps.setString(10, replaceNullChars(insertEntities.get(i).getStrValue()));
 | 
			
		||||
                        AttributeKvEntity kvEntity = insertEntities.get(i);
 | 
			
		||||
                        ps.setString(1, kvEntity.getId().getEntityType().name());
 | 
			
		||||
                        ps.setString(2, kvEntity.getId().getEntityId());
 | 
			
		||||
                        ps.setString(3, kvEntity.getId().getAttributeType());
 | 
			
		||||
                        ps.setString(4, kvEntity.getId().getAttributeKey());
 | 
			
		||||
                        ps.setString(5, replaceNullChars(kvEntity.getStrValue()));
 | 
			
		||||
                        ps.setString(10, replaceNullChars(kvEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(6, insertEntities.get(i).getLongValue());
 | 
			
		||||
                            ps.setLong(11, insertEntities.get(i).getLongValue());
 | 
			
		||||
                        if (kvEntity.getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(6, kvEntity.getLongValue());
 | 
			
		||||
                            ps.setLong(11, kvEntity.getLongValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(6, Types.BIGINT);
 | 
			
		||||
                            ps.setNull(11, Types.BIGINT);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(7, insertEntities.get(i).getDoubleValue());
 | 
			
		||||
                            ps.setDouble(12, insertEntities.get(i).getDoubleValue());
 | 
			
		||||
                        if (kvEntity.getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(7, kvEntity.getDoubleValue());
 | 
			
		||||
                            ps.setDouble(12, kvEntity.getDoubleValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(7, Types.DOUBLE);
 | 
			
		||||
                            ps.setNull(12, Types.DOUBLE);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(8, insertEntities.get(i).getBooleanValue());
 | 
			
		||||
                            ps.setBoolean(13, insertEntities.get(i).getBooleanValue());
 | 
			
		||||
                        if (kvEntity.getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(8, kvEntity.getBooleanValue());
 | 
			
		||||
                            ps.setBoolean(13, kvEntity.getBooleanValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(8, Types.BOOLEAN);
 | 
			
		||||
                            ps.setNull(13, Types.BOOLEAN);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ps.setLong(9, insertEntities.get(i).getLastUpdateTs());
 | 
			
		||||
                        ps.setLong(14, insertEntities.get(i).getLastUpdateTs());
 | 
			
		||||
                        ps.setLong(9, kvEntity.getLastUpdateTs());
 | 
			
		||||
                        ps.setLong(14, kvEntity.getLastUpdateTs());
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    @Override
 | 
			
		||||
 | 
			
		||||
@ -57,34 +57,35 @@ public class TimescaleInsertRepository extends AbstractTimeseriesInsertRepositor
 | 
			
		||||
        jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                ps.setString(1, entities.get(i).getTenantId());
 | 
			
		||||
                ps.setString(2, entities.get(i).getEntityId());
 | 
			
		||||
                ps.setString(3, entities.get(i).getKey());
 | 
			
		||||
                ps.setLong(4, entities.get(i).getTs());
 | 
			
		||||
                TimescaleTsKvEntity tsKvEntity = entities.get(i);
 | 
			
		||||
                ps.setString(1, tsKvEntity.getTenantId());
 | 
			
		||||
                ps.setString(2, tsKvEntity.getEntityId());
 | 
			
		||||
                ps.setString(3, tsKvEntity.getKey());
 | 
			
		||||
                ps.setLong(4, tsKvEntity.getTs());
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                    ps.setBoolean(5, entities.get(i).getBooleanValue());
 | 
			
		||||
                    ps.setBoolean(9, entities.get(i).getBooleanValue());
 | 
			
		||||
                if (tsKvEntity.getBooleanValue() != null) {
 | 
			
		||||
                    ps.setBoolean(5, tsKvEntity.getBooleanValue());
 | 
			
		||||
                    ps.setBoolean(9, tsKvEntity.getBooleanValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(5, Types.BOOLEAN);
 | 
			
		||||
                    ps.setNull(9, Types.BOOLEAN);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ps.setString(6, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                ps.setString(10, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                ps.setString(6, replaceNullChars(tsKvEntity.getStrValue()));
 | 
			
		||||
                ps.setString(10, replaceNullChars(tsKvEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getLongValue() != null) {
 | 
			
		||||
                    ps.setLong(7, entities.get(i).getLongValue());
 | 
			
		||||
                    ps.setLong(11, entities.get(i).getLongValue());
 | 
			
		||||
                if (tsKvEntity.getLongValue() != null) {
 | 
			
		||||
                    ps.setLong(7, tsKvEntity.getLongValue());
 | 
			
		||||
                    ps.setLong(11, tsKvEntity.getLongValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(7, Types.BIGINT);
 | 
			
		||||
                    ps.setNull(11, Types.BIGINT);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                    ps.setDouble(8, entities.get(i).getDoubleValue());
 | 
			
		||||
                    ps.setDouble(12, entities.get(i).getDoubleValue());
 | 
			
		||||
                if (tsKvEntity.getDoubleValue() != null) {
 | 
			
		||||
                    ps.setDouble(8, tsKvEntity.getDoubleValue());
 | 
			
		||||
                    ps.setDouble(12, tsKvEntity.getDoubleValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(8, Types.DOUBLE);
 | 
			
		||||
                    ps.setNull(12, Types.DOUBLE);
 | 
			
		||||
 | 
			
		||||
@ -65,31 +65,32 @@ public class PsqlLatestInsertRepository extends AbstractLatestInsertRepository {
 | 
			
		||||
                int[] result = jdbcTemplate.batchUpdate(BATCH_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                        ps.setLong(1, entities.get(i).getTs());
 | 
			
		||||
                        TsKvLatestEntity tsKvLatestEntity = entities.get(i);
 | 
			
		||||
                        ps.setLong(1, tsKvLatestEntity.getTs());
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(2, entities.get(i).getBooleanValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(2, tsKvLatestEntity.getBooleanValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(2, Types.BOOLEAN);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ps.setString(3, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                        ps.setString(3, replaceNullChars(tsKvLatestEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(4, entities.get(i).getLongValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(4, tsKvLatestEntity.getLongValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(4, Types.BIGINT);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (entities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(5, entities.get(i).getDoubleValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(5, tsKvLatestEntity.getDoubleValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(5, Types.DOUBLE);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ps.setString(6, entities.get(i).getEntityType().name());
 | 
			
		||||
                        ps.setString(7, entities.get(i).getEntityId());
 | 
			
		||||
                        ps.setString(8, entities.get(i).getKey());
 | 
			
		||||
                        ps.setString(6, tsKvLatestEntity.getEntityType().name());
 | 
			
		||||
                        ps.setString(7, tsKvLatestEntity.getEntityId());
 | 
			
		||||
                        ps.setString(8, tsKvLatestEntity.getKey());
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    @Override
 | 
			
		||||
@ -115,35 +116,36 @@ public class PsqlLatestInsertRepository extends AbstractLatestInsertRepository {
 | 
			
		||||
                jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                        ps.setString(1, insertEntities.get(i).getEntityType().name());
 | 
			
		||||
                        ps.setString(2, insertEntities.get(i).getEntityId());
 | 
			
		||||
                        ps.setString(3, insertEntities.get(i).getKey());
 | 
			
		||||
                        ps.setLong(4, insertEntities.get(i).getTs());
 | 
			
		||||
                        ps.setLong(9, insertEntities.get(i).getTs());
 | 
			
		||||
                        TsKvLatestEntity tsKvLatestEntity = insertEntities.get(i);
 | 
			
		||||
                        ps.setString(1, tsKvLatestEntity.getEntityType().name());
 | 
			
		||||
                        ps.setString(2, tsKvLatestEntity.getEntityId());
 | 
			
		||||
                        ps.setString(3, tsKvLatestEntity.getKey());
 | 
			
		||||
                        ps.setLong(4, tsKvLatestEntity.getTs());
 | 
			
		||||
                        ps.setLong(9, tsKvLatestEntity.getTs());
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(5, insertEntities.get(i).getBooleanValue());
 | 
			
		||||
                            ps.setBoolean(10, insertEntities.get(i).getBooleanValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getBooleanValue() != null) {
 | 
			
		||||
                            ps.setBoolean(5, tsKvLatestEntity.getBooleanValue());
 | 
			
		||||
                            ps.setBoolean(10, tsKvLatestEntity.getBooleanValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(5, Types.BOOLEAN);
 | 
			
		||||
                            ps.setNull(10, Types.BOOLEAN);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        ps.setString(6, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                        ps.setString(11, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                        ps.setString(6, replaceNullChars(tsKvLatestEntity.getStrValue()));
 | 
			
		||||
                        ps.setString(11, replaceNullChars(tsKvLatestEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(7, insertEntities.get(i).getLongValue());
 | 
			
		||||
                            ps.setLong(12, insertEntities.get(i).getLongValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getLongValue() != null) {
 | 
			
		||||
                            ps.setLong(7, tsKvLatestEntity.getLongValue());
 | 
			
		||||
                            ps.setLong(12, tsKvLatestEntity.getLongValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(7, Types.BIGINT);
 | 
			
		||||
                            ps.setNull(12, Types.BIGINT);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (insertEntities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(8, insertEntities.get(i).getDoubleValue());
 | 
			
		||||
                            ps.setDouble(13, insertEntities.get(i).getDoubleValue());
 | 
			
		||||
                        if (tsKvLatestEntity.getDoubleValue() != null) {
 | 
			
		||||
                            ps.setDouble(8, tsKvLatestEntity.getDoubleValue());
 | 
			
		||||
                            ps.setDouble(13, tsKvLatestEntity.getDoubleValue());
 | 
			
		||||
                        } else {
 | 
			
		||||
                            ps.setNull(8, Types.DOUBLE);
 | 
			
		||||
                            ps.setNull(13, Types.DOUBLE);
 | 
			
		||||
 | 
			
		||||
@ -99,34 +99,35 @@ public class PsqlTimeseriesInsertRepository extends AbstractTimeseriesInsertRepo
 | 
			
		||||
        jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
			
		||||
                ps.setString(1, entities.get(i).getEntityType().name());
 | 
			
		||||
                ps.setString(2, entities.get(i).getEntityId());
 | 
			
		||||
                ps.setString(3, entities.get(i).getKey());
 | 
			
		||||
                ps.setLong(4, entities.get(i).getTs());
 | 
			
		||||
                TsKvEntity tsKvEntity = entities.get(i);
 | 
			
		||||
                ps.setString(1, tsKvEntity.getEntityType().name());
 | 
			
		||||
                ps.setString(2, tsKvEntity.getEntityId());
 | 
			
		||||
                ps.setString(3, tsKvEntity.getKey());
 | 
			
		||||
                ps.setLong(4, tsKvEntity.getTs());
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getBooleanValue() != null) {
 | 
			
		||||
                    ps.setBoolean(5, entities.get(i).getBooleanValue());
 | 
			
		||||
                    ps.setBoolean(9, entities.get(i).getBooleanValue());
 | 
			
		||||
                if (tsKvEntity.getBooleanValue() != null) {
 | 
			
		||||
                    ps.setBoolean(5, tsKvEntity.getBooleanValue());
 | 
			
		||||
                    ps.setBoolean(9, tsKvEntity.getBooleanValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(5, Types.BOOLEAN);
 | 
			
		||||
                    ps.setNull(9, Types.BOOLEAN);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ps.setString(6, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                ps.setString(10, replaceNullChars(entities.get(i).getStrValue()));
 | 
			
		||||
                ps.setString(6, replaceNullChars(tsKvEntity.getStrValue()));
 | 
			
		||||
                ps.setString(10, replaceNullChars(tsKvEntity.getStrValue()));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getLongValue() != null) {
 | 
			
		||||
                    ps.setLong(7, entities.get(i).getLongValue());
 | 
			
		||||
                    ps.setLong(11, entities.get(i).getLongValue());
 | 
			
		||||
                if (tsKvEntity.getLongValue() != null) {
 | 
			
		||||
                    ps.setLong(7, tsKvEntity.getLongValue());
 | 
			
		||||
                    ps.setLong(11, tsKvEntity.getLongValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(7, Types.BIGINT);
 | 
			
		||||
                    ps.setNull(11, Types.BIGINT);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (entities.get(i).getDoubleValue() != null) {
 | 
			
		||||
                    ps.setDouble(8, entities.get(i).getDoubleValue());
 | 
			
		||||
                    ps.setDouble(12, entities.get(i).getDoubleValue());
 | 
			
		||||
                if (tsKvEntity.getDoubleValue() != null) {
 | 
			
		||||
                    ps.setDouble(8, tsKvEntity.getDoubleValue());
 | 
			
		||||
                    ps.setDouble(12, tsKvEntity.getDoubleValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                    ps.setNull(8, Types.DOUBLE);
 | 
			
		||||
                    ps.setNull(12, Types.DOUBLE);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user