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

COVERAGE SUMMARY FOR SOURCE FILE [AlterSequence.java]

nameclass, %method, %block, %line, %
AlterSequence.java100% (1/1)100% (13/13)87%  (160/184)95%  (45.4/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AlterSequence100% (1/1)100% (13/13)87%  (160/184)95%  (45.4/48)
setColumn (Column): void 100% (1/1)71%  (12/17)80%  (4/5)
update (): int 100% (1/1)84%  (97/116)93%  (20.4/22)
AlterSequence (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)
isTransactional (): boolean 100% (1/1)100% (2/2)100% (1/1)
setCacheSize (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setCycle (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)
setSequence (Sequence): 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.dml;
7 
8import org.h2.api.ErrorCode;
9import org.h2.command.CommandInterface;
10import org.h2.command.ddl.SchemaCommand;
11import org.h2.engine.Database;
12import org.h2.engine.Right;
13import org.h2.engine.Session;
14import org.h2.expression.Expression;
15import org.h2.message.DbException;
16import org.h2.schema.Schema;
17import org.h2.schema.Sequence;
18import org.h2.table.Column;
19import org.h2.table.Table;
20 
21/**
22 * This class represents the statement
23 * ALTER SEQUENCE
24 */
25public class AlterSequence extends SchemaCommand {
26 
27    private Table table;
28    private Sequence sequence;
29    private Expression start;
30    private Expression increment;
31    private Boolean cycle;
32    private Expression minValue;
33    private Expression maxValue;
34    private Expression cacheSize;
35 
36    public AlterSequence(Session session, Schema schema) {
37        super(session, schema);
38    }
39 
40    public void setSequence(Sequence sequence) {
41        this.sequence = sequence;
42    }
43 
44    @Override
45    public boolean isTransactional() {
46        return true;
47    }
48 
49    public void setColumn(Column column) {
50        table = column.getTable();
51        sequence = column.getSequence();
52        if (sequence == null) {
53            throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, column.getSQL());
54        }
55    }
56 
57    public void setStartWith(Expression start) {
58        this.start = start;
59    }
60 
61    public void setIncrement(Expression increment) {
62        this.increment = increment;
63    }
64 
65    public void setCycle(Boolean cycle) {
66        this.cycle = cycle;
67    }
68 
69    public void setMinValue(Expression minValue) {
70        this.minValue = minValue;
71    }
72 
73    public void setMaxValue(Expression maxValue) {
74        this.maxValue = maxValue;
75    }
76 
77    public void setCacheSize(Expression cacheSize) {
78        this.cacheSize = cacheSize;
79    }
80 
81    @Override
82    public int update() {
83        Database db = session.getDatabase();
84        if (table != null) {
85            session.getUser().checkRight(table, Right.ALL);
86        }
87        if (cycle != null) {
88            sequence.setCycle(cycle);
89        }
90        if (cacheSize != null) {
91            long size = cacheSize.optimize(session).getValue(session).getLong();
92            sequence.setCacheSize(size);
93        }
94        if (start != null || minValue != null ||
95                maxValue != null || increment != null) {
96            Long startValue = getLong(start);
97            Long min = getLong(minValue);
98            Long max = getLong(maxValue);
99            Long inc = getLong(increment);
100            sequence.modify(startValue, min, max, inc);
101        }
102        // need to use the system session, so that the update
103        // can be committed immediately - not committing it
104        // would keep other transactions from using the sequence
105        Session sysSession = db.getSystemSession();
106        synchronized (sysSession) {
107            synchronized (db) {
108                db.updateMeta(sysSession, sequence);
109                sysSession.commit(true);
110            }
111        }
112        return 0;
113    }
114 
115    private Long getLong(Expression expr) {
116        if (expr == null) {
117            return null;
118        }
119        return expr.optimize(session).getValue(session).getLong();
120    }
121 
122    @Override
123    public int getType() {
124        return CommandInterface.ALTER_SEQUENCE;
125    }
126 
127}

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