Details

    • Type: Sub-task Sub-task
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1
    • Component/s: JDO queries
    • Labels:
      None
    • Number of attachments :
      2
    1. patch-C2776-20090729.txt
      13 kB
      AHMAD HASSAN
    2. patch-C2776-20090729-01.txt
      13 kB
      Ralf Joachim

      Issue Links

        Activity

        Hide
        Ralf Joachim added a comment -

        CASTOR-2774 should be resolved first

        Show
        Ralf Joachim added a comment - CASTOR-2774 should be resolved first
        Hide
        AHMAD HASSAN added a comment -

        While working on this patch, I used the Select class hierarchy to generate select query. Previously the QueryExpression class was generating sql select query. But the query is being generated by SQLSelectInsertCheck by itself. The difference is as follows

        
        old query      SELECT 1 FROM test87_extended WHERE test87_extended.id=? FOR UPDATE
        new query    SELECT test87_extended.id FROM test87_extended WHERE test87_extended.id=?
        
        

        The method for creating the old query is

        /** 
             * Build SQL statement to check for duplicate keys.
             *  
             * @throws MappingException If unable to get query from QueryExpression.
             */
            private void buildStatement() throws MappingException {
                try {
                    QueryExpression query = _factory.getQueryExpression();
        
                    // initalize lookup query
                    for (int i = 0; i < _ids.length; i++) {
                        query.addParameter(_mapTo, _ids[i].getName(), QueryExpression.OP_EQUALS);
                    }
                    _statement = query.getStatement(true);
                } catch (QueryException except) {
                  LOG.warn("Problem building SQL", except);
                  throw new MappingException(except);
                }
            }
        

        The method for creating new query is

            /**
             * Build SQL statement to check for duplicate keys.
             * 
             * @param mapTo Table name from which records need to be fetched.
             */
            private void buildStatement(final String mapTo) {  
                // initialize Select.
                Select select = new Select(mapTo);
                 
                // Adding fields to be fetched.
                select.addSelect(mapTo, _ids[0].getName());
                 
                // Adding conditions to the select statement
                for (int i = 0; i < _ids.length; i++) {             
                    select.addCondition(mapTo, _ids[i].getName());
                }
                 
                // construct SQL query string by walking through select class hierarchy and
                // generate map of parameter names to indices for binding of parameters.      
                select.toString(_ctx);
            }
        

        In our usecase, I think we do not 'FOR UPDATE' clause in the end of select. What do you think...

        Is this the correct way?

        Regards.

        Show
        AHMAD HASSAN added a comment - While working on this patch, I used the Select class hierarchy to generate select query. Previously the QueryExpression class was generating sql select query. But the query is being generated by SQLSelectInsertCheck by itself. The difference is as follows old query SELECT 1 FROM test87_extended WHERE test87_extended.id=? FOR UPDATE new query SELECT test87_extended.id FROM test87_extended WHERE test87_extended.id=? The method for creating the old query is /** * Build SQL statement to check for duplicate keys. * * @ throws MappingException If unable to get query from QueryExpression. */ private void buildStatement() throws MappingException { try { QueryExpression query = _factory.getQueryExpression(); // initalize lookup query for ( int i = 0; i < _ids.length; i++) { query.addParameter(_mapTo, _ids[i].getName(), QueryExpression.OP_EQUALS); } _statement = query.getStatement( true ); } catch (QueryException except) { LOG.warn( "Problem building SQL" , except); throw new MappingException(except); } } The method for creating new query is /** * Build SQL statement to check for duplicate keys. * * @param mapTo Table name from which records need to be fetched. */ private void buildStatement( final String mapTo) { // initialize Select. Select select = new Select(mapTo); // Adding fields to be fetched. select.addSelect(mapTo, _ids[0].getName()); // Adding conditions to the select statement for ( int i = 0; i < _ids.length; i++) { select.addCondition(mapTo, _ids[i].getName()); } // construct SQL query string by walking through select class hierarchy and // generate map of parameter names to indices for binding of parameters. select.toString(_ctx); } In our usecase, I think we do not 'FOR UPDATE' clause in the end of select. What do you think... Is this the correct way? Regards.
        Hide
        Ralf Joachim added a comment -

        Final patch.

        Show
        Ralf Joachim added a comment - Final patch.

          People

          • Assignee:
            AHMAD HASSAN
            Reporter:
            Ralf Joachim
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: