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

COVERAGE SUMMARY FOR SOURCE FILE [RunScriptCommand.java]

nameclass, %method, %block, %line, %
RunScriptCommand.java100% (1/1)83%  (5/6)89%  (101/113)87%  (34/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RunScriptCommand100% (1/1)83%  (5/6)89%  (101/113)87%  (34/39)
queryMeta (): ResultInterface 0%   (0/1)0%   (0/2)0%   (0/1)
execute (String): void 100% (1/1)84%  (26/31)80%  (8/10)
update (): int 100% (1/1)93%  (62/67)91%  (20/22)
RunScriptCommand (Session): void 100% (1/1)100% (7/7)100% (3/3)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setCharset (Charset): 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 java.io.BufferedReader;
9import java.io.IOException;
10import java.io.InputStreamReader;
11import java.nio.charset.Charset;
12import org.h2.command.CommandInterface;
13import org.h2.command.Prepared;
14import org.h2.engine.Constants;
15import org.h2.engine.Session;
16import org.h2.message.DbException;
17import org.h2.result.ResultInterface;
18import org.h2.util.ScriptReader;
19 
20/**
21 * This class represents the statement
22 * RUNSCRIPT
23 */
24public class RunScriptCommand extends ScriptBase {
25 
26    /**
27     * The byte order mark.
28     * 0xfeff because this is the Unicode char
29     * represented by the UTF-8 byte order mark (EF BB BF).
30     */
31    private static final char UTF8_BOM = '\uFEFF';
32 
33    private Charset charset = Constants.UTF8;
34 
35    public RunScriptCommand(Session session) {
36        super(session);
37    }
38 
39    @Override
40    public int update() {
41        session.getUser().checkAdmin();
42        int count = 0;
43        try {
44            openInput();
45            BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset));
46            // if necessary, strip the BOM from the front of the file
47            reader.mark(1);
48            if (reader.read() != UTF8_BOM) {
49                reader.reset();
50            }
51            ScriptReader r = new ScriptReader(reader);
52            while (true) {
53                String sql = r.readStatement();
54                if (sql == null) {
55                    break;
56                }
57                execute(sql);
58                count++;
59                if ((count & 127) == 0) {
60                    checkCanceled();
61                }
62            }
63            reader.close();
64        } catch (IOException e) {
65            throw DbException.convertIOException(e, null);
66        } finally {
67            closeIO();
68        }
69        return count;
70    }
71 
72    private void execute(String sql) {
73        try {
74            Prepared command = session.prepare(sql);
75            if (command.isQuery()) {
76                command.query(0);
77            } else {
78                command.update();
79            }
80            if (session.getAutoCommit()) {
81                session.commit(false);
82            }
83        } catch (DbException e) {
84            throw e.addSQL(sql);
85        }
86    }
87 
88    public void setCharset(Charset charset) {
89        this.charset = charset;
90    }
91 
92    @Override
93    public ResultInterface queryMeta() {
94        return null;
95    }
96 
97    @Override
98    public int getType() {
99        return CommandInterface.RUNSCRIPT;
100    }
101 
102}

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