
org.zoodb.jdo.internal.server.ObjectWriterSV Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parent Show documentation
Show all versions of parent Show documentation
ZooDB Java JDO Object Database.
The newest version!
/*
* Copyright 2009-2013 Tilmann Zaeschke. All rights reserved.
*
* This file is part of ZooDB.
*
* ZooDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZooDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ZooDB. If not, see .
*
* See the README and COPYING files for further information.
*/
package org.zoodb.jdo.internal.server;
import org.zoodb.jdo.internal.ZooClassDef;
import org.zoodb.jdo.internal.server.DiskIO.DATA_TYPE;
import org.zoodb.jdo.internal.server.index.PagedOidIndex;
import org.zoodb.jdo.internal.server.index.PagedPosIndex;
import org.zoodb.jdo.internal.server.index.PagedUniqueLongLong.LLEntry;
import org.zoodb.jdo.internal.server.index.SchemaIndex;
import org.zoodb.jdo.internal.server.index.SchemaIndex.SchemaIndexEntry;
/**
* This class serves as a mediator between the serializer and the file access class.
* Compared to the StorageWrite, the ObjectWriter also provides the following:
* - Updating the oid- and class-index with new object positions.
* - Insert the page header (currently containing only the class-oid).
*
* SV stands for 'server'.
*
* @author Tilmann Zaeschke
*/
public class ObjectWriterSV implements ObjectWriter, CallbackPageWrite {
private final StorageChannelOutput out;
private final PagedOidIndex oidIndex;
private SchemaIndexEntry schemaIndexEntry;
private final SchemaIndex schemaIndex;
private final ZooClassDef def;
private PagedPosIndex posIndex = null;
private int currentPage = -1;
private long currentOffs = -1;
private final long headerForWrite;
public ObjectWriterSV(StorageChannel file, PagedOidIndex oidIndex,
ZooClassDef def, SchemaIndex schemaIndex) {
this.out = file.getWriter(true);
this.oidIndex = oidIndex;
out.setOverflowCallbackWrite(this);
this.def = def;
this.headerForWrite = def.getOid();
this.schemaIndex = schemaIndex;
}
@Override
public void startObject(long oid, int prevSchemaVersion) {
if (posIndex == null) {
if (schemaIndexEntry == null) {
schemaIndexEntry = schemaIndex.getSchema(def);
}
posIndex = schemaIndexEntry.getObjectIndexLatestSchemaVersion();
}
PagedPosIndex prevIndex = schemaIndexEntry.getObjectIndexVersion(prevSchemaVersion);
currentPage = out.getPage();
currentOffs = out.getOffset();
//first remove possible previous position
final LLEntry objPos = oidIndex.findOidGetLong(oid);
if (objPos != null) {
long pos = objPos.getValue(); //long with 32=page + 32=offs
//prevPos.getValue() returns > 0, so the loop is performed at least once.
do {
//remove and report to FSM if applicable
//TODO
//In cache, use separate list for evolved objects to be written (Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy