Coverage Report - org.apache.ojb.broker.platforms.KualiMySQLSequenceManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiMySQLSequenceManagerImpl
0%
0/24
0%
0/4
4
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.ojb.broker.platforms;
 17  
 
 18  
 import java.sql.Connection;
 19  
 import java.sql.ResultSet;
 20  
 import java.sql.Statement;
 21  
 
 22  
 import org.apache.ojb.broker.PersistenceBroker;
 23  
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 24  
 import org.apache.ojb.broker.util.sequence.AbstractSequenceManager;
 25  
 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
 26  
 
 27  
 public class KualiMySQLSequenceManagerImpl extends AbstractSequenceManager {
 28  
 
 29  
         public KualiMySQLSequenceManagerImpl(PersistenceBroker broker) {
 30  0
                 super(broker);
 31  0
         }
 32  
 
 33  
         @Override
 34  
         protected long getUniqueLong(FieldDescriptor arg0)
 35  
                         throws SequenceManagerException {
 36  0
                 PersistenceBroker broker = getBrokerForClass();
 37  
 
 38  0
                 Statement stmt = null;
 39  0
                 Long seqNumber = null;
 40  0
                 final String sequenceName = arg0.getSequenceName();
 41  
 
 42  
                 try {
 43  
                         //FIXME: should we be closing this connection in a finally block?
 44  0
                         Connection c = broker.serviceConnectionManager().getConnection();
 45  0
                         stmt = c.createStatement();
 46  0
                         String sql = "INSERT INTO " + sequenceName + " VALUES (NULL);";
 47  0
                         stmt.executeUpdate(sql);
 48  0
                         sql = "SELECT LAST_INSERT_ID()";
 49  
                         
 50  
                         //FIXME: should we be closing this result set in a finally block?
 51  0
                         ResultSet rs = stmt.executeQuery(sql);
 52  0
                         if (rs != null) {
 53  0
                                 rs.first();
 54  0
                                 seqNumber = rs.getLong(1);
 55  
                         }
 56  0
                 } catch (Exception e) {
 57  0
                         throw new RuntimeException("Unable to execute for sequence name: " + sequenceName, e);
 58  
                 } finally {
 59  0
                         try {
 60  0
                                 if (stmt != null) {
 61  0
                                         stmt.close();
 62  
                                 }
 63  0
                         } catch (Exception e) {
 64  0
                                 throw new RuntimeException("Unable to close statement for sequence name: " + sequenceName, e);
 65  0
                         }
 66  
                 }
 67  
 
 68  0
                 return seqNumber;
 69  
         }
 70  
 
 71  
 }