use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class PrepareTranslation method prepare.
private static void prepare(String baseDir, String path, boolean utf8) throws IOException {
String suffix = utf8 ? ".prop" : ".properties";
File dir = new File(path);
File main = null;
ArrayList<File> translations = new ArrayList<>();
for (File f : dir.listFiles()) {
if (f.getName().endsWith(suffix) && f.getName().indexOf('_') >= 0) {
if (f.getName().endsWith("_" + MAIN_LANGUAGE + suffix)) {
main = f;
} else {
translations.add(f);
}
}
}
SortedProperties p = load(main.getAbsolutePath(), utf8);
Properties base = load(baseDir + "/" + main.getName(), utf8);
store(p, main.getAbsolutePath(), utf8);
for (File trans : translations) {
String language = trans.getName();
language = language.substring(language.lastIndexOf('_') + 1, language.lastIndexOf('.'));
prepare(p, base, trans, utf8);
}
store(p, baseDir + "/" + main.getName(), utf8);
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class PrepareTranslation method prepare.
private static void prepare(Properties main, Properties base, File trans, boolean utf8) throws IOException {
SortedProperties p = load(trans.getAbsolutePath(), utf8);
Properties oldTranslations = new Properties();
for (Object k : base.keySet()) {
String key = (String) k;
String m = base.getProperty(key);
String t = p.getProperty(key);
if (t != null && !t.startsWith("#")) {
oldTranslations.setProperty(m, t);
}
}
HashSet<String> toTranslate = new HashSet<>();
// add missing keys, using # and the value from the main file
for (Object k : main.keySet()) {
String key = (String) k;
String now = main.getProperty(key);
if (!p.containsKey(key)) {
String t = oldTranslations.getProperty(now);
if (t == null) {
// System.out.println(trans.getName() +
// ": key " + key + " not found in " +
// "translation file; added # 'translation'");
t = "#" + now;
p.put(key, t);
} else {
p.put(key, t);
}
} else {
String t = p.getProperty(key);
String last = base.getProperty(key);
if (t.startsWith("#") && !t.startsWith("##")) {
// not translated before
t = oldTranslations.getProperty(now);
if (t == null) {
t = "#" + now;
}
p.put(key, t);
} else if (last != null && !last.equals(now)) {
t = oldTranslations.getProperty(now);
if (t == null) {
// main data changed since the last run: review
// translation
System.out.println(trans.getName() + ": key " + key + " changed, please review; last=" + last + " now=" + now);
String old = p.getProperty(key);
t = "#" + now + " #" + old;
p.put(key, t);
} else {
p.put(key, t);
}
}
}
}
for (String key : toTranslate) {
String now = main.getProperty(key);
String t;
System.out.println(trans.getName() + ": key " + key + " not found in translation file; added dummy # 'translation'");
t = "#" + now;
p.put(key, t);
}
// (deleted or typo in the key)
for (Object k : new ArrayList<>(p.keySet())) {
String key = (String) k;
if (!main.containsKey(key)) {
p.remove(key);
}
}
store(p, trans.getAbsolutePath(), utf8);
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class MVTableEngine method createTable.
@Override
public TableBase createTable(CreateTableData data) {
Database db = data.session.getDatabase();
Store store = init(db);
MVTable table = new MVTable(data, store);
table.init(data.session);
store.tableMap.put(table.getMapName(), table);
return table;
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class MVTableEngine method init.
/**
* Initialize the MVStore.
*
* @param db the database
* @return the store
*/
public static Store init(final Database db) {
Store store = db.getMvStore();
if (store != null) {
return store;
}
byte[] key = db.getFileEncryptionKey();
String dbPath = db.getDatabasePath();
MVStore.Builder builder = new MVStore.Builder();
store = new Store();
boolean encrypted = false;
if (dbPath != null) {
String fileName = dbPath + Constants.SUFFIX_MV_FILE;
MVStoreTool.compactCleanUp(fileName);
builder.fileName(fileName);
builder.pageSplitSize(db.getPageSize());
if (db.isReadOnly()) {
builder.readOnly();
} else {
// possibly create the directory
boolean exists = FileUtils.exists(fileName);
if (exists && !FileUtils.canWrite(fileName)) {
// read only
} else {
String dir = FileUtils.getParent(fileName);
FileUtils.createDirectories(dir);
}
}
if (key != null) {
encrypted = true;
char[] password = new char[key.length / 2];
for (int i = 0; i < password.length; i++) {
password[i] = (char) (((key[i + i] & 255) << 16) | ((key[i + i + 1]) & 255));
}
builder.encryptionKey(password);
}
if (db.getSettings().compressData) {
builder.compress();
// use a larger page split size to improve the compression ratio
builder.pageSplitSize(64 * 1024);
}
builder.backgroundExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
db.setBackgroundException(DbException.convert(e));
}
});
}
store.open(db, builder, encrypted);
db.setMvStore(store);
return store;
}
use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.
the class PageDataOverflow method create.
/**
* Create a new overflow page.
*
* @param store the page store
* @param page the page id
* @param type the page type
* @param parentPageId the parent page id
* @param next the next page or 0
* @param all the data
* @param offset the offset within the data
* @param size the number of bytes
* @return the page
*/
static PageDataOverflow create(PageStore store, int page, int type, int parentPageId, int next, Data all, int offset, int size) {
Data data = store.createData();
PageDataOverflow p = new PageDataOverflow(store, page, data);
store.logUndo(p, null);
data.writeByte((byte) type);
data.writeShortInt(0);
data.writeInt(parentPageId);
if (type == Page.TYPE_DATA_OVERFLOW) {
data.writeInt(next);
} else {
data.writeShortInt(size);
}
p.start = data.length();
data.write(all.getBytes(), offset, size);
p.type = type;
p.parentPageId = parentPageId;
p.nextPage = next;
p.size = size;
return p;
}
Aggregations