Search in sources :

Example 11 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class WebServer method readTranslations.

/**
 * Read the translation for this language and save them in the 'text'
 * property of this session.
 *
 * @param session the session
 * @param language the language
 */
void readTranslations(WebSession session, String language) {
    Properties text = new Properties();
    try {
        trace("translation: " + language);
        byte[] trans = getFile("_text_" + language + ".prop");
        trace("  " + new String(trans));
        text = SortedProperties.fromLines(new String(trans, StandardCharsets.UTF_8));
        // remove starting # (if not translated yet)
        for (Entry<Object, Object> entry : text.entrySet()) {
            String value = (String) entry.getValue();
            if (value.startsWith("#")) {
                entry.setValue(value.substring(1));
            }
        }
    } catch (IOException e) {
        DbException.traceThrowable(e);
    }
    session.put("text", new HashMap<>(text));
}
Also used : IOException(java.io.IOException) SortedProperties(org.h2.util.SortedProperties) SysProperties(org.h2.engine.SysProperties) Properties(java.util.Properties)

Example 12 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class WebServer method init.

@Override
public void init(String... args) {
    // set the serverPropertiesDir, because it's used in loadProperties()
    for (int i = 0; args != null && i < args.length; i++) {
        if ("-properties".equals(args[i])) {
            serverPropertiesDir = args[++i];
        }
    }
    Properties prop = loadProperties();
    port = SortedProperties.getIntProperty(prop, "webPort", Constants.DEFAULT_HTTP_PORT);
    ssl = SortedProperties.getBooleanProperty(prop, "webSSL", false);
    allowOthers = SortedProperties.getBooleanProperty(prop, "webAllowOthers", false);
    commandHistoryString = prop.getProperty(COMMAND_HISTORY);
    for (int i = 0; args != null && i < args.length; i++) {
        String a = args[i];
        if (Tool.isOption(a, "-webPort")) {
            port = Integer.decode(args[++i]);
        } else if (Tool.isOption(a, "-webSSL")) {
            ssl = true;
        } else if (Tool.isOption(a, "-webAllowOthers")) {
            allowOthers = true;
        } else if (Tool.isOption(a, "-webDaemon")) {
            isDaemon = true;
        } else if (Tool.isOption(a, "-baseDir")) {
            String baseDir = args[++i];
            SysProperties.setBaseDir(baseDir);
        } else if (Tool.isOption(a, "-ifExists")) {
            ifExists = true;
        } else if (Tool.isOption(a, "-properties")) {
            // already set
            i++;
        } else if (Tool.isOption(a, "-trace")) {
            trace = true;
        }
    }
    // }
    for (String[] lang : LANGUAGES) {
        languages.add(lang[0]);
    }
    updateURL();
}
Also used : SortedProperties(org.h2.util.SortedProperties) SysProperties(org.h2.engine.SysProperties) Properties(java.util.Properties)

Example 13 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class PgServer method listen.

@Override
public void listen() {
    String threadName = Thread.currentThread().getName();
    try {
        while (!stop) {
            Socket s = serverSocket.accept();
            if (!allow(s)) {
                trace("Connection not allowed");
                s.close();
            } else {
                PgServerThread c = new PgServerThread(s, this);
                running.add(c);
                c.setProcessId(pid.incrementAndGet());
                Thread thread = new Thread(c, threadName + " thread");
                thread.setDaemon(isDaemon);
                c.setThread(thread);
                thread.start();
            }
        }
    } catch (Exception e) {
        if (!stop) {
            e.printStackTrace();
        }
    }
}
Also used : Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) DbException(org.h2.message.DbException) UnknownHostException(java.net.UnknownHostException) SQLException(java.sql.SQLException)

Example 14 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestTraceSystem method testAdapter.

private void testAdapter() {
    TraceSystem ts = new TraceSystem(null);
    ts.setName("test");
    ts.setLevelFile(TraceSystem.ADAPTER);
    ts.getTrace("test").debug("test");
    ts.getTrace("test").info("test");
    ts.getTrace("test").error(new Exception(), "test");
    // The used SLF4J-nop logger has all log levels disabled,
    // so this should be reflected in the trace system.
    assertFalse(ts.isEnabled(TraceSystem.INFO));
    assertFalse(ts.getTrace("test").isInfoEnabled());
    ts.close();
}
Also used : TraceSystem(org.h2.message.TraceSystem)

Example 15 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestValueMemory method testType.

private void testType(int type) throws SQLException {
    System.gc();
    System.gc();
    long first = Utils.getMemoryUsed();
    ArrayList<Value> list = new ArrayList<>();
    long memory = 0;
    while (memory < 1000000) {
        Value v = create(type);
        memory += v.getMemory() + Constants.MEMORY_POINTER;
        list.add(v);
    }
    Object[] array = list.toArray();
    IdentityHashMap<Object, Object> map = new IdentityHashMap<>();
    for (Object a : array) {
        map.put(a, a);
    }
    int size = map.size();
    map.clear();
    map = null;
    list = null;
    System.gc();
    System.gc();
    long used = Utils.getMemoryUsed() - first;
    memory /= 1024;
    if (config.traceTest || used > memory * 3) {
        String msg = "Type: " + type + " Used memory: " + used + " calculated: " + memory + " length: " + array.length + " size: " + size;
        if (config.traceTest) {
            trace(msg);
        }
        if (used > memory * 3) {
            fail(msg);
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) Value(org.h2.value.Value) ArrayList(java.util.ArrayList) ValueJavaObject(org.h2.value.ValueJavaObject) ValueString(org.h2.value.ValueString) MemoryFootprint(org.h2.test.utils.MemoryFootprint)

Aggregations

SQLException (java.sql.SQLException)16 DbException (org.h2.message.DbException)14 Connection (java.sql.Connection)11 ResultSet (java.sql.ResultSet)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)8 IOException (java.io.IOException)7 Savepoint (java.sql.Savepoint)7 Random (java.util.Random)7 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TraceSystem (org.h2.message.TraceSystem)5 Server (org.h2.tools.Server)5 ValueString (org.h2.value.ValueString)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 SysProperties (org.h2.engine.SysProperties)4 JdbcConnection (org.h2.jdbc.JdbcConnection)4 SortedProperties (org.h2.util.SortedProperties)4 Value (org.h2.value.Value)4 Socket (java.net.Socket)3