Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2009 Mysema Ltd.
   * All rights reserved.
   *
   */
  package com.mysema.query.jdoql.dml;
  
  import java.util.List;
 import java.util.Map;
 
 import  javax.jdo.PersistenceManager;
 import  javax.jdo.Query;
 
DeleteClause implementation for JDO

Author(s):
tiwe
 
 public class JDOQLDeleteClause implements DeleteClause<JDOQLDeleteClause>{
 
     private final QueryMetadata metadata = new DefaultQueryMetadata();
 
     private final PersistenceManager persistenceManager;
 
     private final JDOQLTemplates templates;
 
     private final PEntity<?> entity;
 
     public JDOQLDeleteClause(PersistenceManager pmPEntity<?> entity){
         this(pmentity.);
     }
 
     public JDOQLDeleteClause(PersistenceManager persistenceManagerPEntity<?> entityJDOQLTemplates templates){
         this. = entity;
         this. = persistenceManager;
         this. = templates;
         .addJoin(.entity);
     }
 
     @Override
     public long execute() {
         Query query = .newQuery(.getType());
         if (.getWhere() != null){
             JDOQLSerializer serializer = new JDOQLSerializer();
             serializer.handle(.getWhere());
             query.setFilter(serializer.toString());
             Map<Object,StringconstToLabel = serializer.getConstantToLabel();
 
             try{
                 if (!constToLabel.isEmpty()) {
                     List<Objectconstants = new ArrayList<Object>(constToLabel.size());
                     StringBuilder builder = new StringBuilder();
                     for (Map.Entry<ObjectStringentry : constToLabel.entrySet()){
                         if (builder.length() > 0){
                             builder.append(", ");
                         }
                         builder.append(entry.getKey().getClass().getName()).append(" ");
                         builder.append(entry.getValue());
                         constants.add(entry.getKey());
                     }
                     query.declareParameters(builder.toString());
                     return query.deletePersistentAll(constants.toArray());
                 } else {
                     return query.deletePersistentAll();
                 }
             }finally{
                 query.closeAll();
             }
         }else{
             try{
                 return query.deletePersistentAll();
             }finally{
                 query.closeAll();
             }
         }
     }
 
     @Override
     public JDOQLDeleteClause where(EBoolean... o) {
         .addWhere(o);
         return this;
     }
     
     @Override
     public String toString(){
         JDOQLSerializer serializer = new JDOQLSerializer();
         serializer.handle(.getWhere());
         return serializer.toString();
    }
New to GrepCode? Check out our FAQ X