本文整理汇总了Java中com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.begin方法的典型用法代码示例。如果您正苦于以下问题:Java ODatabaseDocumentTx.begin方法的具体用法?Java ODatabaseDocumentTx.begin怎么用?Java ODatabaseDocumentTx.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
的用法示例。
在下文中一共展示了ODatabaseDocumentTx.begin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initGraph
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
protected void initGraph(OrientGraph g) {
final ODatabaseDocumentTx db = g.getRawDatabase();
boolean txActive = db.getTransaction().isActive();
if (txActive)
// COMMIT TX BEFORE ANY SCHEMA CHANGES
db.commit();
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(OClass.VERTEX_CLASS_NAME))
schema.createClass(OClass.VERTEX_CLASS_NAME).setOverSize(2);
if (!schema.existsClass(OClass.EDGE_CLASS_NAME))
schema.createClass(OClass.EDGE_CLASS_NAME);
if (txActive) {
// REOPEN IT AGAIN
db.begin();
}
}
示例2: populateCaseInsensitiveNameFieldBatch
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
private boolean populateCaseInsensitiveNameFieldBatch(final ODatabaseDocumentTx db) {
log.trace("Processing batch of {} component records...", BATCH_SIZE);
db.begin();
List<ODocument> components = db.query(SELECT_COMPONENT_BATCH);
if (components.isEmpty()) {
return false;
}
for (ODocument component : components) {
String name = component.field(P_NAME, String.class);
component.field(P_CI_NAME, name.toLowerCase(Locale.ENGLISH));
component.save();
}
db.commit();
return true;
}
示例3: testPointTransactionRollBack
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
@Test
public void testPointTransactionRollBack() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:txPoint");
try {
db.create();
OSchema schema = db.getMetadata().getSchema();
OClass v = schema.getClass("V");
OClass oClass = schema.createClass("City");
oClass.setSuperClass(v);
oClass.createProperty("location", OType.EMBEDDED, schema.getClass("OPoint"));
oClass.createProperty("name", OType.STRING);
db.command(new OCommandSQL("CREATE INDEX City.location ON City(location) SPATIAL ENGINE LUCENE")).execute();
OIndex idx = db.getMetadata().getIndexManager().getIndex("City.location");
ODocument rome = newCity("Rome", 12.5, 41.9);
ODocument london = newCity("London", -0.1275, 51.507222);
db.begin();
db.command(new OCommandSQL("insert into City set name = 'Test' , location = ST_GeomFromText('" + PWKT + "')")).execute();
db.save(rome);
db.save(london);
String query = "select * from City where location && 'LINESTRING(-160.06393432617188 21.996535232496047,-160.1099395751953 21.94304553343818,-160.169677734375 21.89399562866819,-160.21087646484375 21.844928843026818,-160.21018981933594 21.787556698550834)' ";
List<ODocument> docs = db.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(1, docs.size());
Assert.assertEquals(3, idx.getSize());
db.rollback();
query = "select * from City where location && 'LINESTRING(-160.06393432617188 21.996535232496047,-160.1099395751953 21.94304553343818,-160.169677734375 21.89399562866819,-160.21087646484375 21.844928843026818,-160.21018981933594 21.787556698550834)' ";
docs = db.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(0, docs.size());
Assert.assertEquals(0, idx.getSize());
} finally {
db.drop();
}
}
示例4: ensureClassExists
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
private void ensureClassExists(final String className) {
ODatabaseDocumentTx db = getGraph();
final OSchemaProxy schema = db.getMetadata().getSchema();
if (!schema.existsClass(className)) {
final boolean wasInTX = db.getTransaction().isActive();
if (wasInTX) {
LOGGER.warn("Warning: premature commit needed to create class {}", className);
saveDirty();
getGraph().commit();
}
/*
* In order to be treated by OrientDB's query layer as a vertex (e.g. the "Graph" viewer
* in the OrientDB Studio), the vertex classes need to have V as a superclass and refer
* to outgoing edges as out_X and incoming edges as in_X. All edge documents must then
* belong to E or a subclass of and use out and in for the source and target of the edge.
*/
final OClass oClass = schema.createClass(className);
if (className.startsWith(VERTEX_TYPE_PREFIX)) {
OClass baseVertexClass = schema.getClass("V");
if (baseVertexClass == null) {
baseVertexClass = schema.createClass("V");
baseVertexClass.setOverSize(2);
}
oClass.addSuperClass(baseVertexClass);
OrientNode.setupDocumentClass(oClass);
} else if (EDGE_TYPE.equals(className)) {
OrientEdge.setupDocumentClass(oClass);
}
if (wasInTX) {
db.begin();
}
}
}
示例5: OrientTransaction
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
public OrientTransaction(OrientDatabase orientDatabase) {
this.graph = orientDatabase;
final ODatabaseDocumentTx db = graph.getGraph();
if (!db.getTransaction().isActive()) {
// OrientDB does not support nested transactions: a begin() will
// *roll back* any transaction that we had from before!
graph.clearPostponedIndexes();
db.begin();
}
}
示例6: testPointTransactionUpdate
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入方法依赖的package包/类
@Test
public void testPointTransactionUpdate() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:txPoint");
try {
db.create();
OSchema schema = db.getMetadata().getSchema();
OClass v = schema.getClass("V");
OClass oClass = schema.createClass("City");
oClass.setSuperClass(v);
oClass.createProperty("location", OType.EMBEDDED, schema.getClass("OPoint"));
oClass.createProperty("name", OType.STRING);
db.command(new OCommandSQL("CREATE INDEX City.location ON City(location) SPATIAL ENGINE LUCENE")).execute();
OIndex idx = db.getMetadata().getIndexManager().getIndex("City.location");
ODocument rome = newCity("Rome", 12.5, 41.9);
db.begin();
db.save(rome);
db.commit();
String query = "select * from City where location && 'LINESTRING(-160.06393432617188 21.996535232496047,-160.1099395751953 21.94304553343818,-160.169677734375 21.89399562866819,-160.21087646484375 21.844928843026818,-160.21018981933594 21.787556698550834)' ";
List<ODocument> docs = db.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(0, docs.size());
Assert.assertEquals(1, idx.getSize());
db.begin();
db.command(new OCommandSQL("update City set location = ST_GeomFromText('" + PWKT + "')")).execute();
query = "select * from City where location && 'LINESTRING(-160.06393432617188 21.996535232496047,-160.1099395751953 21.94304553343818,-160.169677734375 21.89399562866819,-160.21087646484375 21.844928843026818,-160.21018981933594 21.787556698550834)' ";
docs = db.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(1, docs.size());
Assert.assertEquals(1, idx.getSize());
db.commit();
query = "select * from City where location && 'LINESTRING(-160.06393432617188 21.996535232496047,-160.1099395751953 21.94304553343818,-160.169677734375 21.89399562866819,-160.21087646484375 21.844928843026818,-160.21018981933594 21.787556698550834)' ";
docs = db.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(1, docs.size());
Assert.assertEquals(1, idx.getSize());
} finally {
db.drop();
}
}