private void createSignatureType(OSchema schema) { OClass signatures = schema.createClass("Signatures"); signatures.createProperty(String.valueOf(DocumentAttributes.SHA1), OType.STRING).setNotNull(true); signatures.createIndex("sha1Idx", OClass.INDEX_TYPE.UNIQUE, DocumentAttributes.SHA1.toString()); }
if (!db.getMetadata().getSchema().existsClass(CLASS)) { db.getMetadata().getSchema().createClass(CLASS);
public final void updateSchema() { if (db.isClosed()) { db.create(); } OSchema schema = db.getMetadata().getSchema(); for (String docType : DocumentTypes.getDocumentTypes()) { if (!schema.existsClass(docType)) { createDocType(schema, docType); } } if (!schema.existsClass("Signatures")) { createSignatureType(schema); } }
protected void checkParametersConflict(final OClass baseClass) { final Collection<OProperty> baseClassProperties = baseClass.properties(); for (OProperty property : baseClassProperties) { OProperty thisProperty = getProperty(property.getName()); if (thisProperty != null && !thisProperty.getType().equals(property.getType())) { throw new OSchemaException( "Cannot add base class '" + baseClass.getName() + "', because of property conflict: '" + thisProperty + "' vs '" + property + "'"); } } }
@Override protected void defineType(final OClass type) { type.createProperty(P_USER_ID, OType.STRING) .setNotNull(true); type.createProperty(P_SOURCE, OType.STRING) .setNotNull(true); type.createProperty(P_ROLES, OType.EMBEDDEDSET); type.createIndex(I_USER_ID_SOURCE, INDEX_TYPE.UNIQUE, P_USER_ID, P_SOURCE); }
@Override protected void defineType(final OClass type) { type.createProperty(P_ID, OType.STRING) .setMandatory(true) .setNotNull(true); type.createProperty(P_ALIAS, OType.STRING) .setMandatory(false) .setNotNull(false); }
private static String adjustFieldName(final OClass clazz, final String fieldName) { final OProperty property = clazz.getProperty(fieldName); if (property != null) return property.getName(); else return fieldName; } }
private OType getFieldType(final ODocumentEntry entry) { OType type = entry.type; if (type == null) { final OProperty prop = entry.property; if (prop != null) type = prop.getType(); } if (type == null || OType.ANY == type) type = OType.getTypeByValue(entry.value); return type; }
@Override public void getIndexes(final Collection<OIndex<?>> indexes) { acquireSchemaReadLock(); try { getClassIndexes(indexes); for (OClass superClass : superClasses) { superClass.getIndexes(indexes); } } finally { releaseSchemaReadLock(); } }
@Override public void getIndexes(final Collection<OIndex<?>> indexes) { initSuperClasses(); getClassIndexes(indexes); for (OClass superClass : superClasses) { superClass.getIndexes(indexes); } }
public String getFullNameQuoted() { acquireSchemaReadLock(); try { return "`" + owner.getName() + "`.`" + globalRef.getName() + "`"; } finally { releaseSchemaReadLock(); } }
@Override public OIndex<?> createIndex(String iType, ODocument metadata) { acquireSchemaReadLock(); try { return owner.createIndex(getFullName(), iType, null, metadata, new String[] { globalRef.getName() }); } finally { releaseSchemaReadLock(); } }
/** * @deprecated Use {@link OClass#getInvolvedIndexes(String...)} instead. */ @Deprecated public Set<OIndex<?>> getIndexes() { acquireSchemaReadLock(); try { return owner.getInvolvedIndexes(globalRef.getName()); } finally { releaseSchemaReadLock(); } }
public String getName() { acquireSchemaReadLock(); try { return globalRef.getName(); } finally { releaseSchemaReadLock(); } }
public OType getType() { acquireSchemaReadLock(); try { return globalRef.getType(); } finally { releaseSchemaReadLock(); } }
private void createDocType(final OSchema schema, final String docType) { logger.debug("Create document class '{}'", docType); OClass page = schema.createClass(docType); // Primary key String attribName = DocumentAttributes.SOURCE_URI.toString(); page.createProperty(attribName, OType.STRING).setNotNull(true); page.createIndex(docType + "sourceUriIndex", OClass.INDEX_TYPE.UNIQUE, attribName); attribName = DocumentAttributes.SHA1.toString(); page.createProperty(attribName, OType.STRING).setNotNull(true); page.createIndex(docType + "sha1Index", OClass.INDEX_TYPE.NOTUNIQUE, attribName); attribName = DocumentAttributes.CACHED.toString(); page.createProperty(attribName, OType.BOOLEAN).setNotNull(true); page.createIndex(docType + "cachedIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName); attribName = DocumentAttributes.RENDERED.toString(); page.createProperty(attribName, OType.BOOLEAN).setNotNull(true); page.createIndex(docType + "renderedIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName); attribName = DocumentAttributes.STATUS.toString(); page.createProperty(attribName, OType.STRING).setNotNull(true); page.createIndex(docType + "statusIndex", OClass.INDEX_TYPE.NOTUNIQUE, attribName); }
@Override protected void defineType(final OClass type) { type.createProperty(P_NAME, OType.STRING).setNotNull(true); type.createProperty(P_TYPE, OType.STRING).setNotNull(true); type.createProperty(P_CONTENT, OType.STRING).setNotNull(true); //ensure name is unique as it serves as the ID for a script type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); }
public String getFullName() { acquireSchemaReadLock(); try { return owner.getName() + "." + globalRef.getName(); } finally { releaseSchemaReadLock(); } }