-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Jakarta Persistence Driver - Support for some delete statements
Depends on Eclipselink snapshot version, which contains a few fixes
- Loading branch information
Showing
13 changed files
with
124 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...e-driver/src/main/java/org/eclipse/jnosql/jakartapersistence/mapping/BaseQueryParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Ondro Mihalyi | ||
*/ | ||
package org.eclipse.jnosql.jakartapersistence.mapping; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.metamodel.EntityType; | ||
import org.eclipse.jnosql.jakartapersistence.communication.PersistenceDatabaseManager; | ||
|
||
class BaseQueryParser { | ||
|
||
protected final PersistenceDatabaseManager manager; | ||
|
||
protected BaseQueryParser(PersistenceDatabaseManager manager) { | ||
this.manager = manager; | ||
} | ||
|
||
protected <T> EntityType<T> findEntityType(String entityName) { | ||
return manager.findEntityType(entityName); | ||
} | ||
|
||
protected EntityManager entityManager() { | ||
return manager.getEntityManager(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...driver/src/main/java/org/eclipse/jnosql/jakartapersistence/mapping/DeleteQueryParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Ondro Mihalyi | ||
*/ | ||
package org.eclipse.jnosql.jakartapersistence.mapping; | ||
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.CriteriaDelete; | ||
import jakarta.persistence.criteria.Root; | ||
import jakarta.persistence.metamodel.EntityType; | ||
import jakarta.persistence.metamodel.SingularAttribute; | ||
import org.eclipse.jnosql.jakartapersistence.communication.PersistenceDatabaseManager; | ||
|
||
class DeleteQueryParser extends BaseQueryParser { | ||
|
||
|
||
public DeleteQueryParser(PersistenceDatabaseManager manager) { | ||
super(manager); | ||
} | ||
|
||
public <T, K> void delete(Class<T> type, K key) { | ||
CriteriaBuilder criteriaBuilder = entityManager().getCriteriaBuilder(); | ||
CriteriaDelete<T> deleteCriteria = criteriaBuilder.createCriteriaDelete(type); | ||
Root<?> root = deleteCriteria.from(type); | ||
String entityIdName = getEntityIdName(type); | ||
deleteCriteria.where(criteriaBuilder.equal(root.get(entityIdName), key)); | ||
entityManager().createQuery(deleteCriteria).executeUpdate(); | ||
} | ||
|
||
private <T> String getEntityIdName(Class<T> type) { | ||
EntityType<T> entityType = entityManager().getMetamodel().entity(type); | ||
SingularAttribute<?, ?> idAttribute = entityType.getId(entityType.getIdType().getJavaType()); | ||
String entityIdName = idAttribute.getName(); | ||
return entityIdName; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters