I attached my test class. It always results with test.trace.db file created 
(somewhere around 7500 iteration).

MM


W dniu wtorek, 26 marca 2013 14:21:15 UTC+1 użytkownik Michał Michalak 
napisał:
>
> Hello
>
> I am using Java with H2 to store serialized objects. Application stores 
> many small data chunks (1kB) but it happens from time to time that data 
> chuck size is quite large (20MB) - rarely but it happens. This is stored in 
> table with int id and blob column for data. I am using H2 version 1.3.170 
> (Maven repository) to start embedded database that uses file on disk.
>
> I noticed that "trace.db" file appears couple of minutes after application 
> start with message:
> pageStore: Transaction log could not be truncated; size: 16 MB
>
> When creating new H2 connection I always set auto commit to true. I also 
> make sure to close statement after each insert and select using Java7 
> autoclose mechanizm try(){}. Is there anything more I could do to avoid 
> this warning. And another question is, does this affect any data stored in 
> database?
>
> Regards
> M.Michalak
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


package ___mm___;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.rowset.serial.SerialBlob;

public class H2TraceFile {
	private static final int FILES_NUMBER = 10000;
	private static final int STRING_SIZE = 10000;
	private static final int STRING_SIZE_BIG = 30000000;
	private static String testString;
	private static String testStringBig;
	static {
		StringBuilder sb = new StringBuilder();
		while (sb.length() < STRING_SIZE) {
			sb.append("hello world!");
		}
		testString = sb.toString();
		while (sb.length() < STRING_SIZE_BIG) {
			sb.append("hello big world!");
		}
		testStringBig = sb.toString();
	}

	public static void main(String[] args) throws Exception {
		new H2TraceFile().startTest();
	}

	private void startTest() throws SQLException, IOException {
		// Make sure there is no old test db file.
		Files.deleteIfExists(new File("test.h2.db").toPath());
		Files.deleteIfExists(new File("test.lock.db").toPath());
		Files.deleteIfExists(new File("test.trace.db").toPath());

		// Create connection.
		try (Connection h2Connection = DriverManager.getConnection("jdbc:h2:test", "sa", "")) {
			h2Connection.setAutoCommit(true);

			// Create new table.
			try (Statement statement = h2Connection.createStatement()) {
				boolean resultCreateTable = statement.execute("CREATE TABLE JOB_DATA (ID BIGINT, DATA IMAGE)");
				if (resultCreateTable) {
					// Should never happen.
					System.out.println("Create table, failed.");
				} else {
					// Create unique marker.
					resultCreateTable = statement.execute("ALTER TABLE JOB_DATA ADD UNIQUE (ID)");
					if (resultCreateTable) {
						System.out.println("Create table, done. Make ID unique, failed.");
					} else {
						System.out.println("Create table, done. Make ID unique, done.");
					}
				}
			}

			// Store data.
			for (int i = 0; i < FILES_NUMBER; i++) {
				boolean isSmall = i % 10 != 0;
				String sqlQuery = "INSERT INTO JOB_DATA VALUES(?, ?)";
				try (PreparedStatement statement = h2Connection.prepareStatement(sqlQuery)) {
					statement.setLong(1, i);
					if (isSmall) {
						statement.setBlob(2, new SerialBlob(testString.getBytes()));
					} else {
						statement.setBlob(2, new SerialBlob(testStringBig.getBytes()));
					}
					int rowsChanged = statement.executeUpdate();
					if (rowsChanged < 1) {
						throw new SQLException("Add data, failure. Nothing inserted.");
					}
				}
				System.out.println("Done: " + i + (isSmall ? "" : " BIG"));
			}
		}
	}
}

Reply via email to