mirror of https://github.com/apache/cloudstack.git
api: Implement findByXId in GenericDaoBase and EntityManagerImpl
Declare and define findByXId() in GenericDao and EntityManager. This method would return a VO by UUID and EntityManager's interface would take in the VO Interface. Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
parent
d54d8cbcd7
commit
837d21bb2d
|
|
@ -45,7 +45,7 @@ public interface EntityManager {
|
|||
* @param xid external id
|
||||
* @return T if found, null if not.
|
||||
*/
|
||||
public <T> T findByXid(Class<T> entityType, String xid);
|
||||
public <T> T findByXId(Class<T> entityType, String xid);
|
||||
|
||||
/**
|
||||
* Lists all entities. Use this method at your own risk.
|
||||
|
|
|
|||
|
|
@ -45,8 +45,9 @@ public class EntityManagerImpl implements EntityManager, Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T findByXid(Class<T> entityType, String xid) {
|
||||
return null;
|
||||
public <T> T findByXId(Class<T> entityType, String xid) {
|
||||
GenericDao<? extends T, String> dao = (GenericDao<? extends T, String>)GenericDaoBase.getDao(entityType);
|
||||
return dao.findByXId(xid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ public interface GenericDao<T, ID extends Serializable> {
|
|||
T findByIdIncludingRemoved(ID id);
|
||||
|
||||
T findById(ID id, boolean fresh);
|
||||
|
||||
// Finds a VO object using uuid
|
||||
T findByXId(ID uuid);
|
||||
|
||||
/**
|
||||
* @return VO object ready to be used for update. It won't have any fields filled in.
|
||||
|
|
|
|||
|
|
@ -913,6 +913,14 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
}
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
@SuppressWarnings("unchecked")
|
||||
public T findByXId(final ID uuid) {
|
||||
SearchCriteria<T> sc = createSearchCriteria();
|
||||
sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
public T findByIdIncludingRemoved(ID id) {
|
||||
return findById(id, true, null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue