Skip to content

Commit

Permalink
add read only
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Dec 4, 2023
1 parent ea34335 commit 8089a99
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.nucleodb'
version = '1.12.2'
version = '1.12.3'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class DataEntryProjection{

Predicate<DataEntry> filter = null;

boolean writable = true;

public DataEntryProjection(Pagination pagination, Predicate<DataEntry> filter) {
this.pagination = pagination;
this.filter = filter;
Expand Down Expand Up @@ -41,4 +43,20 @@ public void setPagination(Pagination pagination) {
public void setFilter(Predicate<DataEntry> filter) {
this.filter = filter;
}

public Pagination getPagination() {
return pagination;
}

public Predicate<DataEntry> getFilter() {
return filter;
}

public boolean isWritable() {
return writable;
}

public void setWritable(boolean writable) {
this.writable = writable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.function.Consumer;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class DataTable implements Serializable{
private static final long serialVersionUID = 1;
Expand Down Expand Up @@ -325,7 +326,12 @@ public Set<DataEntry> search(String key, Object searchObject, DataEntryProjectio
dataEntryProjection = new DataEntryProjection();
}
try {
return dataEntryProjection.process(this.indexes.get(key).search(searchObject).stream()).map(de->(DataEntry)de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
Stream<DataEntry> process = dataEntryProjection.process(this.indexes.get(key).search(searchObject).stream());
if(dataEntryProjection.isWritable()) {
return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
}else{
return process.collect(Collectors.toSet());
}
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -351,7 +357,12 @@ public Set<DataEntry> get(String key, Object value, DataEntryProjection dataEntr
} catch (Exception e) {
e.printStackTrace();
}
return dataEntryProjection.process(entries.stream()).map(de->(DataEntry)de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
Stream<DataEntry> process = dataEntryProjection.process(entries.stream());
if(dataEntryProjection.isWritable()) {
return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
}else{
return process.collect(Collectors.toSet());
}
}

public Set<DataEntry> getNotEqual(String key, Object value, DataEntryProjection dataEntryProjection) {
Expand All @@ -368,7 +379,12 @@ public Set<DataEntry> getNotEqual(String key, Object value, DataEntryProjection
Set<DataEntry> negation = new TreeSet<>(entries);
negation.removeAll(foundEntries);
if (entries != null) {
return dataEntryProjection.process(negation.stream()).map(c->(DataEntry)c.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
Stream<DataEntry> process = dataEntryProjection.process(negation.stream());
if(dataEntryProjection.isWritable()) {
return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
}else{
return process.collect(Collectors.toSet());
}
}
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 8089a99

Please sign in to comment.