/*
 * The Gemma project.
 * 
 * Copyright (c) 2006 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package ubic.gemma.model.genome.sequenceAnalysis;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;

import ubic.gemma.model.genome.biosequence.BioSequence;
import ubic.gemma.util.BusinessKey;

/**
 * @see ubic.gemma.model.genome.sequenceAnalysis.BlatResult
 */
public class BlatResultDaoImpl extends ubic.gemma.model.genome.sequenceAnalysis.BlatResultDaoBase {

    /*
     * (non-Javadoc)
     * 
     * @see ubic.gemma.model.genome.sequenceAnalysis.BlatResultDaoBase#find(ubic.gemma.model.genome.biosequence.BioSequence)
     */
    @SuppressWarnings("unchecked")
    @Override
    public Collection<BlatResult> findByBioSequence( BioSequence bioSequence ) {
        BusinessKey.checkValidKey( bioSequence );

        Criteria queryObject = super.getSession( false ).createCriteria( BlatResult.class );

        BusinessKey.attachCriteria( queryObject, bioSequence, "querySequence" );

        List results = queryObject.list();

        if ( results != null ) {
            for ( Object object : results ) {
                BlatResult br = ( BlatResult ) object;
                if ( br.getTargetChromosome() != null ) {
                    br.getTargetChromosome().getName(); // to initialize the proxies.
                }
                br.getQuerySequence();
            }
        }

        return results;
    }
    
      /* (non-Javadoc)
     * @see ubic.gemma.model.genome.sequenceAnalysis.BlatResultDaoBase#findOrCreate(ubic.gemma.model.genome.sequenceAnalysis.BlatResult)
     */
    @Override
    public ubic.gemma.model.genome.sequenceAnalysis.BlatResult findOrCreate(ubic.gemma.model.genome.sequenceAnalysis.BlatResult blatResult){
        if ( blatResult.getQuerySequence() == null )
            throw new IllegalArgumentException( "BlatResult must have a querrySequence associated with it." );
        
        
        BlatResult result = this.find( blatResult );
        if ( result != null )
            return result;
       
        
        logger.debug( "Creating new BlatResult: " + blatResult.toString() );
        result = ( BlatResult ) create( blatResult );
        return result;
    }

    /* (non-Javadoc)
     * @see ubic.gemma.model.genome.sequenceAnalysis.BlatResultDaoBase#handleLoad(java.util.Collection)
     */
    @Override
    protected Collection handleLoad( Collection ids ) throws Exception {
        Collection<BlatResult> blatResults = null;
        final String queryString = "select distinct blatResult from BlatResultImpl blatResult where blatResult.id in (:ids)";
        try {
            org.hibernate.Query queryObject = super.getSession( false ).createQuery( queryString );
            queryObject.setParameterList( "ids", ids );
            blatResults = queryObject.list();

        } catch ( org.hibernate.HibernateException ex ) {
            throw super.convertHibernateAccessException( ex );
        }
        return blatResults;
    }

}
@@ -2127,20 +2127,21 @@
   %7D%0A
+%0A
     
+/*
 %0A     
- /
 * (n
@@ -2144,32 +2144,40 @@
 * (non-Javadoc)%0A
+     * %0A
      * @see ubic
@@ -2387,32 +2387,45 @@
 lt findOrCreate(
+%0A            
 ubic.gemma.model
@@ -2470,17 +2470,19 @@
 atResult
-)
+ ) 
 %7B%0A      
@@ -2643,26 +2643,9 @@
  );%0A
-        %0A        
 %0A
+
     
@@ -2722,28 +2722,16 @@
 = null )
-%0A           
  return 
@@ -2738,32 +2738,16 @@
 result;%0A
-       %0A        
 %0A       
@@ -2906,16 +2906,23 @@
 %0A%0A    /*
+%0A     *
  (non-Ja
@@ -2924,24 +2924,32 @@
 on-Javadoc)%0A
+     * %0A
      * @see 
@@ -3139,59 +3139,8 @@
 n %7B%0A
-        Collection%3CBlatResult%3E blatResults = null;%0A
     
@@ -3273,374 +3273,86 @@
     
-try %7B%0A            org.hibernate.Query queryObject = super.getSession( false ).createQuery( queryString );%0A            queryObject.setParameterList( %22ids%22, ids );%0A            blatResults = queryObject.list();%0A%0A        %7D catch ( org.hibernate.HibernateException ex ) %7B%0A            throw super.convertHibernateAccessException( ex );%0A        %7D%0A        return blatResults
+return this.getHibernateTemplate().findByNamedParam( queryString, %22ids%22, ids )
 ;%0A  

use hibernatetemplate