use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.
the class IdentifierFactoryImplTest method emptyCollectionDocPartRootToIdentifierTest.
@Test
public void emptyCollectionDocPartRootToIdentifierTest() {
ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "", createTableRef());
Assert.assertEquals("", identifier);
}
use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.
the class SnapshotMerger method merge.
private void merge(ImmutableMetaSnapshot.Builder parentBuilder, MutableMetaDatabase newDb, MetaElementState newState) throws UnmergeableException {
ImmutableMetaDatabase byName = oldSnapshot.getMetaDatabaseByName(newDb.getName());
ImmutableMetaDatabase byId = oldSnapshot.getMetaDatabaseByIdentifier(newDb.getIdentifier());
switch(newState) {
default:
case NOT_CHANGED:
case NOT_EXISTENT:
throw new AssertionError("A modification was expected, but the new state is " + newState);
case ADDED:
case MODIFIED:
{
if (byName != byId) {
throw createUnmergeableException(newDb, byName, byId);
}
if (byName == null && byId == null) {
parentBuilder.put(newDb.immutableCopy());
return;
}
assert byName != null;
assert byId != null;
ImmutableMetaDatabase.Builder childBuilder = new ImmutableMetaDatabase.Builder(byId);
for (Tuple2<MutableMetaCollection, MetaElementState> modifiedCollection : newDb.getModifiedCollections()) {
merge(newDb, byId, childBuilder, modifiedCollection.v1(), modifiedCollection.v2());
}
parentBuilder.put(childBuilder);
break;
}
case REMOVED:
{
if (byName != byId) {
/*
* The backend transaction will remove by id, but it is referencing another name on the
* current snapshot, so the final state will be inconsistent. It is better to fail.
*/
throw createUnmergeableException(newDb, byName, byId);
}
if (byName == null && byId == null) {
/*
* it has been removed on another transaction or created and removed on the current one.
* No change must be done
*/
return;
}
assert byName != null;
assert byId != null;
/*
* In this case, we can delegate on the backend transaction check. If it thinks everything
* is fine, we can remove the element. If it thinks there is an error, then we have to
* rollback the transaction.
*/
parentBuilder.remove(byName);
}
}
}
use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.
the class IdentifierFactoryImplTest method longForCounterWithCollisionCharacterDocPartToIdentifierTest.
@Test
public void longForCounterWithCollisionCharacterDocPartToIdentifierTest() {
ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").put(new ImmutableMetaCollection.Builder("collecti", "collecti").put(new ImmutableMetaDocPart.Builder(createTableRef(), "collecti_long_long_long_long_long_long_long_long_long_long_longong_long_long_long_long_long_long_long_long_long_long_long_long_1").build()).build()).build();
String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long"));
Assert.assertEquals("collecti_long_long_long_long_long_long_long_long_long_long_longong_long_long_long_long_long_long_long_long_long_long_long_long_2", identifier);
}
use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.
the class IdentifierFactoryImplTest method docPartArrayInArrayChildToIdentifierTest.
@Test
public void docPartArrayInArrayChildToIdentifierTest() {
ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("array", "2"));
Assert.assertEquals("collecti_array$2", identifier);
}
use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.
the class IdentifierFactoryImplTest method docPartObjectChildToIdentifierTest.
@Test
public void docPartObjectChildToIdentifierTest() {
ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("object"));
Assert.assertEquals("collecti_object", identifier);
}
Aggregations