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

COVERAGE SUMMARY FOR SOURCE FILE [MetaRecord.java]

nameclass, %method, %block, %line, %
MetaRecord.java100% (1/1)90%  (9/10)70%  (135/194)83%  (44/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MetaRecord100% (1/1)90%  (9/10)70%  (135/194)83%  (44/53)
toString (): String 0%   (0/1)0%   (0/22)0%   (0/1)
execute (Database, Session, DatabaseEventListener): void 100% (1/1)35%  (14/40)42%  (5/12)
getCreateOrder (): int 100% (1/1)75%  (33/44)94%  (16/17)
MetaRecord (DbObject): void 100% (1/1)100% (15/15)100% (5/5)
MetaRecord (SearchRow): void 100% (1/1)100% (21/21)100% (5/5)
compareTo (MetaRecord): int 100% (1/1)100% (19/19)100% (5/5)
getId (): int 100% (1/1)100% (3/3)100% (1/1)
getObjectType (): int 100% (1/1)100% (3/3)100% (1/1)
getSQL (): String 100% (1/1)100% (3/3)100% (1/1)
setRecord (SearchRow): void 100% (1/1)100% (24/24)100% (5/5)

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.engine;
7 
8import java.sql.SQLException;
9import org.h2.api.DatabaseEventListener;
10import org.h2.command.Prepared;
11import org.h2.message.DbException;
12import org.h2.message.Trace;
13import org.h2.result.SearchRow;
14import org.h2.value.ValueInt;
15import org.h2.value.ValueString;
16 
17/**
18 * A record in the system table of the database.
19 * It contains the SQL statement to create the database object.
20 */
21public class MetaRecord implements Comparable<MetaRecord> {
22 
23    private final int id;
24    private final int objectType;
25    private final String sql;
26 
27    public MetaRecord(SearchRow r) {
28        id = r.getValue(0).getInt();
29        objectType = r.getValue(2).getInt();
30        sql = r.getValue(3).getString();
31    }
32 
33    MetaRecord(DbObject obj) {
34        id = obj.getId();
35        objectType = obj.getType();
36        sql = obj.getCreateSQL();
37    }
38 
39    void setRecord(SearchRow r) {
40        r.setValue(0, ValueInt.get(id));
41        r.setValue(1, ValueInt.get(0));
42        r.setValue(2, ValueInt.get(objectType));
43        r.setValue(3, ValueString.get(sql));
44    }
45 
46    /**
47     * Execute the meta data statement.
48     *
49     * @param db the database
50     * @param systemSession the system session
51     * @param listener the database event listener
52     */
53    void execute(Database db, Session systemSession,
54            DatabaseEventListener listener) {
55        try {
56            Prepared command = systemSession.prepare(sql);
57            command.setObjectId(id);
58            command.update();
59        } catch (DbException e) {
60            e = e.addSQL(sql);
61            SQLException s = e.getSQLException();
62            db.getTrace(Trace.DATABASE).error(s, sql);
63            if (listener != null) {
64                listener.exceptionThrown(s, sql);
65                // continue startup in this case
66            } else {
67                throw e;
68            }
69        }
70    }
71 
72    public int getId() {
73        return id;
74    }
75 
76    public int getObjectType() {
77        return objectType;
78    }
79 
80    public String getSQL() {
81        return sql;
82    }
83 
84    /**
85     * Sort the list of meta records by 'create order'.
86     *
87     * @param other the other record
88     * @return -1, 0, or 1
89     */
90    @Override
91    public int compareTo(MetaRecord other) {
92        int c1 = getCreateOrder();
93        int c2 = other.getCreateOrder();
94        if (c1 != c2) {
95            return c1 - c2;
96        }
97        return getId() - other.getId();
98    }
99 
100    /**
101     * Get the sort order id for this object type. Objects are created in this
102     * order when opening a database.
103     *
104     * @return the sort index
105     */
106    private int getCreateOrder() {
107        switch(objectType) {
108        case DbObject.SETTING:
109            return 0;
110        case DbObject.USER:
111            return 1;
112        case DbObject.SCHEMA:
113            return 2;
114        case DbObject.FUNCTION_ALIAS:
115            return 3;
116        case DbObject.USER_DATATYPE:
117            return 4;
118        case DbObject.SEQUENCE:
119            return 5;
120        case DbObject.CONSTANT:
121            return 6;
122        case DbObject.TABLE_OR_VIEW:
123            return 7;
124        case DbObject.INDEX:
125            return 8;
126        case DbObject.CONSTRAINT:
127            return 9;
128        case DbObject.TRIGGER:
129            return 10;
130        case DbObject.ROLE:
131            return 11;
132        case DbObject.RIGHT:
133            return 12;
134        case DbObject.AGGREGATE:
135            return 13;
136        case DbObject.COMMENT:
137            return 14;
138        default:
139            throw DbException.throwInternalError("type="+objectType);
140        }
141    }
142 
143    @Override
144    public String toString() {
145        return "MetaRecord [id=" + id + ", objectType=" + objectType +
146                ", sql=" + sql + "]";
147    }
148 
149}

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