Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  *  Copyright 2013-2014 Pavel Ponec
  *  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
 *  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.
package org.ujorm.orm;
Support for the native database sequences. The sequence name can be specified in the parameter org.ujorm.orm.annot.Table.sequence().

Pavel Ponec
public class NativeDbSequencer extends UjoSequencer {

    private static final UjoLogger LOGGER = UjoLoggerFactory.getLogger(OrmProperty.class);

Required constructor
    public NativeDbSequencer(MetaTable table) {

    public synchronized long nextValue(Session session) {
        final String sequenceName = ..of();
        if (UjoManager.isFilled(sequenceName)) {
            try {
                ResultSet rs = session.getFirstConnection().createStatement().executeQuery(createNextSequence(sequenceName));
                if ( {
                    return rs.getLong(1);
                } else {
                    throw new IllegalStateException("No value for sequence: " + sequenceName);
            } catch (Exception e) {
                final String msg = "Sequence error for name: " + sequenceName;
                throw new IllegalStateException(msge);
        return super.nextValue(session);

Create a SQL script for the NEXT SEQUENCE from a native database sequencer
    public String createNextSequence(String sequenceNamethrows IOException {
        return ..of()
              .printNextSequence(sequenceNamenew StringBuilder(128))
New to GrepCode? Check out our FAQ X