Created
July 23, 2013 09:23
-
-
Save patrickjmccarty/6061126 to your computer and use it in GitHub Desktop.
This reproduces a bug in OrientDB 1.4.1 involving the exception:
com.orientechnologies.orient.core.exception.ODatabaseException: Error on retrieving record using temporary RecordId: #3:-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.IOException; | |
import java.nio.charset.Charset; | |
import java.nio.file.FileVisitResult; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.nio.file.SimpleFileVisitor; | |
import java.nio.file.attribute.BasicFileAttributes; | |
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | |
import com.orientechnologies.orient.core.id.ORID; | |
import com.orientechnologies.orient.core.record.impl.ODocument; | |
import com.orientechnologies.orient.core.record.impl.ORecordBytes; | |
public class TemporaryRecordIdBugReport | |
{ | |
private static final String DATABASES_FOLDER = "./databases"; | |
private static final String DATABASE_NAME = "TxCopyTest"; | |
private static final Path DATABASE_PATH = Paths.get(DATABASES_FOLDER, DATABASE_NAME); | |
private static final String DATABASE_URL = "local:" + DATABASES_FOLDER + "/" + DATABASE_NAME; | |
public static void main(final String[] args) throws IOException | |
{ | |
if (Files.exists(DATABASE_PATH)) | |
{ | |
deleteDatabase(); | |
} | |
try (ODatabaseDocumentTx database = new ODatabaseDocumentTx(DATABASE_URL)) | |
{ | |
database.create(); | |
System.out.println("Database " + DATABASE_URL + " created."); | |
final ODocument testDoc = new ODocument("Test"); | |
testDoc.save(); | |
database.begin(); | |
try | |
{ | |
final byte[] data = "Test data".getBytes(Charset.forName("UTF-8")); | |
final ORecordBytes chunk = new ORecordBytes(database, data); | |
chunk.save(); | |
//final ORID chunkId = chunk.getIdentity(); // This will commit successfully. | |
final ORID chunkId = chunk.getIdentity().copy(); // This fails to commit with ODatabaseException: Error on retrieving record using temporary RecordId: #3:-2 | |
testDoc.field("MyChunk", chunkId); | |
testDoc.save(); | |
database.commit(); | |
System.out.println("Committed."); | |
} | |
catch (final Exception ex) | |
{ | |
database.rollback(); | |
System.out.println("ROLLBACK!"); | |
ex.printStackTrace(); | |
} | |
} | |
} | |
private static void deleteDatabase() throws IOException | |
{ | |
System.out.println("Deleting Database " + DATABASE_URL); | |
// Delete the database folder directly, because database.drop() requires | |
// the database to be open, which can take a long time if repair is necessary. | |
Files.walkFileTree(DATABASE_PATH, new SimpleFileVisitor<Path>() | |
{ | |
@Override | |
public FileVisitResult visitFile(final Path file, | |
final BasicFileAttributes attrs) | |
throws IOException | |
{ | |
Files.delete(file); | |
return FileVisitResult.CONTINUE; | |
} | |
@Override | |
public FileVisitResult postVisitDirectory(final Path dir, | |
final IOException ex) | |
throws IOException | |
{ | |
if (ex != null) | |
{ | |
throw ex; | |
} | |
Files.delete(dir); | |
return FileVisitResult.CONTINUE; | |
} | |
}); | |
System.out.println("Database " + DATABASE_URL + " deleted."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment