Created
March 13, 2018 15:29
-
-
Save pablocloud/e8692c9f90cd86a3b772e17fbebb6684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.besuricata.rest.services; | |
import org.springframework.dao.EmptyResultDataAccessException; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import java.util.Collection; | |
public abstract class BasicServiceAbstract<T, ID> implements BasicService<T, ID> { | |
protected JpaRepository<T, ID> repository; | |
@Override | |
public T getById(ID identifier) { | |
return repository.getOne(identifier); | |
} | |
@Override | |
public Collection<T> findAll() { | |
return repository.findAll(); | |
} | |
@Override | |
public T saveNew(T object) { | |
return repository.save(object); | |
} | |
@Override | |
public T update(T object) { | |
return repository.save(object); | |
} | |
@Override | |
public Boolean delete(ID identifier) { | |
try { | |
repository.deleteById(identifier); | |
return true; | |
} catch (EmptyResultDataAccessException exception) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment