persistence work (unstable)
This commit is contained in:
parent
1a8b39bde6
commit
011d6a1f78
|
@ -33,9 +33,9 @@ public abstract class AbstractHibernateDao<T extends Serializable> implements IO
|
|||
}
|
||||
|
||||
@Override
|
||||
public final long create(final T entity) {
|
||||
public final void create(final T entity) {
|
||||
Preconditions.checkNotNull(entity);
|
||||
return (Long) getCurrentSession().save(entity);
|
||||
getCurrentSession().save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,7 @@ public interface IOperations<T extends Serializable> {
|
|||
|
||||
List<T> findAll();
|
||||
|
||||
long create(final T entity);
|
||||
void create(final T entity);
|
||||
|
||||
T update(final T entity);
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.baeldung.spring.persistence.service.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.persistence.dao.common.IOperations;
|
||||
|
||||
public abstract class AbstractService<T extends Serializable> implements IOperations<T> {
|
||||
|
||||
@Override
|
||||
public T findOne(final long id) {
|
||||
return getDao().findOne(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return getDao().findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(final T entity) {
|
||||
getDao().create(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T update(final T entity) {
|
||||
return getDao().update(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(final T entity) {
|
||||
getDao().delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(final long entityId) {
|
||||
getDao().deleteById(entityId);
|
||||
}
|
||||
|
||||
protected abstract IOperations<T> getDao();
|
||||
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
package org.baeldung.spring.persistence.service;
|
||||
package org.baeldung.spring.persistence.service.impl;
|
||||
|
||||
import org.baeldung.spring.persistence.dao.IFooDao;
|
||||
import org.baeldung.spring.persistence.dao.common.IOperations;
|
||||
import org.baeldung.spring.persistence.model.Foo;
|
||||
import org.baeldung.spring.persistence.service.common.AbstractService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class FooService {
|
||||
public class FooService extends AbstractService<Foo> {
|
||||
|
||||
@Autowired
|
||||
private IFooDao dao;
|
||||
|
@ -19,8 +21,9 @@ public class FooService {
|
|||
|
||||
// API
|
||||
|
||||
public void create(final Foo entity) {
|
||||
dao.create(entity);
|
||||
@Override
|
||||
protected IOperations<Foo> getDao() {
|
||||
return dao;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
|||
|
||||
import org.baeldung.spring.persistence.config.PersistenceConfig;
|
||||
import org.baeldung.spring.persistence.model.Foo;
|
||||
import org.baeldung.spring.persistence.service.impl.FooService;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
Loading…
Reference in New Issue