Search in sources :

Example 1 with JDOQLTypedQuery

use of javax.jdo.JDOQLTypedQuery in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedQueryImpl method saveAsNamedQuery.

/* (non-Javadoc)
     * @see javax.jdo.JDOQLTypedQuery#saveAsNamedQuery(java.lang.String)
     */
@Override
public JDOQLTypedQuery<T> saveAsNamedQuery(String name) {
    assertIsOpen();
    JDOPersistenceManagerFactory.checkJDOPermission(JDOPermission.GET_METADATA);
    QueryMetaData qmd = new QueryMetaData(name);
    qmd.setLanguage(Query.LANGUAGE_JDOQL);
    Query query = getInternalQuery();
    qmd.setQuery(query.toString());
    qmd.setResultClass(query.getResultClassName());
    qmd.setUnique(query.isUnique());
    Map<String, Object> queryExts = query.getExtensions();
    if (queryExts != null && !queryExts.isEmpty()) {
        Iterator<Map.Entry<String, Object>> queryExtsIter = queryExts.entrySet().iterator();
        while (queryExtsIter.hasNext()) {
            Map.Entry<String, Object> queryExtEntry = queryExtsIter.next();
            qmd.addExtension(queryExtEntry.getKey(), "" + queryExtEntry.getValue());
        }
    }
    query.getExecutionContext().getMetaDataManager().registerNamedQuery(qmd);
    return this;
}
Also used : QueryMetaData(org.datanucleus.metadata.QueryMetaData) Query(org.datanucleus.store.query.Query) JDOQLTypedQuery(javax.jdo.JDOQLTypedQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JDOQLTypedQuery (javax.jdo.JDOQLTypedQuery)1 JDOQuery (org.datanucleus.api.jdo.JDOQuery)1 QueryMetaData (org.datanucleus.metadata.QueryMetaData)1 Query (org.datanucleus.store.query.Query)1