INNER CODE UNIT · Java

disassociatedDogFromVeterinary

righettod/poc-graphql · src/main/java/eu/righettod/graphqlpoc/repository/BusinessDataRepository.java:230

    public Dog disassociatedDogFromVeterinary(int veterinaryId, int dogId) throws Exception {
        Dog d = null;
        //Verify is the specified DogResolver is already associated to the specified veterinary
        String sql = "SELECT COUNT(ID) FROM DOG WHERE VETERINARY_ID = ? and ID = ?";
        boolean isAssociated;
        try (PreparedStatement stmt = this.storageConnection.prepareStatement(sql)) {
            stmt.setInt(1, veterinaryId);
            stmt.setInt(2, dogId);
            try (ResultSet rst = stmt.executeQuery()) {
                isAssociated = rst.getInt(1) > 0;
            }
        }
        //Disassociated it if it's associated
        if (!isAssociated) {
            sql = "UPDATE DOG SET VETERINARY_ID = NULL WHERE VETERINARY_ID = ? AND ID = ?";
            try (PreparedStatement stmt = this.storageConnection.prepareStatement(sql)) {
                stmt.setInt(1, veterinaryId);
                stmt.setInt(2, dogId);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…