From 8089a994849e1d2fa1dc96047322f41f06e51c45 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Mon, 4 Dec 2023 03:27:33 -0700 Subject: [PATCH] add read only --- build.gradle | 2 +- .../tables/table/DataEntryProjection.java | 18 +++++++++++++++ .../database/tables/table/DataTable.java | 22 ++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index dafef8f..5df0cb4 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'com.nucleodb' -version = '1.12.2' +version = '1.12.3' repositories { mavenCentral() diff --git a/src/main/java/com/nucleodb/library/database/tables/table/DataEntryProjection.java b/src/main/java/com/nucleodb/library/database/tables/table/DataEntryProjection.java index e083916..061b54a 100644 --- a/src/main/java/com/nucleodb/library/database/tables/table/DataEntryProjection.java +++ b/src/main/java/com/nucleodb/library/database/tables/table/DataEntryProjection.java @@ -9,6 +9,8 @@ public class DataEntryProjection{ Predicate filter = null; + boolean writable = true; + public DataEntryProjection(Pagination pagination, Predicate filter) { this.pagination = pagination; this.filter = filter; @@ -41,4 +43,20 @@ public void setPagination(Pagination pagination) { public void setFilter(Predicate filter) { this.filter = filter; } + + public Pagination getPagination() { + return pagination; + } + + public Predicate getFilter() { + return filter; + } + + public boolean isWritable() { + return writable; + } + + public void setWritable(boolean writable) { + this.writable = writable; + } } diff --git a/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java b/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java index ce14cfa..c74c505 100644 --- a/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java +++ b/src/main/java/com/nucleodb/library/database/tables/table/DataTable.java @@ -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; @@ -325,7 +326,12 @@ public Set 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 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(); } @@ -351,7 +357,12 @@ public Set 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 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 getNotEqual(String key, Object value, DataEntryProjection dataEntryProjection) { @@ -368,7 +379,12 @@ public Set getNotEqual(String key, Object value, DataEntryProjection Set 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 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();