use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OSchemaShared method doCreateClass.
private OClass doCreateClass(final String className, final int clusters, final int retry, OClass... superClasses) {
OClass result;
final ODatabaseDocumentInternal db = getDatabase();
final OStorage storage = db.getStorage();
StringBuilder cmd = null;
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
if (superClasses != null)
OClassImpl.checkParametersConflict(Arrays.asList(superClasses));
acquireSchemaWriteLock();
try {
final String key = className.toLowerCase();
if (classes.containsKey(key) && retry == 0)
throw new OSchemaException("Class '" + className + "' already exists in current database");
cmd = new StringBuilder("create class ");
// if (getDatabase().getStorage().getConfiguration().isStrictSql())
// cmd.append('`');
cmd.append(className);
// if (getDatabase().getStorage().getConfiguration().isStrictSql())
// cmd.append('`');
List<OClass> superClassesList = new ArrayList<OClass>();
if (superClasses != null && superClasses.length > 0) {
boolean first = true;
for (OClass superClass : superClasses) {
// Filtering for null
if (superClass != null) {
if (first)
cmd.append(" extends ");
else
cmd.append(", ");
cmd.append(superClass.getName());
first = false;
superClassesList.add(superClass);
}
}
}
if (clusters == 0)
cmd.append(" abstract");
else {
cmd.append(" clusters ");
cmd.append(clusters);
}
if (executeThroughDistributedStorage()) {
final int[] clusterIds = createClusters(className, clusters);
createClassInternal(className, clusterIds, superClassesList);
final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
commandSQL.addExcludedNode(autoshardedStorage.getNodeId());
final Object res = db.command(commandSQL).execute();
} else if (storage instanceof OStorageProxy) {
db.command(new OCommandSQL(cmd.toString())).execute();
reload();
} else {
final int[] clusterIds = createClusters(className, clusters);
createClassInternal(className, clusterIds, superClassesList);
}
result = classes.get(className.toLowerCase());
// WAKE UP DB LIFECYCLE LISTENER
for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreateClass(getDatabase(), result);
} catch (ClusterIdsAreEmptyException e) {
throw OException.wrapException(new OSchemaException("Cannot create class '" + className + "'"), e);
} finally {
releaseSchemaWriteLock();
}
return result;
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OSecurityShared method authenticate.
public OUser authenticate(final String iUserName, final String iUserPassword) {
final String dbName = getDatabase().getName();
final OUser user = getUser(iUserName);
if (user == null)
throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");
if (user.getAccountStatus() != OSecurityUser.STATUSES.ACTIVE)
throw new OSecurityAccessException(dbName, "User '" + iUserName + "' is not active");
if (!(getDatabase().getStorage() instanceof OStorageProxy)) {
// CHECK USER & PASSWORD
if (!user.checkPassword(iUserPassword)) {
// WAIT A BIT TO AVOID BRUTE FORCE
try {
Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");
}
}
return user;
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OSBTreeRidBag method serialize.
@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
for (Map.Entry<OIdentifiable, OModifiableInteger> entry : newEntries.entrySet()) {
OIdentifiable identifiable = entry.getKey();
assert identifiable instanceof ORecord;
Change c = changes.get(identifiable);
final int delta = entry.getValue().intValue();
if (c == null)
changes.put(identifiable, new DiffChange(delta));
else
c.applyDiff(delta);
}
newEntries.clear();
final ORecordSerializationContext context;
boolean remoteMode = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy;
if (remoteMode) {
context = null;
} else
context = ORecordSerializationContext.getContext();
// make sure that we really save underlying record.
if (collectionPointer == null) {
if (context != null) {
final int clusterId = getHighLevelDocClusterId();
assert clusterId > -1;
collectionPointer = ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager().createSBTree(clusterId, ownerUuid);
}
}
OBonsaiCollectionPointer collectionPointer;
if (this.collectionPointer != null)
collectionPointer = this.collectionPointer;
else {
collectionPointer = OBonsaiCollectionPointer.INVALID;
}
OLongSerializer.INSTANCE.serializeLiteral(collectionPointer.getFileId(), stream, offset);
offset += OLongSerializer.LONG_SIZE;
OBonsaiBucketPointer rootPointer = collectionPointer.getRootPointer();
OLongSerializer.INSTANCE.serializeLiteral(rootPointer.getPageIndex(), stream, offset);
offset += OLongSerializer.LONG_SIZE;
OIntegerSerializer.INSTANCE.serializeLiteral(rootPointer.getPageOffset(), stream, offset);
offset += OIntegerSerializer.INT_SIZE;
// Keep this section for binary compatibility with versions older then 1.7.5
OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
if (context == null) {
ChangeSerializationHelper.INSTANCE.serializeChanges(changes, OLinkSerializer.INSTANCE, stream, offset);
} else {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
for (Entry<OIdentifiable, Change> change : this.changes.entrySet()) {
OIdentifiable key = change.getKey();
if (db != null && db.getTransaction().isActive()) {
if (!key.getIdentity().isPersistent()) {
OIdentifiable newKey = db.getTransaction().getRecord(key.getIdentity());
if (newKey != null) {
changes.remove(key);
changes.put(newKey, change.getValue());
}
}
}
}
this.collectionPointer = collectionPointer;
context.push(new ORidBagUpdateSerializationOperation(changes, collectionPointer));
// 0-length serialized list of changes
OIntegerSerializer.INSTANCE.serializeLiteral(0, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
}
return offset;
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OPropertyImpl method setName.
public OProperty setName(final String name) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s name %s", getFullNameQuoted(), quoteString(name));
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s name %s", getFullNameQuoted(), quoteString(name));
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setNameInternal(name);
} else
setNameInternal(name);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OPropertyImpl method setLinkedClass.
public OPropertyImpl setLinkedClass(final OClass linkedClass) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
checkSupportLinkedClass(getType());
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s linkedclass `%s`", getFullNameQuoted(), linkedClass);
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s linkedclass `%s`", getFullNameQuoted(), linkedClass);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setLinkedClassInternal(linkedClass);
} else
setLinkedClassInternal(linkedClass);
} finally {
releaseSchemaWriteLock();
}
return this;
}
Aggregations