EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.command.ddl]

COVERAGE SUMMARY FOR SOURCE FILE [CreateSequence.java]

nameclass, %method, %block, %line, %
CreateSequence.java100% (1/1)100% (13/13)96%  (129/134)97%  (38/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateSequence100% (1/1)100% (13/13)96%  (129/134)97%  (38/39)
update (): int 100% (1/1)94%  (72/77)93%  (14/15)
CreateSequence (Session, Schema): void 100% (1/1)100% (5/5)100% (2/2)
getLong (Expression): Long 100% (1/1)100% (14/14)100% (3/3)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setBelongsToTable (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setCacheSize (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setCycle (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setIfNotExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setIncrement (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setMaxValue (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setMinValue (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setSequenceName (String): void 100% (1/1)100% (4/4)100% (2/2)
setStartWith (Expression): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.command.ddl;
7 
8import org.h2.api.ErrorCode;
9import org.h2.command.CommandInterface;
10import org.h2.engine.Database;
11import org.h2.engine.Session;
12import org.h2.expression.Expression;
13import org.h2.message.DbException;
14import org.h2.schema.Schema;
15import org.h2.schema.Sequence;
16 
17/**
18 * This class represents the statement
19 * CREATE SEQUENCE
20 */
21public class CreateSequence extends SchemaCommand {
22 
23    private String sequenceName;
24    private boolean ifNotExists;
25    private boolean cycle;
26    private Expression minValue;
27    private Expression maxValue;
28    private Expression start;
29    private Expression increment;
30    private Expression cacheSize;
31    private boolean belongsToTable;
32 
33    public CreateSequence(Session session, Schema schema) {
34        super(session, schema);
35    }
36 
37    public void setSequenceName(String sequenceName) {
38        this.sequenceName = sequenceName;
39    }
40 
41    public void setIfNotExists(boolean ifNotExists) {
42        this.ifNotExists = ifNotExists;
43    }
44 
45    public void setCycle(boolean cycle) {
46        this.cycle = cycle;
47    }
48 
49    @Override
50    public int update() {
51        session.commit(true);
52        Database db = session.getDatabase();
53        if (getSchema().findSequence(sequenceName) != null) {
54            if (ifNotExists) {
55                return 0;
56            }
57            throw DbException.get(ErrorCode.SEQUENCE_ALREADY_EXISTS_1, sequenceName);
58        }
59        int id = getObjectId();
60        Long startValue = getLong(start);
61        Long inc = getLong(increment);
62        Long cache = getLong(cacheSize);
63        Long min = getLong(minValue);
64        Long max = getLong(maxValue);
65        Sequence sequence = new Sequence(getSchema(), id, sequenceName, startValue, inc,
66            cache, min, max, cycle, belongsToTable);
67        db.addSchemaObject(session, sequence);
68        return 0;
69    }
70 
71    private Long getLong(Expression expr) {
72        if (expr == null) {
73            return null;
74        }
75        return expr.optimize(session).getValue(session).getLong();
76    }
77 
78    public void setStartWith(Expression start) {
79        this.start = start;
80    }
81 
82    public void setIncrement(Expression increment) {
83        this.increment = increment;
84    }
85 
86    public void setMinValue(Expression minValue) {
87        this.minValue = minValue;
88    }
89 
90    public void setMaxValue(Expression maxValue) {
91        this.maxValue = maxValue;
92    }
93 
94    public void setBelongsToTable(boolean belongsToTable) {
95        this.belongsToTable = belongsToTable;
96    }
97 
98    public void setCacheSize(Expression cacheSize) {
99        this.cacheSize = cacheSize;
100    }
101 
102    @Override
103    public int getType() {
104        return CommandInterface.CREATE_SEQUENCE;
105    }
106 
107}

[all classes][org.h2.command.ddl]
EMMA 2.0.5312 (C) Vladimir Roubtsov