Skip to content

Commit

Permalink
added changes to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Sep 19, 2024
1 parent 89157e2 commit d4a0f3c
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 261 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencyManagement {
}
}
group = 'com.nucleodb'
version = '3.5.8'
version = '3.6.0'

repositories {
mavenCentral()
Expand All @@ -23,7 +23,7 @@ repositories {
}

dependencies {
api 'com.nucleodb:library:1.18.4'
api 'com.nucleodb:library:1.18.9'
api 'org.springframework:spring-beans'
api 'org.springframework:spring-context'
api 'org.springframework:spring-expression'
Expand Down
413 changes: 194 additions & 219 deletions src/main/java/com/nucleodb/spring/NDBRepositoryFactoryBean.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Import({NDBRepositoryRegistrar.class})
@Import({NDBRepositoryRegistrar.class, NDBInstance.class})
public @interface EnableNDBRepositories{
NucleoDB.DBType dbType() default NucleoDB.DBType.NO_LOCAL;

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/nucleodb/spring/config/NDBInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nucleodb.spring.config;

import com.nucleodb.library.NucleoDB;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class NDBInstance {
@Bean
public NucleoDB createNucleoDB(){
return new NucleoDB();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConf
@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
builder.addAutowiredProperty("publisher");
builder.addAutowiredProperty("nucleoDB");
builder.addDependsOn("ndbMappingContext");

Optional<String> mqsConfig = config.getAttribute("mqsConfiguration");
if(mqsConfig.isPresent()){
builder.addPropertyValue("mqsConfiguration", mqsConfig.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public Set<C> getByFromAndTo(F fromEntity, T toEntity, Pagination pagination, Pr
}

@Override
public <S extends C> S save(S entity) {
AtomicReference<S> returnedVal = new AtomicReference<>();
public C save(C entity) {
AtomicReference<C> returnedVal = new AtomicReference<>();
try {
connectionHandler.saveAsync(entity, (connection)->{
returnedVal.set((S)connection);
returnedVal.set((C)connection);
synchronized (returnedVal) {
returnedVal.notify();
}
Expand All @@ -177,13 +177,13 @@ public <S extends C> S save(S entity) {
}

@Override
public <S extends C> Set<S> saveAll(Iterable<S> entities) {
AtomicReference<Set<S>> returnedVal = new AtomicReference<>(new TreeSetExt<>());
public Set<C> saveAll(Iterable<C> entities) {
AtomicReference<Set<C>> returnedVal = new AtomicReference<>(new TreeSetExt<>());
CountDownLatch countDownLatch = new CountDownLatch(Long.valueOf(StreamSupport.stream(entities.spliterator(), false).count()).intValue());
StreamSupport.stream(entities.spliterator(), true).forEach(entity-> {
try {
connectionHandler.saveAsync(entity, (connection) -> {
returnedVal.getAcquire().add((S) connection);
returnedVal.getAcquire().add((C) connection);
countDownLatch.countDown();
});
} catch (InvalidConnectionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,39 @@ public NDBDataEntryRepositoryImpl(NucleoDB nucleoDB, Class<T> classType, Applica
}

@Override
public <S extends T> S save(S entity) {
AtomicReference<S> returnedVal = new AtomicReference<>();
public T save(T entity) {
AtomicReference<T> returnedVal = new AtomicReference<>();
try {
if(table.getEntries().contains(entity)) {
table.saveAsync(entity.copy(classType,true), (de) -> {
returnedVal.set((S) de);
synchronized (returnedVal) {
returnedVal.notify();
}
});
}else {
table.saveAsync(entity, (de) -> {
returnedVal.set((S) de);
synchronized (returnedVal) {
returnedVal.notify();
}
});
}
table.saveAsync(entity, (de) -> {
returnedVal.set((T) de);
synchronized (returnedVal) {
returnedVal.notify();
}
});
synchronized (returnedVal) {
returnedVal.wait();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IncorrectDataEntryObjectException e) {
throw new RuntimeException(e);
} catch (ObjectNotSavedException e) {
throw new RuntimeException(e);
}
return returnedVal.get();
}

public void saveForget(T entity) {
try {
table.saveAndForget(entity);
} catch (IncorrectDataEntryObjectException e) {
throw new RuntimeException(e);
}
}

@Override
public <S extends T> List<S> saveAll(Iterable<S> entities) {
List<S> items = new LinkedList<>();
public List<T> saveAll(Iterable<T> entities) {
List<T> items = new LinkedList<>();
entities.forEach(entity -> {
S savedEntity = save(entity);
T savedEntity = save(entity);
if (savedEntity == null) return;
items.add(savedEntity);
});
Expand Down Expand Up @@ -136,15 +133,9 @@ public void deleteById(ID id) {
@Override
public void delete(T entity) {
try {
if(table.getEntries().contains(entity)) {
table.deleteSync(entity.copy(classType, true));
}else{
table.deleteSync(entity);
}
table.deleteSync(entity);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ObjectNotSavedException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public interface NDBConnRepository<C extends Connection<F, T>, ID extends String, F extends DataEntry, T extends DataEntry> extends Repository<C, ID> {

<S extends C> S save(S entity);
<S extends C> Iterable<S> saveAll(Iterable<S> entities);
C save(C entity);
Iterable<C> saveAll(Iterable<C> entities);

Set<C> getByTo(T entity);
Set<C> getByTo(T entity, ConnectionProjection projection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@NoRepositoryBean
public interface NDBDataRepository<T, ID> extends Repository<T, ID> {

<S extends T> List<S> saveAll(Iterable<S> entities);
List<T> saveAll(Iterable<T> entities);

/*
* (non-Javadoc)
Expand All @@ -29,6 +29,7 @@ public interface NDBDataRepository<T, ID> extends Repository<T, ID> {

List<T> findAllById(Iterable<ID> iterable);

void saveForget(T entity);
/*
* (non-Javadoc)
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
Expand All @@ -50,7 +51,7 @@ public interface NDBDataRepository<T, ID> extends Repository<T, ID> {
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
* present but does not exist in the database.
*/
<S extends T> S save(S entity);
T save(T entity);


/**
Expand Down

0 comments on commit d4a0f3c

Please sign in to comment.