blob: 1875fbb885cf0389c8887fe28c56d040c158b048 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr)
* 7 Colonel Roche 31077 Toulouse - France
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* Thierry Monteil : Project manager, technical co-manager
* Mahdi Ben Alaya : Technical co-manager
* Samir Medjiah : Technical co-manager
* Khalil Drira : Strategy expert
* Guillaume Garzone : Developer
* François Aïssaoui : Developer
*
* New contributors :
*******************************************************************************/
package org.eclipse.om2m.persistence.eclipselink.internal.dao;
import org.eclipse.om2m.commons.constants.DBEntities;
import org.eclipse.om2m.commons.entities.UriMapperEntity;
import org.eclipse.om2m.persistence.eclipselink.internal.DBTransactionJPAImpl;
import org.eclipse.om2m.persistence.service.DBTransaction;
public class UriMapperDAO extends AbstractDAO<UriMapperEntity>{
@Override
public UriMapperEntity find(DBTransaction dbTransaction, Object id) {
DBTransactionJPAImpl transaction = (DBTransactionJPAImpl) dbTransaction;
return transaction.getEm().find(UriMapperEntity.class, id);
}
@Override
public void delete(DBTransaction dbTransaction, UriMapperEntity resource) {
DBTransactionJPAImpl transaction = (DBTransactionJPAImpl) dbTransaction;
// Delete the entry of the current entity
String req = "DELETE FROM "+DBEntities.URI_MAPPER_ENTITY+" U WHERE U.hierarchicalUri LIKE '"+resource.getHierarchicalUri()+"'";
// Delete all children of the current entity
transaction.getEm().createQuery(req).executeUpdate();
req = "DELETE FROM "+DBEntities.URI_MAPPER_ENTITY+" U WHERE U.hierarchicalUri LIKE '"+resource.getHierarchicalUri()+"/%'";
transaction.getEm().createQuery(req).executeUpdate();
}
}