use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OJDBCExtractor method next.
@Override
public OExtractedItem next() {
try {
if (!didNext) {
if (!rs.next())
throw new NoSuchElementException("[JDBC extractor] previous position was " + current);
}
didNext = false;
final ODocument doc = new ODocument();
for (int i = 0; i < rsColumns; i++) {
// final OType fieldType = columnTypes != null ? columnTypes.get(i) : null;
Object fieldValue = rs.getObject(i + 1);
doc.field(columnNames.get(i), fieldValue);
}
return new OExtractedItem(current++, doc);
} catch (SQLException e) {
throw new OExtractorException("[JDBC extractor] error on moving forward in resultset of query '" + query + "'. Previous position was " + current, e);
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OXmlExtractor method xml2doc.
private Object xml2doc(final Node xmlDocument, final String iPath, final int iLevel) {
final ODocument doc = new ODocument();
Object result = doc;
final NamedNodeMap attrs = xmlDocument.getAttributes();
if (attrs != null)
for (int i = 0; i < attrs.getLength(); ++i) {
final Node item = attrs.item(i);
switch(item.getNodeType()) {
case Node.ATTRIBUTE_NODE:
{
final Attr attr = (Attr) item;
doc.field(attr.getName(), attr.getValue());
break;
}
}
}
final NodeList children = xmlDocument.getChildNodes();
if (children != null) {
for (int i = 0; i < children.getLength(); ++i) {
final Node child = children.item(i);
switch(child.getNodeType()) {
case Node.ELEMENT_NODE:
{
final Element element = (Element) child;
final String path = iPath.isEmpty() ? element.getNodeName() : iPath + "." + element.getNodeName();
if (tagsAsAttribute.contains(iPath)) {
final NodeList subChildren = element.getChildNodes();
if (subChildren.getLength() > 0) {
final Node fieldContent = subChildren.item(0);
doc.field(element.getNodeName(), fieldContent.getTextContent());
}
} else {
final Object sub = xml2doc(element, path, iLevel + 1);
final Object previous = doc.field(element.getNodeName());
if (previous != null) {
List list;
if (previous instanceof List) {
list = (List) previous;
} else {
// TRANSFORM IN A LIST
list = new ArrayList();
list.add(previous);
doc.field(element.getNodeName(), list, OType.EMBEDDEDLIST);
}
list.add(sub);
} else
doc.field(element.getNodeName(), sub, OType.EMBEDDED);
if (rootNode != null && rootNode.startsWith(path))
// SKIP
result = doc.field(element.getNodeName());
}
break;
}
}
}
}
return result;
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class SimulateOperationsAgainstServer method updateDocument.
protected void updateDocument(final int threadId, final int iCycle, final String dbUrl, final String className, final int iSkip) {
final ODatabaseDocumentTx db = getDatabase(dbUrl);
for (int retry = 0; retry < MAX_RETRY; ++retry) {
ODocument doc = null;
try {
List<OIdentifiable> result = db.query(new OSQLSynchQuery<Object>("select from " + className + " skip " + iSkip + " limit 1"));
if (result == null || result.isEmpty())
log(threadId, iCycle, dbUrl, " update no item " + iSkip + " because out of range");
else {
doc = (ODocument) result.get(0);
doc.field("updated", "" + (doc.getVersion() + 1));
doc.save();
log(threadId, iCycle, dbUrl, " updated item " + iSkip + " RID=" + result.get(0));
}
// OK
break;
} catch (OConcurrentModificationException e) {
log(threadId, iCycle, dbUrl, " concurrent update against record " + doc + ", reload it and retry " + retry + "/" + MAX_RETRY + "...");
if (doc != null)
doc.reload(null, true);
} catch (ORecordNotFoundException e) {
log(threadId, iCycle, dbUrl, " update no item " + iSkip + " because not found");
break;
} finally {
db.close();
}
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class SimulateOperationsAgainstServer method createDocument.
protected void createDocument(final int threadId, final int iCycle, final String dbUrl, final String className, final int iProperties) {
final ODatabaseDocumentTx db = getDatabase(dbUrl);
try {
log(threadId, iCycle, dbUrl, " creating document: class=" + className);
ODocument doc = new ODocument(className);
for (int i = 0; i < iProperties; ++i) {
doc.field("prop" + i, "propValue" + i);
}
doc.save();
} finally {
db.close();
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class TestDistributeConfigSerialization method executeTest.
@Override
protected void executeTest() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:target/server0/databases/" + getDatabaseName());
try {
db.setSerializer(new ORecordSerializerSchemaAware2CSV());
db.create();
db.getMetadata().getSchema().createClass("TestMessaging");
db.activateOnCurrentThread();
db.save(new ODocument("TestMessaging").field("test", "test"));
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
try {
db = new ODatabaseDocumentTx("remote:localhost/" + getDatabaseName());
db.open("admin", "admin");
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
}
Aggregations