本文整理汇总了Java中com.orientechnologies.orient.core.sql.OCommandSQL类的典型用法代码示例。如果您正苦于以下问题:Java OCommandSQL类的具体用法?Java OCommandSQL怎么用?Java OCommandSQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OCommandSQL类属于com.orientechnologies.orient.core.sql包,在下文中一共展示了OCommandSQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPreSetup
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的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();
}
示例2: query
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
/**
* Ejecuta un comando que devuelve un número. El valor devuelto será el primero que se encuentre en la lista de resultado.
*
* @param sql comando a ejecutar
* @param retVal nombre de la propiedad a devolver
* @return retorna el valor de la propiedad indacada obtenida de la ejecución de la consulta
*
* ejemplo: int size = sm.query("select count(*) as size from TestData","size");
*/
@Override
public long query(String sql, String retVal) {
if (this.orientdbTransact == null) {
throw new NoOpenTx();
}
this.flush();
OCommandSQL osql = new OCommandSQL(sql);
OrientVertex ov = (OrientVertex) ((OrientDynaElementIterable) this.orientdbTransact.command(osql).execute()).iterator().next();
if (retVal == null) {
retVal = ov.getProperties().keySet().iterator().next();
}
return ov.getProperty(retVal);
}
示例3: getVertices
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
private <V extends ODBVertex> Iterable<S> getVertices() throws IllegalAccessException, InstantiationException {
// Object ret = orientGraph.command(new OCommandGremlin("g.v('9:68128').both().both()")).execute();
String oSqlCommand = "SELECT * FROM " + vertexType.getSimpleName();
Object ret = graph().command(new OCommandSQL(oSqlCommand)).execute();
// List<V> res = new ArrayList<>();
List<S> models = new ArrayList<>();
for (OrientVertex vertex : (Iterable<OrientVertex>) ret) {
V modelVert = (V) vertexType.newInstance();
modelVert.load(vertex.getRecord());
models.add((S) modelVert.model());
}
return models;
}
示例4: delete
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的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;
}
示例5: testEdgeIndexViaQuery
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
@Test
public void testEdgeIndexViaQuery() throws Exception {
OrientGraph g = factory.getTx();
try {
System.out.println("Checking edge");
long start = System.currentTimeMillis();
for (int i = 0; i < nChecks; i++) {
OrientVertex randomDocument = items.get((int) (Math.random() * items.size()));
OCommandSQL cmd = new OCommandSQL("select from index:e.has_item where key=?");
OCompositeKey key = new OCompositeKey(root.getId(), randomDocument.getId());
assertTrue(((Iterable<Vertex>) g.command(cmd).execute(key)).iterator().hasNext());
}
long dur = System.currentTimeMillis() - start;
System.out.println("[query] Duration: " + dur);
System.out.println("[query] Duration per lookup: " + ((double) dur / (double) nChecks));
} finally {
g.shutdown();
}
}
示例6: updateInfo
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
@Override
public Account updateInfo(Account account) {
metrics.meter(ACCOUNT_UPDATE_INFO_METRIC).mark();
try (OObjectDatabaseTx db = db()) {
int i;
try {
i = db.command(new OCommandSQL(String.format(UPDATE_INFO_COMMAND, account.id().toString(),
account.username(), account.email(), account.firstName(), account.lastName(),
account.passHash()))).execute();
} catch (Throwable t) {
throw Exceptions.runtime(t);
}
if (i != 1) {
throw new IllegalArgumentException(String.format("Can't update account %s with data %s", account.id(), account));
}
return account;
}
}
示例7: executeTx
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
protected void executeTx(String cmd) {
try (OObjectDatabaseTx db = db()) {
db.begin();
int i;
try {
i = db.command(new OCommandSQL(cmd)).execute();
} catch (Throwable t) {
db.rollback();
throw Exceptions.runtime(t);
}
if (i != 1) {
db.rollback();
throw new IllegalArgumentException(String.format("Command [%s] didn't affected any record!", cmd));
}
db.commit();
}
}
示例8: getCount
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
public long getCount(final ODatabaseDocumentTx db, final String repositoryName, final String assetName) {
checkNotNull(db);
checkNotNull(repositoryName);
checkNotNull(assetName);
Map<String, Object> parameters = buildQueryParameters(repositoryName, assetName, DateType.DAY, null, null);
Iterable<ODocument> docs = db.command(new OCommandSQL(TOTAL_COUNT_QUERY)).execute(parameters);
ODocument result = Iterables.getFirst(docs, null);
if (result != null) {
return result.field("sum", OType.LONG);
}
return 0;
}
示例9: incrementCount
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
private void incrementCount(final ODatabaseDocumentTx db,
final String repositoryName,
final String assetName,
final String nodeId,
final DateType dateType,
final DateTime date,
final long count)
{
Map<String, Object> parameters = buildQueryParameters(repositoryName, assetName, dateType, date, nodeId);
String query = String.format("update %s increment count = %s where %s = :nodeId and %s = :repositoryName "
+ "and %s = :assetName and %s = :dateType and %s = :date", DB_CLASS, count, P_NODE_ID, P_REPOSITORY_NAME,
P_ASSET_NAME, P_DATE_TYPE, P_DATE);
Integer updateCount = db.command(new OCommandSQL(query)).execute(parameters);
if (updateCount < 1) {
addEntity(db, newEntity().withRepositoryName(repositoryName).withAssetName(assetName).withNodeId(nodeId)
.withDateType(dateType).withDate(new DateTime(dateType.standardizeDate(date))).withCount(count));
}
}
示例10: findByProperty
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
Asset findByProperty(final ODatabaseDocumentTx db,
final String propName,
final Object propValue,
final Component component)
{
checkNotNull(propName);
checkNotNull(propValue);
checkNotNull(component);
Map<String, Object> parameters = ImmutableMap.of(
"bucket", bucketEntityAdapter.recordIdentity(component.bucketId()),
"component", componentEntityAdapter.recordIdentity(component),
"propValue", propValue
);
String query = String.format(
"select from %s where %s = :bucket and %s = :component and %s = :propValue",
DB_CLASS, P_BUCKET, P_COMPONENT, propName
);
Iterable<ODocument> docs = db.command(new OCommandSQL(query)).execute(parameters);
ODocument first = Iterables.getFirst(docs, null);
return first != null ? readEntity(first) : null;
}
示例11: deleteComponentNode
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
/**
* Removes any {@link BrowseNode}s associated with the given component id.
*/
public void deleteComponentNode(final ODatabaseDocumentTx db, final EntityId componentId) {
// some formats have the same component appearing on different branches of the tree
Iterable<ODocument> documents =
db.command(new OCommandSQL(FIND_BY_COMPONENT)).execute(
ImmutableMap.of(P_COMPONENT_ID, recordIdentity(componentId)));
documents.forEach(document -> {
if (document.containsField(P_ASSET_ID)) {
// asset still exists, just remove component details
document.removeField(P_COMPONENT_ID);
document.save();
}
else {
document.delete();
}
});
}
示例12: deleteAssetNode
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
/**
* Removes the {@link BrowseNode} associated with the given asset id.
*/
public void deleteAssetNode(final ODatabaseDocumentTx db, final EntityId assetId) {
// a given asset will only appear once in the tree
ODocument document = getFirst(
db.command(new OCommandSQL(FIND_BY_ASSET)).execute(
ImmutableMap.of(P_ASSET_ID, recordIdentity(assetId))), null);
if (document != null) {
if (document.containsField(P_COMPONENT_ID)) {
// component still exists, just remove asset details
document.removeField(P_ASSET_ID);
document.removeField(P_ASSET_NAME_LOWERCASE);
document.save();
}
else {
document.delete();
}
}
}
示例13: buildQuery
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
/**
* Builds a visible node query from the primary select clause, optional asset filter, and limit.
*
* Optionally include nodes which don't have assets (regardless of the filter) to allow their
* component details to be used in the final listing when they overlap with visible subtrees.
*/
private static OCommandSQL buildQuery(final String select,
final boolean includeNonAssetNodes,
final String assetFilter,
final int limit)
{
StringBuilder buf = new StringBuilder(select);
if (!assetFilter.isEmpty()) {
buf.append(" and (").append(P_ASSET_ID);
if (includeNonAssetNodes) {
buf.append(" is null or ");
}
else {
buf.append(" is not null and ");
}
buf.append(assetFilter).append(')');
}
buf.append(" limit ").append(limit);
return new OCommandSQL(buf.toString());
}
示例14: browseByNameCaseInsensitive
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
public Iterable<Component> browseByNameCaseInsensitive(final ODatabaseDocumentTx db,
final String name,
@Nullable final Iterable<Bucket> buckets,
@Nullable final String querySuffix)
{
checkNotNull(name);
String whereClause = " where (ci_name = :name)";
StringBuilder query = new StringBuilder("select from " + DB_CLASS + whereClause);
addBucketConstraints(whereClause, buckets, query);
if (querySuffix != null) {
query.append(' ').append(querySuffix);
}
Map<String, Object> parameters = ImmutableMap.of("name", name);
log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters);
return transform(db.command(new OCommandSQL(query.toString())).execute(parameters));
}
示例15: findByProperty
import com.orientechnologies.orient.core.sql.OCommandSQL; //导入依赖的package包/类
T findByProperty(final ODatabaseDocumentTx db,
final String propName, final Object propValue,
final Bucket bucket)
{
checkNotNull(propName);
checkNotNull(propValue);
checkNotNull(bucket);
Map<String, Object> parameters = ImmutableMap.of(
P_BUCKET, bucketEntityAdapter.recordIdentity(bucket),
"propValue", propValue
);
String query = String.format(
"select from %s where %s = :bucket and %s = :propValue",
getTypeName(), P_BUCKET, propName
);
Iterable<ODocument> docs = db.command(new OCommandSQL(query)).execute(parameters);
ODocument first = Iterables.getFirst(docs, null);
return first != null ? readEntity(first) : null;
}