Read and return the migration from the resource.

@return a {@link io.ebeaninternal.dbmigration.migration.Migration} object.
359554
public Migration read() {
        try (StringReader reader = new StringReader(info.getModelDiff())) {
            JAXBContext jaxbContext = JAXBContext.newInstance(Migration.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            return (Migration) unmarshaller.unmarshal(reader);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
758936
@Override
	public String readString() throws JMSException
    {
    	backupState();
		try
		{
			return MessageConvertTools.asString(internalReadObject());
		}
    	catch (JMSException e)
    	{
    		restoreState();
    		throw e;	
    	}
    	catch (RuntimeException e)
    	{
    		restoreState();
    		throw e;
    	}
    }
1029470
def get_migration(plugin, filename):
    ''''''
    db = get_db()
    return db.migrations.find_one({'plugin': plugin, 'filename': filename})
43973
public void migrate(File fromSource, File toDest) {
        IReaderHandler readerHandler = this;
        try (IDataMigratorReader reader = new JsonDataMigratorReader(fromSource);
             IDataMigratorWriter writer = new JsonDataMigratorWriter(toDest)) {
            this.writer = writer;
            reader.read(readerHandler);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
309853
public static Object readValueFromBeanField(Object entityBean, String fieldName) {
		Method readMethod = ClassCacheUtils.getClassFieldReadMethod(entityBean.getClass(), fieldName);
		if (readMethod == null) {
			throw new DialectException(
					"No mapping found for field '" + fieldName + "' in '" + entityBean.getClass() + "'");
		} else
			try {
				return readMethod.invoke(entityBean);
			} catch (Exception e) {
				throw new DialectException(e);
			}
	}
658450
public function read()
    {
        if (null !== $this->resolvedIdentity) {
            return $this->resolvedIdentity;
        }

        $identity = $this->getStorage()->read();

        if (is_int($identity) || is_scalar($identity)) {
            $identity = $this->getMapper()->findById($identity);
        }

        if ($identity) {
            $this->resolvedIdentity = $identity;
        } else {
            $this->resolvedIdentity = null;
        }

        return $this->resolvedIdentity;
    }
562455
public function getMigrations()
    {
        $migrations = [];

        /* @var $migrationName Migration */
        foreach ($this->getMigrationsClasses() as $appName => $classes) {
            foreach ($classes as $fileName) {
                $migrationName = $fileName;
                $migration = $migrationName::createObject($fileName);
                $migration->setAppLabel($appName);
                $this->setMigratedApps($appName);
                $migrations[$fileName] = $migration;
            }
        }

        return $migrations;
    }
96828
public static function getMigrationVersion()
    {
        if (self::isInstallerAvailable()) {
            $migrations = scandir(DOCROOT . '/install/migrations');
            $migration_file = end($migrations);
            $migration_class = 'migration_' . str_replace('.', '', substr($migration_file, 0, -4));
            return call_user_func(array($migration_class, 'getVersion'));
        }

        return false;
    }
97283
public function readAction()
    {
        $result = parent::readAction();
        if (!is_array($result)) {
            return $result;
        }

        $em = $this->getEntityManager();
        $status = $this->getFieldsConfig()->getConfigItem('status');
        $statuses = $status['dataSource']->getData();

        $entity = $em->find($this->entityName, Application::getRequest()->get('id'));
        $status = $entity->getStatus();

        return array_merge($result, ['status' => isset($statuses[$status]) ? $statuses[$status] : '']);
    }
910425
public static void migrate(PersistentIndex index, DirectoryManager directoryManager) throws IOException
   {
      Directory indexDir = index.getDirectory();
      log.debug("Checking {} ...", indexDir);
      ReadOnlyIndexReader reader = index.getReadOnlyIndexReader();
      try
      {
         if (IndexFormatVersion.getVersion(reader).getVersion() >= IndexFormatVersion.V3.getVersion())
         {
            // index was created with Jackrabbit 1.5 or higher
            // no need for migration
            log.debug("IndexFormatVersion >= V3, no migration needed");
            return;
         }
         // assert: there is at least one node in the index, otherwise the
         //         index format version would be at least V3
         TermEnum terms = reader.terms(new Term(FieldNames.PROPERTIES, ""));
         try
         {
            Term t = terms.term();
            if (t.text().indexOf('\uFFFF') == -1)
            {
               log.debug("Index already migrated");
               return;
            }
         }
         finally
         {
            terms.close();
         }
      }
      finally
      {
         reader.release();
         index.releaseWriterAndReaders();
      }

      // if we get here then the index must be migrated
      log.debug("Index requires migration {}", indexDir);

      String migrationName = index.getName() + "_v2.3";
      if (directoryManager.hasDirectory(migrationName))
      {
         directoryManager.delete(migrationName);
      }

      Directory migrationDir = directoryManager.getDirectory(migrationName);
      try
      {
         IndexWriter writer =
            new IndexWriter(migrationDir, new IndexWriterConfig(Version.LUCENE_36, new JcrStandartAnalyzer()));
         try
         {
            IndexReader r = new MigrationIndexReader(IndexReader.open(index.getDirectory()));
            try
            {
               writer.addIndexes(new IndexReader[]{r});
               writer.close();
            }
            finally
            {
               r.close();
            }
         }
         finally
         {
            writer.close();
         }
      }
      finally
      {
         migrationDir.close();
      }
      directoryManager.delete(index.getName());
      if (!directoryManager.rename(migrationName, index.getName()))
      {
         throw new IOException("failed to move migrated directory " + migrationDir);
      }
      log.info("Migrated " + index.getName());
   }
928295
public T read(final K key) throws SQLException {
        return
            transactionTemplate
                .doInTransaction(new SQLFunction<Connection, T>() {
                    @Override
                    public T apply(Connection connection) throws SQLException {
                        return delegate.read(connection, key);
                    }
                });
    }
89979
def _get_queries(self, migration, method):
        
        connection = migration.get_connection()
        db = connection

        with db.pretend():
            getattr(migration, method)()

        return db.get_logged_queries()
955945
public MigrationReport migrate(Map<String, String> nodeMapping) {

        
        KieSession current = null;
        KieSession tobe = null;      
        TransactionManager txm = null;
        boolean transactionOwner = false;
        InternalRuntimeManager currentManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId());
        InternalRuntimeManager toBeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId());

        boolean migrateExecutorJobs = ((SimpleRuntimeEnvironment)currentManager.getEnvironment()).getEnvironmentTemplate().get("ExecutorService") != null;
        validate(migrateExecutorJobs);
        Map<Long, List<TimerInstance>> timerMigrated = null;
        try {

            // collect and cancel any active timers before migration
            timerMigrated = cancelActiveTimersBeforeMigration(currentManager);

            // start transaction to secure consistency of the migration			
            txm = TransactionManagerFactory.get().newTransactionManager(currentManager.getEnvironment().getEnvironment());
            transactionOwner = txm.begin();

            org.kie.api.definition.process.Process toBeProcess = toBeManager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId());

            String auditPu = currentManager.getDeploymentDescriptor().getAuditPersistenceUnit();

            EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(auditPu);
            EntityManager em = emf.createEntityManager();

            try {
                // update variable instance log information with new deployment id and process id
                Query varLogQuery = em.createQuery("update VariableInstanceLog set externalId = :depId, processId = :procId where processInstanceId = :procInstanceId");
                varLogQuery
                           .setParameter("depId", migrationSpec.getToDeploymentId())
                           .setParameter("procId", migrationSpec.getToProcessId())
                           .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int varsUpdated = varLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Variable instances updated = " + varsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

                // update node instance log information with new deployment id and process id
                Query nodeLogQuery = em.createQuery("update NodeInstanceLog set externalId = :depId, processId = :procId where processInstanceId = :procInstanceId");
                nodeLogQuery
                            .setParameter("depId", migrationSpec.getToDeploymentId())
                            .setParameter("procId", migrationSpec.getToProcessId())
                            .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int nodesUpdated = nodeLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Node instances updated = " + nodesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

                // update process instance log with new deployment and process id
                Query pInstanceLogQuery = em.createQuery(
                                                         "update ProcessInstanceLog set externalId = :depId, processId = :procId, processName = :procName, processVersion= :procVersion where processInstanceId = :procInstanceId");
                pInstanceLogQuery
                                 .setParameter("depId", migrationSpec.getToDeploymentId())
                                 .setParameter("procId", migrationSpec.getToProcessId())
                                 .setParameter("procName", toBeProcess.getName())
                                 .setParameter("procVersion", toBeProcess.getVersion())
                                 .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int pInstancesUpdated = pInstanceLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Process instances updated = " + pInstancesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

                try {
                    // update task audit instance log with new deployment and process id
                    Query taskVarLogQuery = em.createQuery("update TaskVariableImpl set processId = :procId where processInstanceId = :procInstanceId");
                    taskVarLogQuery
                                   .setParameter("procId", migrationSpec.getToProcessId())
                                   .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                    int taskVarUpdated = taskVarLogQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Task variables updated = " + taskVarUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
                } catch (Throwable e) {
                    logger.warn("Unexpected error during migration", e);
                    report.addEntry(Type.WARN, "Cannot update task variables (added in version 6.3) due to " + e.getMessage());
                }

                // update task audit instance log with new deployment and process id
                Query auditTaskLogQuery = em.createQuery("update AuditTaskImpl set deploymentId = :depId, processId = :procId where processInstanceId = :procInstanceId");
                auditTaskLogQuery
                                 .setParameter("depId", migrationSpec.getToDeploymentId())
                                 .setParameter("procId", migrationSpec.getToProcessId())
                                 .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Task audit updated = " + auditTaskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

                // update task  instance log with new deployment and process id
                Query taskLogQuery = em.createQuery("update TaskImpl set deploymentId = :depId, processId = :procId where processInstanceId = :procInstanceId");
                taskLogQuery
                            .setParameter("depId", migrationSpec.getToDeploymentId())
                            .setParameter("procId", migrationSpec.getToProcessId())
                            .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int taskUpdated = taskLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Tasks updated = " + taskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

                try {
                    // update context mapping info with new deployment
                    Query contextInfoQuery = em.createQuery("update ContextMappingInfo set ownerId = :depId where contextId = :procInstanceId");
                    contextInfoQuery
                                    .setParameter("depId", migrationSpec.getToDeploymentId())
                                    .setParameter("procInstanceId", migrationSpec.getProcessInstanceId().toString());

                    int contextInfoUpdated = contextInfoQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Context info updated = " + contextInfoUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
                } catch (Throwable e) {
                    logger.warn("Unexpected error during migration", e);
                    report.addEntry(Type.WARN, "Cannot update context mapping owner (added in version 6.2) due to " + e.getMessage());
                }
                
                if (migrateExecutorJobs) {
                    // update request info/executor with new deployment id
                    Query executorRequestQuery = em.createQuery("update RequestInfo set deploymentId = :depId where processInstanceId = :procInstanceId and status in ('ERROR')");
                    executorRequestQuery
                                .setParameter("depId", migrationSpec.getToDeploymentId())                            
                                .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());
    
                    int executorRequestsUpdated = executorRequestQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Executor Jobs updated = " + executorRequestsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
                }
                current = JPAKnowledgeService.newStatefulKnowledgeSession(currentManager.getEnvironment().getKieBase(), null, currentManager.getEnvironment().getEnvironment());
                tobe = toBeManager.getEnvironment().getKieBase().newKieSession();
                upgradeProcessInstance(current, tobe, migrationSpec.getProcessInstanceId(), migrationSpec.getToProcessId(), nodeMapping, em, toBeManager.getIdentifier());

                if (!timerMigrated.isEmpty()) {
                    rescheduleTimersAfterMigration(toBeManager, timerMigrated);
                }
                em.flush();
            } finally {
                em.clear();
                em.close();
            }

            txm.commit(transactionOwner);
            report.addEntry(Type.INFO, "Migration of process instance (" + migrationSpec.getProcessInstanceId() + ") completed successfully to process " + migrationSpec.getToProcessId());
            report.setSuccessful(true);
            report.setEndDate(new Date());
        } catch (Throwable e) {
            txm.rollback(transactionOwner);
            logger.error("Unexpected error during migration", e);
            // put back timers (if there are any) in case of rollback
            if (timerMigrated != null && !timerMigrated.isEmpty()) {
                rescheduleTimersAfterMigration(currentManager, timerMigrated);
            }
            report.addEntry(Type.ERROR, "Migration of process instance (" + migrationSpec.getProcessInstanceId() + ") failed due to " + e.getMessage());

        } finally {
            if (current != null) {
                try {
                    current.destroy();
                } catch (SessionNotFoundException e) {
                    // in case of rollback session might not exist
                }
            }

            if (tobe != null) {

                try {
                    tobe.destroy();
                } catch (SessionNotFoundException e) {
                    // in case of rollback session might not exist
                }
            }
        }

        return report;
    }
853271
public DataConnection getConnection() {
        DataConnection connection;

        for (connection = availableConnections.poll();
             connection != null && !connection.isUsable();
             connection = availableConnections.poll())
        {
            if (!connection.isUsable()) {
                connection.close();
            }
        }

        if (connection == null) {
            connection = new DataConnection(getDataUri());

            try {
                connection.connect();
            }
            catch (Exception e) {
                logger.error("[getConnection] could not connect to database", e);
                return null;
            }
        }

        connection.setLocale(threadLocale.getLocale());

        return connection;
    }
1092192
final public static function migratedAt()
    {
        $row = Db::connection()->query(Query::select()->from('migrations')->where([
            'hash' => static::hash(),
        ]))->fetch();

        return $row !== null
            ? new Carbon($row['migratedAt'])
            : null;
    }
1140977
public int getMigrationStamp() {
        int completed = ownerMigrationsCompleted.get();
        int started = ownerMigrationsStarted.get();
        return completed == started ? completed : IN_FLIGHT_MIGRATION_STAMP;
    }
355321
protected function getLastMigration()
    {
        $lastMigrationTime = $this->getLastMigrationTime();
        if (empty($lastMigrationTime))
            return false;

        foreach (glob($this->getMigrationsPath() . DS . sprintf(self::CLASS_NAME_PATTERN, $lastMigrationTime, '*') . '.php') as $fileName) {
            $className = self::MIGRATIONS_NAMESPACE . '\\' . pathinfo($fileName, PATHINFO_FILENAME);
            $migration = new $className;
            break;
        }

        return $migration;
    }