本文整理汇总了Java中com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx类的典型用法代码示例。如果您正苦于以下问题:Java ODatabaseDocumentTx类的具体用法?Java ODatabaseDocumentTx怎么用?Java ODatabaseDocumentTx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ODatabaseDocumentTx类属于com.orientechnologies.orient.core.db.document包,在下文中一共展示了ODatabaseDocumentTx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJdbc
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Ignore
@Test
public void testJdbc() throws Exception
{
//load Driver
forName(OrientJdbcDriver.class.getName());
String dbUrl = "memory:testdb";
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
createSchemaDB(db);
loadDB(db, 20);
db.create();
Properties info = new Properties();
info.put("user", "admin");
info.put("password", "admin");
orientJdbcConnection = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:" + dbUrl, info);
//create and execute statement
Statement stmt = orientJdbcConnection.createStatement();
int updated = stmt.executeUpdate("INSERT into emplyoee (key, text) values('001', 'satish')");
if (orientJdbcConnection != null && !orientJdbcConnection.isClosed())
{
orientJdbcConnection.close();
}
}
示例2: doPreSetup
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
protected void doPreSetup() throws Exception {
server = OServerMain.create();
server.startup(getClass().getResourceAsStream("db.config.xml"));
server.activate();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DB_URL,false);
db = db.create();
db.command(new OCommandSQL("CREATE CLASS "+TEST_CLASS)).execute();
db.command(new OCommandSQL("CREATE PROPERTY "+TEST_CLASS+"."+TEST_PROPERTY+" STRING")).execute();
db.command(new OCommandSQL("CREATE PROPERTY "+TEST_CLASS+"."+TEST_LINK_PROPERTY+" LINK")).execute();
db.command(new OCommandSQL("CREATE CLASS "+TEST_LINKED_CLASS)).execute();
db.command(new OCommandSQL("CREATE PROPERTY "+TEST_LINKED_CLASS+"."+TEST_PROPERTY+" STRING")).execute();
db.close();
Thread.sleep(1000);
super.doPreSetup();
}
示例3: createSchemaDB
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
private void createSchemaDB(ODatabaseDocumentTx db)
{
OSchema schema = db.getMetadata().getSchema();
// item
OClass item = schema.createClass("Item");
item.createProperty("stringKey", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE);
item.createProperty("intKey", OType.INTEGER).createIndex(OClass.INDEX_TYPE.UNIQUE);
item.createProperty("date", OType.DATE).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("time", OType.DATETIME).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("text", OType.STRING);
item.createProperty("length", OType.LONG).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("published", OType.BOOLEAN).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("title", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("author", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
item.createProperty("tags", OType.EMBEDDEDLIST);
}
示例4: graph
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
/**
* Wraps passed in {@link OrientGraph} handler into {@link ODatabaseDocumentTx} handler.
*/
public static Handler<AsyncResult<ODatabaseDocumentTx>> graph(final Handler<AsyncResult<OrientGraph>> handler) {
Objects.requireNonNull(handler);
return adb -> {
if (adb.failed()) {
handler.handle(Future.failedFuture(adb.cause()));
}
else {
OrientGraph gd = new OrientGraph(adb.result());
try {
handler.handle(Future.succeededFuture(gd));
}
finally {
gd.shutdown();
}
}
};
}
示例5: tx
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
/**
* Wraps passed in handler into a transaction.
*/
public static Handler<ODatabaseDocumentTx> tx(final Handler<ODatabaseDocumentTx> handler)
{
Objects.requireNonNull(handler);
return db -> {
try {
db.begin();
handler.handle(db);
db.commit();
}
catch (Exception e) {
db.rollback();
throw e;
}
};
}
示例6: start
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void start(final Future<Void> startFuture) throws Exception {
consumer = vertx.eventBus().consumer("read",
(Message<JsonObject> m) -> {
documentDatabase.exec(adb -> {
if (adb.failed()) {
log.warn("DB failure", adb.cause());
}
else {
ODatabaseDocumentTx db = adb.result();
List<ODocument> res = db.query(new OSQLSynchQuery<ODocument>("select count(*) as count from test"));
log.info("List size=" + res.get(0).field("count"));
}
});
}
);
super.start(startFuture);
}
示例7: start
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void start(final Future<Void> startFuture) throws Exception {
consumer = vertx.eventBus().consumer("write",
(Message<JsonObject> m) -> {
documentDatabase.exec(adb -> {
if (adb.succeeded()) {
ODatabaseDocumentTx db = adb.result();
JsonObject message = m.body();
db.begin();
ODocument doc = new ODocument("test");
doc.field("name", message.getValue("name"));
doc.field("value", message.getValue("value"));
db.save(doc);
db.commit();
log.info("Written " + message);
}
else {
log.error("Error", adb.cause());
}
}
);
}
);
super.start(startFuture);
}
示例8: insert
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public DocumentDatabaseService insert(final String clazz,
final JsonObject document,
final Handler<AsyncResult<String>> handler)
{
documentDatabase.exec(
ah -> {
if (ah.succeeded()) {
ODatabaseDocumentTx db = ah.result();
db.begin();
ODocument doc = db.newInstance(clazz);
doc.fromJSON(document.toString());
db.save(doc);
db.commit();
handler.handle(Future.succeededFuture(doc.getIdentity().toString()));
}
else {
handler.handle(Future.failedFuture(ah.cause()));
}
}
);
return this;
}
示例9: delete
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public DocumentDatabaseService delete(final String clazz, final String where, final Handler<AsyncResult<Void>> handler) {
documentDatabase.exec(
ah -> {
if (ah.succeeded()) {
ODatabaseDocumentTx db = ah.result();
db.begin();
db.command(new OCommandSQL("delete from " + clazz + " where " + where)).execute();
db.commit();
handler.handle(Future.succeededFuture());
}
else {
handler.handle(Future.failedFuture(ah.cause()));
}
}
);
return this;
}
示例10: initializeData
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void initializeData() {
// Important! method is called without transaction to let implementation control transaction scope and type
// (initializer may even use many (different?) transactions).
// Unit of work must be defined before calling orient api: the simplest way is to use @Transactional
// on class or method
final ODatabaseDocumentTx db = context.getConnection();
if (db.countClass(ManualSchemeInitializer.CLASS_NAME) > 0) {
// perform initialization only in case of empty table
return;
}
// low level api used to insert records, but the same could be done with sql insert commands
for (int i = 0; i < 10; i++) {
final ODocument rec = db.newInstance(ManualSchemeInitializer.CLASS_NAME)
.field("name", "Sample" + i)
.field("amount", (int) (Math.random() * 200));
rec.save();
}
}
示例11: initialize
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void initialize() {
// method is called under unit of work (with NOTX transaction mode,
// because orient "DDL" must be executed in this mode).
final ODatabaseDocumentTx db = context.getConnection();
final OSchema schema = db.getMetadata().getSchema();
// creating class only if it isn't already exists
// this is very naive approach: normally existing class structure must also be
// verified and updated if necessary
if (schema.existsClass(CLASS_NAME)) {
return;
}
final OClass sampleClass = schema.createClass(CLASS_NAME);
sampleClass.createProperty("name", OType.STRING);
sampleClass.createProperty("amount", OType.INTEGER);
}
示例12: restoreGraph
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void restoreGraph(String backupFile) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Running restore using {" + backupFile + "} backup file.");
}
ODatabaseDocumentTx db = factory.getDatabase();
try {
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
};
InputStream in = new FileInputStream(backupFile);
db.restore(in, null, null, listener);
} finally {
db.close();
}
}
示例13: exportGraph
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void exportGraph(String outputDirectory) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Running export to {" + outputDirectory + "} directory.");
}
ODatabaseDocumentTx db = factory.getDatabase();
try {
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
};
String dateString = formatter.format(new Date());
String exportFile = "export_" + dateString;
new File(outputDirectory).mkdirs();
ODatabaseExport export = new ODatabaseExport(db, new File(outputDirectory, exportFile).getAbsolutePath(), listener);
export.exportDatabase();
export.close();
} finally {
db.close();
}
}
示例14: importGraph
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
@Override
public void importGraph(String importFile) throws IOException {
ODatabaseDocumentTx db = factory.getDatabase();
try {
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
};
ODatabaseImport databaseImport = new ODatabaseImport(db, importFile, listener);
databaseImport.importDatabase();
databaseImport.close();
} finally {
db.close();
}
}
示例15: fix
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; //导入依赖的package包/类
public static void fix(MeshOptions options) {
File graphDir = new File(options.getStorageOptions().getDirectory(), "storage");
if (graphDir.exists()) {
log.info("Checking database {" + graphDir + "}");
OrientGraphFactory factory = new OrientGraphFactory("plocal:" + graphDir.getAbsolutePath()).setupPool(5, 100);
try {
// Enable the patched security class
factory.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecuritySharedPatched.class);
ODatabaseDocumentTx tx = factory.getDatabase();
try {
OClass userClass = tx.getMetadata().getSchema().getClass("OUser");
if (userClass == null) {
log.info("OrientDB user credentials not found. Recreating needed roles and users.");
tx.getMetadata().getSecurity().create();
tx.commit();
} else {
log.info("OrientDB user credentials found. Skipping fix.");
}
} finally {
tx.close();
}
} finally {
factory.close();
}
}
}