diff --git a/jnosql-solr/src/main/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManager.java b/jnosql-solr/src/main/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManager.java index 30b235371..fcf729773 100644 --- a/jnosql-solr/src/main/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManager.java +++ b/jnosql-solr/src/main/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManager.java @@ -23,6 +23,9 @@ import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrInputDocument; +import org.eclipse.jnosql.communication.document.Document; +import org.eclipse.jnosql.communication.document.DocumentCondition; +import org.eclipse.jnosql.communication.document.DocumentConfiguration; import org.eclipse.jnosql.communication.document.DocumentDeleteQuery; import org.eclipse.jnosql.communication.document.DocumentEntity; import org.eclipse.jnosql.communication.document.DocumentQuery; @@ -106,6 +109,17 @@ public Iterable insert(Iterable entities, Durati @Override public DocumentEntity update(DocumentEntity entity) { + Objects.requireNonNull(entity, "entity is required"); + + Document id = entity.find("_id").orElseThrow(() -> + new IllegalArgumentException("The _id field is required for update")); + + DocumentCondition condition = DocumentCondition.eq(id); + DocumentDeleteQuery query = DocumentDeleteQuery.builder() + .from(entity.name()) + .where(condition).build(); + delete(query); + return insert(entity); } diff --git a/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManagerTest.java b/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManagerTest.java index 26adaf8e6..78aa67270 100644 --- a/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManagerTest.java +++ b/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/communication/DefaultSolrDocumentManagerTest.java @@ -53,7 +53,7 @@ public class DefaultSolrDocumentManagerTest { public static final String COLLECTION_NAME = "person"; - public static final String ID = "id"; + public static final String ID = "_id"; private static SolrDocumentManager entityManager; @BeforeAll diff --git a/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/integration/SolrTemplateIntegrationTest.java b/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/integration/SolrTemplateIntegrationTest.java index 65bf3667b..0bfa041dd 100644 --- a/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/integration/SolrTemplateIntegrationTest.java +++ b/jnosql-solr/src/test/java/org/eclipse/jnosql/databases/solr/integration/SolrTemplateIntegrationTest.java @@ -51,7 +51,7 @@ class SolrTemplateIntegrationTest { static { DocumentDatabase.INSTANCE.get(); - System.setProperty(SolrDocumentConfigurations.HOST.get() + ".1", DocumentDatabase.INSTANCE.host()); + System.setProperty(SolrDocumentConfigurations.HOST.get(), DocumentDatabase.INSTANCE.host()); System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "database"); }