Examples of ODatabaseRecordInternal


Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final ODatabaseRecordInternal database = getDatabase();
    database.checkSecurity(ODatabaseSecurityResources.DATABASE, ORole.PERMISSION_UPDATE);

    database.setInternal(attribute, value);
    return null;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (destField == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final ODatabaseRecordInternal database = getDatabase();
    if (!(database.getDatabaseOwner() instanceof ODatabaseDocumentTx))
      throw new OCommandSQLParsingException("This command supports only the database type ODatabaseDocumentTx and type '"
          + database.getClass() + "' was found");

    final ODatabaseDocumentTx db = (ODatabaseDocumentTx) database.getDatabaseOwner();

    final OClass sourceClass = database.getMetadata().getSchema().getClass(sourceClassName);
    if (sourceClass == null)
      throw new OCommandExecutionException("Source class '" + sourceClassName + "' not found");

    final OClass destClass = database.getMetadata().getSchema().getClass(destClassName);
    if (destClass == null)
      throw new OCommandExecutionException("Destination class '" + destClassName + "' not found");

    Object value;

    String cmd = "select from ";
    if (!ODocumentHelper.ATTRIBUTE_RID.equals(destField)) {
      cmd = "select from " + destClassName + " where " + destField + " = ";
    }

    List<ODocument> result;
    ODocument target;
    Object oldValue;
    long total = 0;

    if (linkName == null)
      // NO LINK NAME EXPRESSED: OVERWRITE THE SOURCE FIELD
      linkName = sourceField;

    boolean multipleRelationship;
    if (linkType != null)
      // DETERMINE BASED ON FORCED TYPE
      multipleRelationship = linkType == OType.LINKSET || linkType == OType.LINKLIST;
    else
      multipleRelationship = false;

    long totRecords = db.countClass(sourceClass.getName());
    long currRecord = 0;

    if (progressListener != null)
      progressListener.onBegin(this, totRecords, false);

    database.declareIntent(new OIntentMassiveInsert());
    try {
      // BROWSE ALL THE RECORDS OF THE SOURCE CLASS
      for (ODocument doc : db.browseClass(sourceClass.getName())) {
        value = doc.field(sourceField);

        if (value != null) {
          if (value instanceof ODocument || value instanceof ORID) {
            // ALREADY CONVERTED
          } else if (value instanceof Collection<?>) {
            // TODO
          } else {
            // SEARCH THE DESTINATION RECORD
            target = null;

            if (!ODocumentHelper.ATTRIBUTE_RID.equals(destField) && value instanceof String)
              if (((String) value).length() == 0)
                value = null;
              else
                value = "'" + value + "'";

            result = database.<OCommandRequest> command(new OSQLSynchQuery<ODocument>(cmd + value)).execute();

            if (result == null || result.size() == 0)
              value = null;
            else if (result.size() > 1)
              throw new OCommandExecutionException("Cannot create link because multiple records was found in class '"
                  + destClass.getName() + "' with value " + value + " in field '" + destField + "'");
            else {
              target = result.get(0);
              value = target;
            }

            if (target != null && inverse) {
              // INVERSE RELATIONSHIP
              oldValue = target.field(linkName);

              if (oldValue != null) {
                if (!multipleRelationship)
                  multipleRelationship = true;

                Collection<ODocument> coll;
                if (oldValue instanceof Collection) {
                  // ADD IT IN THE EXISTENT COLLECTION
                  coll = (Collection<ODocument>) oldValue;
                  target.setDirty();
                } else {
                  // CREATE A NEW COLLECTION FOR BOTH
                  coll = new ArrayList<ODocument>(2);
                  target.field(linkName, coll);
                  coll.add((ODocument) oldValue);
                }
                coll.add(doc);
              } else {
                if (linkType != null)
                  if (linkType == OType.LINKSET) {
                    value = new ORecordLazySet(target);
                    ((Set<OIdentifiable>) value).add(doc);
                  } else if (linkType == OType.LINKLIST) {
                    value = new ORecordLazyList(target);
                    ((ORecordLazyList) value).add(doc);
                  } else
                    // IGNORE THE TYPE, SET IT AS LINK
                    value = doc;
                else
                  value = doc;

                target.field(linkName, value);
              }
              target.save();

            } else {
              // SET THE REFERENCE
              doc.field(linkName, value);
              doc.save();
            }

            total++;
          }
        }

        if (progressListener != null)
          progressListener.onProgress(this, currRecord, currRecord * 100f / totRecords);
      }

      if (total > 0) {
        if (inverse) {
          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = destClass.getProperty(linkName);
          if (prop != null)
            destClass.dropProperty(linkName);

          if (linkType == null)
            linkType = multipleRelationship ? OType.LINKSET : OType.LINK;

          // CREATE THE PROPERTY
          destClass.createProperty(linkName, linkType, sourceClass);

        } else {

          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = sourceClass.getProperty(linkName);
          if (prop != null)
            sourceClass.dropProperty(linkName);

          // CREATE THE PROPERTY
          sourceClass.createProperty(linkName, OType.LINK, destClass);
        }
      }

      if (progressListener != null)
        progressListener.onCompletition(this, true);

    } catch (Exception e) {
      if (progressListener != null)
        progressListener.onCompletition(this, false);

      throw new OCommandExecutionException("Error on creation of links", e);

    } finally {
      database.declareIntent(null);
    }

    return total;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

    if (iRecordType == ODocument.RECORD_TYPE) {
      final ODocument storedRecord = rid.getRecord();
      final ODocument newRecord = new ODocument().fromStream(iRecordContent);

      final ODatabaseRecordInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.get();
      hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false);
    } else {
      // CHECK BYTE PER BYTE
      final ORecordAbstract storedRecord = rid.getRecord();
      hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent);
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

      return ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration().getTimeZone();
    return TimeZone.getDefault();
  }

  public static DateFormat getDateFormatInstance() {
    final ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !db.isClosed())
      return db.getStorage().getConfiguration().getDateFormatInstance();
    else
      return new SimpleDateFormat(DEF_DATE_FORMAT);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

    else
      return new SimpleDateFormat(DEF_DATE_FORMAT);
  }

  public static String getDateFormat() {
    final ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !db.isClosed())
      return db.getStorage().getConfiguration().getDateFormat();
    else
      return DEF_DATE_FORMAT;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

    else
      return DEF_DATE_FORMAT;
  }

  public static DateFormat getDateTimeFormatInstance() {
    final ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !db.isClosed())
      return db.getStorage().getConfiguration().getDateTimeFormatInstance();
    else
      return new SimpleDateFormat(DEF_DATETIME_FORMAT);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

    else
      return new SimpleDateFormat(DEF_DATETIME_FORMAT);
  }

  public static String getDateTimeFormat() {
    final ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !db.isClosed())
      return db.getStorage().getConfiguration().getDateTimeFormat();
    else
      return DEF_DATETIME_FORMAT;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

     if (session == null)
       throw new OSecurityAccessException(iRequest.databaseName, "No session active");

     // after authentication, if current login user is different compare with current DB user, reset DB user to login user
     ODatabaseRecordInternal localDatabase = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();

     if (localDatabase == null) {
       localDatabase = (ODatabaseDocumentTx) server.openDatabase("document", iRequest.databaseName, session.getUserName(),
           session.getUserPassword());
     } else {

       String currentUserId = iRequest.data.currentUserId;
       if (currentUserId != null && currentUserId.length() > 0 && localDatabase != null && localDatabase.getUser() != null) {
         if (!currentUserId.equals(localDatabase.getUser().getDocument().getIdentity().toString())) {
           ODocument userDoc = localDatabase.load(new ORecordId(currentUserId));
           localDatabase.setUser(new OUser(userDoc));
         }
       }
     }

     iRequest.data.lastDatabase = localDatabase.getName();
     iRequest.data.lastUser = localDatabase.getUser() != null ? localDatabase.getUser().getName() : null;
     return (ODatabaseDocumentTx) localDatabase.getDatabaseOwner();
   }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

            cmd.append(clusterIds[i]);
          }
        }
      }

      final ODatabaseRecordInternal db = getDatabase();
      final OStorage storage = db.getStorage();

      if (isDistributedCommand()) {
        final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
        OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
        commandSQL.addExcludedNode(autoshardedStorage.getNodeId());

        db.command(commandSQL).execute();

        createClassInternal(className, superClass, clusterIds);
      } else if (storage instanceof OStorageProxy) {
        db.command(new OCommandSQL(cmd.toString())).execute();
        reload();

      } else
        createClassInternal(className, superClass, clusterIds);
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecordInternal

      final Character wrongCharacter = checkNameIfValid(className);
      if (wrongCharacter != null)
        throw new OSchemaException("Found invalid class name. Character '" + wrongCharacter + "' cannot be used in class name.");

      final ODatabaseRecordInternal database = getDatabase();
      final OStorage storage = database.getStorage();
      checkEmbedded(storage);

      checkClustersAreAbsent(clusterIdsToAdd);

      final int[] clusterIds;
      if (clusterIdsToAdd == null || clusterIdsToAdd.length == 0) {
        // CREATE A NEW CLUSTER(S)
        final int minimumClusters = storage.getConfiguration().getMinimumClusters();

        clusterIds = new int[minimumClusters];
        if (minimumClusters <= 1) {
          clusterIds[0] = database.getClusterIdByName(className);
          if (clusterIds[0] == -1)
            clusterIds[0] = database.addCluster(className);
        } else
          for (int i = 0; i < minimumClusters; ++i) {
            clusterIds[i] = database.getClusterIdByName(className + "_" + i);
            if (clusterIds[i] == -1)
              clusterIds[i] = database.addCluster(className + "_" + i);
          }
      } else
        clusterIds = clusterIdsToAdd;

      database.checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_CREATE);

      final String key = className.toLowerCase();

      if (classes.containsKey(key))
        throw new OSchemaException("Class " + className + " already exists in current database");

      OClassImpl cls = new OClassImpl(this, className, clusterIds);

      classes.put(key, cls);
      if (cls.getShortName() != null)
        // BIND SHORT NAME TOO
        classes.put(cls.getShortName().toLowerCase(), cls);

      if (superClass != null) {
        cls.setSuperClassInternal(superClass);

        // UPDATE INDEXES
        final int[] clustersToIndex = superClass.getPolymorphicClusterIds();
        final String[] clusterNames = new String[clustersToIndex.length];
        for (int i = 0; i < clustersToIndex.length; i++)
          clusterNames[i] = database.getClusterNameById(clustersToIndex[i]);

        for (OIndex<?> index : superClass.getIndexes())
          for (String clusterName : clusterNames)
            if (clusterName != null)
              database.getMetadata().getIndexManager().addClusterToIndex(clusterName, index.getName());
      }

      addClusterClassMap(cls);

      return cls;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.