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