use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class ODocument method getImmutableSchemaClass.
protected OImmutableClass getImmutableSchemaClass() {
if (_immutableClazz == null) {
if (_className == null)
fetchClassName();
final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
if (databaseRecord != null && !databaseRecord.isClosed()) {
final OSchema immutableSchema = ((OMetadataInternal) databaseRecord.getMetadata()).getImmutableSchemaSnapshot();
if (immutableSchema == null)
return null;
_immutableSchemaVersion = immutableSchema.getVersion();
_immutableClazz = (OImmutableClass) immutableSchema.getClass(_className);
}
}
return _immutableClazz;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class ODocument method reset.
/**
* <p>
* Resets the record values and class type to being reused. It's like you create a ODocument from scratch. This method is handy
* when you want to insert a bunch of documents and don't want to strain GC.
* </p>
* <p/>
* <p>
* The following code will create a new document in database.
* </p>
* <code>
* doc.clear();
* doc.save();
* </code>
* <p/>
* <p>
* IMPORTANT! This can be used only if no transactions are begun.
* </p>
*
* @return this
* @throws IllegalStateException if transaction is begun.
* @see #clear()
*/
@Override
public ODocument reset() {
ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null && db.getTransaction().isActive())
throw new IllegalStateException("Cannot reset documents during a transaction. Create a new one each time");
super.reset();
_className = null;
_immutableClazz = null;
_immutableSchemaVersion = -1;
internalReset();
_owners = null;
return this;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class ODocument method setClassName.
public void setClassName(final String className) {
_immutableClazz = null;
_immutableSchemaVersion = -1;
_className = className;
if (className == null) {
return;
}
final ODatabaseDocument db = getDatabaseIfDefined();
if (db != null) {
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
this._immutableClazz = (OImmutableClass) metadata.getImmutableSchemaSnapshot().getClass(className);
OClass clazz;
if (this._immutableClazz != null) {
clazz = this._immutableClazz;
} else {
clazz = metadata.getSchema().getOrCreateClass(className);
}
if (clazz != null) {
_className = clazz.getName();
convertFieldsToClass(clazz);
}
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OFunctionLibraryImpl method init.
protected void init() {
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
if (db.getMetadata().getSchema().existsClass("OFunction")) {
final OClass f = db.getMetadata().getSchema().getClass("OFunction");
OProperty prop = f.getProperty("name");
if (prop.getAllIndexes().isEmpty())
prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
return;
}
final OClass f = db.getMetadata().getSchema().createClass("OFunction");
OProperty prop = f.createProperty("name", OType.STRING, (OType) null, true);
prop.set(OProperty.ATTRIBUTES.NOTNULL, true);
prop.set(OProperty.ATTRIBUTES.MANDATORY, true);
prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
f.createProperty("code", OType.STRING, (OType) null, true);
f.createProperty("language", OType.STRING, (OType) null, true);
f.createProperty("idempotent", OType.BOOLEAN, (OType) null, true);
f.createProperty("parameters", OType.EMBEDDEDLIST, OType.STRING, true);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OFunctionLibraryImpl method load.
public void load() {
// COPY CALLBACK IN RAM
final Map<String, OCallable<Object, Map<Object, Object>>> callbacks = new HashMap<String, OCallable<Object, Map<Object, Object>>>();
for (Map.Entry<String, OFunction> entry : functions.entrySet()) {
if (entry.getValue().getCallback() != null)
callbacks.put(entry.getKey(), entry.getValue().getCallback());
}
functions.clear();
// LOAD ALL THE FUNCTIONS IN MEMORY
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().existsClass("OFunction")) {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from OFunction order by name"));
for (ODocument d : result) {
d.reload();
final OFunction f = new OFunction(d);
// RESTORE CALLBACK IF ANY
f.setCallback(callbacks.get(f.getName()));
functions.put(d.field("name").toString().toUpperCase(), f);
}
}
}
Aggregations