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

COVERAGE SUMMARY FOR SOURCE FILE [CreateIndex.java]

nameclass, %method, %block, %line, %
CreateIndex.java100% (1/1)100% (12/12)97%  (176/181)98%  (48/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateIndex100% (1/1)100% (12/12)97%  (176/181)98%  (48/49)
update (): int 100% (1/1)96%  (133/138)96%  (27/28)
CreateIndex (Session, Schema): void 100% (1/1)100% (5/5)100% (2/2)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setComment (String): void 100% (1/1)100% (4/4)100% (2/2)
setHash (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setIfNotExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setIndexColumns (IndexColumn []): void 100% (1/1)100% (4/4)100% (2/2)
setIndexName (String): void 100% (1/1)100% (4/4)100% (2/2)
setPrimaryKey (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setSpatial (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setTableName (String): void 100% (1/1)100% (4/4)100% (2/2)
setUnique (boolean): 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.Constants;
11import org.h2.engine.Database;
12import org.h2.engine.Right;
13import org.h2.engine.Session;
14import org.h2.index.IndexType;
15import org.h2.message.DbException;
16import org.h2.schema.Schema;
17import org.h2.table.IndexColumn;
18import org.h2.table.Table;
19 
20/**
21 * This class represents the statement
22 * CREATE INDEX
23 */
24public class CreateIndex extends SchemaCommand {
25 
26    private String tableName;
27    private String indexName;
28    private IndexColumn[] indexColumns;
29    private boolean primaryKey, unique, hash, spatial;
30    private boolean ifNotExists;
31    private String comment;
32 
33    public CreateIndex(Session session, Schema schema) {
34        super(session, schema);
35    }
36 
37    public void setIfNotExists(boolean ifNotExists) {
38        this.ifNotExists = ifNotExists;
39    }
40 
41    public void setTableName(String tableName) {
42        this.tableName = tableName;
43    }
44 
45    public void setIndexName(String indexName) {
46        this.indexName = indexName;
47    }
48 
49    public void setIndexColumns(IndexColumn[] columns) {
50        this.indexColumns = columns;
51    }
52 
53    @Override
54    public int update() {
55        if (!transactional) {
56            session.commit(true);
57        }
58        Database db = session.getDatabase();
59        boolean persistent = db.isPersistent();
60        Table table = getSchema().getTableOrView(session, tableName);
61        if (getSchema().findIndex(session, indexName) != null) {
62            if (ifNotExists) {
63                return 0;
64            }
65            throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, indexName);
66        }
67        session.getUser().checkRight(table, Right.ALL);
68        table.lock(session, true, true);
69        if (!table.isPersistIndexes()) {
70            persistent = false;
71        }
72        int id = getObjectId();
73        if (indexName == null) {
74            if (primaryKey) {
75                indexName = table.getSchema().getUniqueIndexName(session,
76                        table, Constants.PREFIX_PRIMARY_KEY);
77            } else {
78                indexName = table.getSchema().getUniqueIndexName(session,
79                        table, Constants.PREFIX_INDEX);
80            }
81        }
82        IndexType indexType;
83        if (primaryKey) {
84            if (table.findPrimaryKey() != null) {
85                throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
86            }
87            indexType = IndexType.createPrimaryKey(persistent, hash);
88        } else if (unique) {
89            indexType = IndexType.createUnique(persistent, hash);
90        } else {
91            indexType = IndexType.createNonUnique(persistent, hash, spatial);
92        }
93        IndexColumn.mapColumns(indexColumns, table);
94        table.addIndex(session, indexName, id, indexColumns, indexType, create,
95                comment);
96        return 0;
97    }
98 
99    public void setPrimaryKey(boolean b) {
100        this.primaryKey = b;
101    }
102 
103    public void setUnique(boolean b) {
104        this.unique = b;
105    }
106 
107    public void setHash(boolean b) {
108        this.hash = b;
109    }
110 
111    public void setSpatial(boolean b) {
112        this.spatial = b;
113    }
114 
115    public void setComment(String comment) {
116        this.comment = comment;
117    }
118 
119    @Override
120    public int getType() {
121        return CommandInterface.CREATE_INDEX;
122    }
123 
124}

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