Skip to content

Commit

Permalink
Fixing #119
Browse files Browse the repository at this point in the history
Not done yet.
  • Loading branch information
rubendel committed Sep 18, 2014
1 parent fa97997 commit 93b30d5
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,57 +38,59 @@ public class NewAttributeChange implements Change {
private final Schema schema;
private int nrFeaturesBefore;

public NewAttributeChange(Schema schema, int nrFeaturesBefore, EAttribute eAttribute) {
this.schema = schema;
this.nrFeaturesBefore = nrFeaturesBefore;
public NewAttributeChange(Schema schema, int nrFeaturesBefore, EAttribute eAttribute) {
this.schema = schema;
this.nrFeaturesBefore = nrFeaturesBefore;
this.eAttribute = eAttribute;
}

@Override

@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
EClass eClass = eAttribute.getEContainingClass();
KeyValueStore keyValueStore = database.getKeyValueStore();
for (EClass subClass : schema.getSubClasses(eClass)) {
try {
try {
// No data migration if the database is new
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());
if (!database.getKeyValueStore().isNew()) {
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());

int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
int nrStartBytesAfter = (int) Math.ceil((nrFeaturesBefore + 1) / 8.0);

byte x = buffer.get();

if (x != nrStartBytesBefore) {
throw new BimserverDatabaseException("Size does not match");
int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
int nrStartBytesAfter = (int) Math.ceil((nrFeaturesBefore + 1) / 8.0);

byte x = buffer.get();

if (x != nrStartBytesBefore) {
throw new BimserverDatabaseException("Size does not match");
}

byte[] unsetted = new byte[nrStartBytesAfter];
buffer.get(unsetted, 0, x);

unsetted[(nrFeaturesBefore) / 8] |= (1 << ((nrFeaturesBefore) % 8));

int extra = 0;

ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
newBuffer.put((byte)nrStartBytesAfter);
newBuffer.put(unsetted);
buffer.position(1 + nrStartBytesBefore);
newBuffer.put(buffer);

keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}

byte[] unsetted = new byte[nrStartBytesAfter];
buffer.get(unsetted, 0, x);

unsetted[(nrFeaturesBefore) / 8] |= (1 << ((nrFeaturesBefore) % 8));

int extra = 0;

ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
newBuffer.put((byte)nrStartBytesAfter);
newBuffer.put(unsetted);
buffer.position(1 + nrStartBytesBefore);
newBuffer.put(buffer);

keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
} catch (Exception e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
}
}
}
}
} catch (BimserverLockConflictException e) {
LOGGER.error("", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,62 @@ public void change(Database database, DatabaseSession databaseSession) throws No
KeyValueStore keyValueStore = database.getKeyValueStore();
for (EClass subClass : schema.getSubClasses(eClass)) {
try {
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());

int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
int nrStartBytesAfter = (int) Math.ceil((nrFeaturesBefore + 1) / 8.0);

byte x = buffer.get();

if (x != nrStartBytesBefore) {
throw new BimserverDatabaseException("Size to not match");
}

byte[] unsetted = new byte[nrStartBytesAfter];
buffer.get(unsetted, 0, x);

if (eReference.isUnsettable()) {
unsetted[(nrFeaturesBefore + 1) / 8] |= (1 << ((nrFeaturesBefore + 1) % 8));
}

int extra = 0;

if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
extra = 4;
} else {
extra = 2;
if (!keyValueStore.isNew()) {
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());

int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
int nrStartBytesAfter = (int) Math.ceil((nrFeaturesBefore + 1) / 8.0);

byte x = buffer.get();

if (x != nrStartBytesBefore) {
throw new BimserverDatabaseException("Size to not match");
}

byte[] unsetted = new byte[nrStartBytesAfter];
buffer.get(unsetted, 0, x);

if (eReference.isUnsettable()) {
unsetted[(nrFeaturesBefore + 1) / 8] |= (1 << ((nrFeaturesBefore + 1) % 8));
}

int extra = 0;

if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
extra = 4;
} else {
extra = 2;
}
}
}

ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
newBuffer.put((byte)nrStartBytesAfter);
newBuffer.put(unsetted);
buffer.position(1 + nrStartBytesBefore);
newBuffer.put(buffer);

if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
newBuffer.putInt(0);
} else {
newBuffer.putShort((short)-1);
ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
newBuffer.put((byte)nrStartBytesAfter);
newBuffer.put(unsetted);
buffer.position(1 + nrStartBytesBefore);
newBuffer.put(buffer);
if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
newBuffer.putInt(0);
} else {
newBuffer.putShort((short)-1);
}
}
}

keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
}
}
}
} catch (BimserverLockConflictException e) {
Expand Down
10 changes: 4 additions & 6 deletions BimServer/src/org/bimserver/database/migrations/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,12 @@ public void upgradeDatabase(Database database, int version, DatabaseSession data
LOGGER.info("Upgrading database to version " + version);
initSubClasses();
for (Change change : changes) {
try {
change.change(database, databaseSession);
} catch (NotImplementedException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
try {
change.change(database, databaseSession);
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
try {
database.setDatabaseVersion(version, databaseSession);
} catch (BimserverLockConflictException e) {
Expand Down
2 changes: 2 additions & 0 deletions Builds/build/bimserver.build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</copy>
<copy todir="builds/BuildJar/config" overwrite="true">
<fileset file="${buildtargets}/shared/IFC2X3_TC1.exp" />
<fileset file="${buildtargets}/shared/IFC4.exp" />
<fileset file="${buildtargets}/shared/version.xml" />
<fileset file="${buildtargets}/shared/web.xml" />
<fileset dir="../../Builds/build/pb">
Expand Down Expand Up @@ -83,6 +84,7 @@
</copy>
<copy todir="builds/BuildWar/WEB-INF" overwrite="true">
<fileset file="${buildtargets}/shared/IFC2X3_TC1.exp" />
<fileset file="${buildtargets}/shared/IFC4.exp" />
<fileset file="${buildtargets}/shared/version.xml" />
<fileset file="${buildtargets}/shared/service.proto" />
<fileset file="${buildtargets}/shared/notification.proto" />
Expand Down
1 change: 1 addition & 0 deletions Builds/build/common.build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</javac>
<copy todir="builds/bimserver/org/bimserver/database/migrations/steps">
<fileset file="../../BimServer/src/org/bimserver/database/migrations/steps/IFC2X3_TC1.ecore"></fileset>
<fileset file="../../BimServer/src/org/bimserver/database/migrations/steps/IFC4.ecore"></fileset>
</copy>
<mkdir dir="builds/bimserver/plugin"/>
<jar destfile="builds/lib/bimserver-${version}.jar">
Expand Down

0 comments on commit 93b30d5

Please sign in to comment.