Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
#627: changed template to use spring-data repository instead of DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jul 31, 2018
1 parent f7df6fa commit 3dfdb64
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-spring-data-jpa</artifactId>
</dependency>

<!-- Envers for historization/journalling of entities -->
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa-envers</artifactId>
</dependency>

<!-- auto-configure datasource
https://stackoverflow.com/questions/34964066/spring-boot-doesnt-use-datasource-properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;

import io.oasp.module.jpa.dataaccess.api.AdvancedRevisionEntity;
import io.oasp.module.jpa.dataaccess.impl.data.GenericRepositoryFactoryBean;

/**
* Main entry point of this {@link SpringBootApplication}. Simply run this class to start this app.
*/
@SpringBootApplication
@EntityScan(basePackages = { "${package}" }, basePackageClasses = { AdvancedRevisionEntity.class })
@EnableJpaRepositories(repositoryFactoryBeanClass = GenericRepositoryFactoryBean.class)
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class SpringBootApp {

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ${package}.general.dataaccess.api.dao;

import io.oasp.module.jpa.dataaccess.api.data.DefaultRepository;
import ${package}.general.dataaccess.api.BinaryObjectEntity;

/**
* {@link DefaultRepository} for {@link BinaryObjectEntity}.
*/
public interface BinaryObjectRepository extends DefaultRepository<BinaryObjectEntity> {

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javax.inject.Named;

import ${package}.general.dataaccess.api.BinaryObjectEntity;
import ${package}.general.dataaccess.api.dao.BinaryObjectDao;
import ${package}.general.dataaccess.api.dao.BinaryObjectRepository;
import ${package}.general.logic.api.UcManageBinaryObject;
import ${package}.general.logic.api.to.BinaryObjectEto;
import ${package}.general.logic.base.AbstractUc;
Expand All @@ -17,51 +17,51 @@
@Named
public class UcManageBinaryObjectImpl extends AbstractUc implements UcManageBinaryObject {

private BinaryObjectDao binaryObjectDao;
private BinaryObjectRepository binaryObjectRepository;

/**
* @return binaryObjectDao
* @return {@link BinaryObjectRepository} instance.
*/
public BinaryObjectDao binaryObjectDao() {
public BinaryObjectRepository getBinaryObjectRepository() {

return this.binaryObjectDao;
return this.binaryObjectRepository;
}

/**
* @param binaryObjectDao the binaryObjectDao to set
* @param binaryObjectRepository the {@link BinaryObjectRepository} to set
*/
@Inject
public void setBinaryObjectDao(BinaryObjectDao binaryObjectDao) {
public void setBinaryObjectRepository(BinaryObjectRepository binaryObjectRepository) {

this.binaryObjectDao = binaryObjectDao;
this.binaryObjectRepository = binaryObjectRepository;
}

@Override
public BinaryObjectEto saveBinaryObject(Blob data, BinaryObjectEto binaryObjectEto) {

BinaryObjectEntity binaryObjectEntity = getBeanMapper().map(binaryObjectEto, BinaryObjectEntity.class);
binaryObjectEntity.setData(data);
this.binaryObjectDao.save(binaryObjectEntity);
this.binaryObjectRepository.save(binaryObjectEntity);
return getBeanMapper().map(binaryObjectEntity, BinaryObjectEto.class);
}

@Override
public void deleteBinaryObject(Long binaryObjectId) {

this.binaryObjectDao.delete(binaryObjectId);
this.binaryObjectRepository.delete(binaryObjectId);

}

@Override
public BinaryObjectEto findBinaryObject(Long binaryObjectId) {

return getBeanMapper().map(this.binaryObjectDao.findOne(binaryObjectId), BinaryObjectEto.class);
return getBeanMapper().map(this.binaryObjectRepository.findOne(binaryObjectId), BinaryObjectEto.class);
}

@Override
public Blob getBinaryObjectBlob(Long binaryObjectId) {

return this.binaryObjectDao.findOne(binaryObjectId).getData();
return this.binaryObjectRepository.findOne(binaryObjectId).getData();
}

}

0 comments on commit 3dfdb64

Please sign in to comment.