// Path: src/main/java/com/globalsight/ling/tm3/core/TM3Exception.java
// public class TM3Exception extends RuntimeException {
//     public TM3Exception(String s) {
//         super(s);
//     }
//     
//     public TM3Exception(String string, Throwable root) {
//         super(string, root);
//     }
//                
//     public TM3Exception(Throwable root) { 
//         super(root);
//     }
// }
// 
// Path: src/main/java/com/globalsight/ling/tm3/core/persistence/StatementBuilder.java
// public class StatementBuilder extends AbstractStatementBuilder {
//     private List<Object> args = new ArrayList<Object>();
//     
//     public StatementBuilder() { 
//         super();
//     }
//     
//     public StatementBuilder(CharSequence s) {
//         super(s);
//     }
//     
//     public StatementBuilder(CharSequence s, Object...args) {
//         super(s);
//         addValues(args);
//     }
//     
//     public StatementBuilder append(CharSequence s) {
//         super.append(s);
//         return this;
//     }
//     
//     public StatementBuilder append(StatementBuilder builder) {
//         super.append(builder.getBuffer());
//         args.addAll(builder.args);
//         return this;
//     }
//     
//     public StatementBuilder addValue(Object o) {
//         args.add(o);
//         return this;
//     }
//     
//     public StatementBuilder addValues(Object...os) {
//         args.addAll(Arrays.asList(os));
//         return this;
//     }
//     
//     /**
//      * Create a PreparedStatement with all attached values inserted.
//      */
//     public PreparedStatement toPreparedStatement(Connection conn) 
//             throws SQLException {
//         PreparedStatement ps = conn.prepareStatement(getBuffer().toString());
//         int index = 1;
//         for (Object o : args) {
//             ps.setObject(index++, o);
//         }
//         this.setStatement(ps);
//         return ps;
//     }
//     
//     @Override
//     public String toString() {
//         StringBuilder s = new StringBuilder();
//         s.append("Statement[")
//          .append(getBuffer())
//          .append(", values=(");
//         for (int i = 0; i < args.size(); i++) {
//             if (i > 0) s.append(", ");
//             s.append(args.get(i));
//         }
//         s.append(")]");
//         return s.toString();
//     }
// }


import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import com.globalsight.ling.tm3.core.TM3Exception;
import com.globalsight.ling.tm3.core.persistence.StatementBuilder;
package com.globalsight.ling.tm3.core.persistence;



/**
 * This class should not be public; I need to fix the test setup.
 * 
 * Note that instances of this class are not themselves threadsafe.
 */
public class DistributedId {

    private String tableName;
    private long nextId = 0;
    private long max = 0;
    private int increment = 100;
    
    public DistributedId(String tableName) {
        this.tableName = tableName;
    }
    
    public DistributedId(String tableName, int increment) {
        this.tableName = tableName;
        this.increment = increment;
    }

    public long getId(Connection conn) throws SQLException {
        if (nextId >= max) {
            nextId = reserveId(conn, increment);
            max = nextId + increment;
        }
        return nextId++;
    }
    
    public void destroy(Connection conn) throws SQLException {
// Path: src/main/java/com/globalsight/ling/tm3/core/TM3Exception.java
// public class TM3Exception extends RuntimeException {
//     public TM3Exception(String s) {
//         super(s);
//     }
//     
//     public TM3Exception(String string, Throwable root) {
//         super(string, root);
//     }
//                
//     public TM3Exception(Throwable root) { 
//         super(root);
//     }
// }
// 
// Path: src/main/java/com/globalsight/ling/tm3/core/persistence/StatementBuilder.java
// public class StatementBuilder extends AbstractStatementBuilder {
//     private List<Object> args = new ArrayList<Object>();
//     
//     public StatementBuilder() { 
//         super();
//     }
//     
//     public StatementBuilder(CharSequence s) {
//         super(s);
//     }
//     
//     public StatementBuilder(CharSequence s, Object...args) {
//         super(s);
//         addValues(args);
//     }
//     
//     public StatementBuilder append(CharSequence s) {
//         super.append(s);
//         return this;
//     }
//     
//     public StatementBuilder append(StatementBuilder builder) {
//         super.append(builder.getBuffer());
//         args.addAll(builder.args);
//         return this;
//     }
//     
//     public StatementBuilder addValue(Object o) {
//         args.add(o);
//         return this;
//     }
//     
//     public StatementBuilder addValues(Object...os) {
//         args.addAll(Arrays.asList(os));
//         return this;
//     }
//     
//     /**
//      * Create a PreparedStatement with all attached values inserted.
//      */
//     public PreparedStatement toPreparedStatement(Connection conn) 
//             throws SQLException {
//         PreparedStatement ps = conn.prepareStatement(getBuffer().toString());
//         int index = 1;
//         for (Object o : args) {
//             ps.setObject(index++, o);
//         }
//         this.setStatement(ps);
//         return ps;
//     }
//     
//     @Override
//     public String toString() {
//         StringBuilder s = new StringBuilder();
//         s.append("Statement[")
//          .append(getBuffer())
//          .append(", values=(");
//         for (int i = 0; i < args.size(); i++) {
//             if (i > 0) s.append(", ");
//             s.append(args.get(i));
//         }
//         s.append(")]");
//         return s.toString();
//     }
// }


// Path: src/main/java/com/globalsight/ling/tm3/core/persistence/DistributedId.java
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import com.globalsight.ling.tm3.core.TM3Exception;
import com.globalsight.ling.tm3.core.persistence.StatementBuilder;

package com.globalsight.ling.tm3.core.persistence;



/**
 * This class should not be public; I need to fix the test setup.
 * 
 * Note that instances of this class are not themselves threadsafe.
 */
public class DistributedId {

    private String tableName;
    private long nextId = 0;
    private long max = 0;
    private int increment = 100;
    
    public DistributedId(String tableName) {
        this.tableName = tableName;
    }
    
    public DistributedId(String tableName, int increment) {
        this.tableName = tableName;
        this.increment = increment;
    }

    public long getId(Connection conn) throws SQLException {
        if (nextId >= max) {
            nextId = reserveId(conn, increment);
            max = nextId + increment;
        }
        return nextId++;
    }
    
    public void destroy(Connection conn) throws SQLException {
        SQLUtil.exec(conn, new StatementBuilder()