Package nexj.core.persistence

Examples of nexj.core.persistence.SchemaVersion


         DataLoader loader = new DataLoader(m_context);
        
         for (Iterator itr = loader.getDataSourceIterator(getDataSourceSet()); itr.hasNext();)
         {
            DataSource ds = (DataSource)itr.next();
            SchemaVersion version = loader.getSchemaVersion(ds);

            if (version != null)
            {
               printVersion(version.getNamespace(), version.getVersion());

               if (!ObjUtil.equal(m_context.getMetadata().getNamespace(), version.getNamespace()))
               {
                  if (s_logger.isWarnEnabled())
                  {
                     s_logger.warn("Namespace mismatch in " + ds + " (expected \"" +
                        m_context.getMetadata().getNamespace() + "\", got \"" +
                        version.getNamespace() + "\")");
                  }

                  setExitCode(2);
               }
            }
View Full Code Here


                  DataSourceFragment fragment = (DataSourceFragment)fragmentItr.next();
                  String sFragment = (fragment.getName() == null) ? "" : fragment.getName();

                  context.setFragmentName(sFragment);

                  SchemaVersion version = ((PersistenceAdapter)dataSource.getComponent()
                     .getInstance(context)).getVersion(dataSource.getSchema());

                  if (version != null)
                  {
                     if (!metadata.getNamespace().equals(version.getNamespace()))
                     {
                        throw new PersistenceException("err.persistence.storageNamespace",
                           new Object[]{version.getNamespace(), dataSource.getName(),
                              sFragment, metadata.getNamespace()});
                     }

                     if (!metadata.getVersion().equals(version.getVersion()))
                     {
                        throw new PersistenceException("err.persistence.storageVersion",
                           new Object[]{version.getVersion(), dataSource.getName(),
                           sFragment, metadata.getVersion(), metadata.getNamespace()});
                     }
                  }
               }
            }
View Full Code Here

      // If the version table exists
      if (versionTable != null && versionTable.getType() == Table.MANAGED)
      {
         StringBuffer buf = new StringBuffer(64);
         Metadata metadata = schema.getMetadata();
         SchemaVersion version = new SchemaVersion();

         version.setNamespace(metadata.getNamespace());
         version.setVersion(metadata.getVersion());
         version.setStep(UPGRADE_END_STEP);
         version.setUpgradable(false);
         version.setTest(false);
         appendVersionTableInsert(buf, schema, version, false); // set version to match schema
         m_appender.appendSQL(buf.toString());
      }
   }
View Full Code Here

      SQLAppender innerAppender = getDynamicSQLAppender(buf);
      Metadata metadata = schema.getMetadata();
      VersionUpgrade firstVersion = (sVersion == null)
                                  ? upgrade.getFirstVersion() : upgrade.getVersion(sVersion);
      Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(firstVersion);
      SchemaVersion version = new SchemaVersion();

      upgrade.validate(metadata, null);
      version.setNamespace(metadata.getNamespace());
      version.setUpgradable(true);
      appendUpgradeInitialize(buf, schema);

      if (buf.length() > 0) // don't want to output end-of-statement character if there's nothing in buffer
      {
         m_appender.appendSQL(buf.toString());
         buf.setLength(0);
      }

      // skip all upgrade versions not applicable to schema's DataSourceAdapter
      if (sVersion == null)
      {
         firstVersion =
            findFirstVersion(firstVersion, stateMap, (RelationalDatabase)schema.getDataSource());
      }

      for (VersionUpgrade u = firstVersion; u != null; u = u.getNext())
      {
         if (u.getName() == null)
         {
            u.apply(Upgrade.getState(stateMap, u));
         }
         else
         {
            version.setVersion(u.getName());
            version.setStep(UPGRADE_END_STEP);

            SchemaVersion prev = (SchemaVersion)version.clone();

            version.setStep((u instanceof ScriptUpgrade && ((ScriptUpgrade)u).getFunction() == null ||
               u instanceof RelationalSchemaUpgrade &&
                  ((RelationalSchemaUpgrade)u).getDataSource().getSchema() != schema ||
               u instanceof LabelUpgrade) ? UPGRADE_END_STEP : 0);

            if (u.getPrev() != null && u.getPrev().getName() != null)
            {
               prev.setVersion(u.getPrev().getName());
               appendUpgradeStepStart(buf, schema, prev);
               appendUpgradeStepEnd(buf, schema, version, prev, null);
               m_appender.appendSQL(buf.toString());
               buf.setLength(0);
            }
View Full Code Here

    * @param bForce True to ignore the upgradable flag in the data source.
    */
   public void upgrade(Set dataSourceSet, Upgrade upgrade, boolean bForce)
   {
      Metadata metadata = m_context.getMetadata();
      SchemaVersion version = null;
      Iterator dataSourceItr = getDataSourceIterator(dataSourceSet);

      dataSourceSet = new HashHolder(4);

      while (dataSourceItr.hasNext())
      {
         DataSource ds = (DataSource)dataSourceItr.next();
         SchemaVersion dsVersion = ((PersistenceAdapter)ds.getComponent()
            .getInstance(m_context)).getVersion(ds.getSchema());

         if (dsVersion != null)
         {
            if (version == null)
            {
               version = dsVersion;

               if (!ObjUtil.equal(metadata.getNamespace(), version.getNamespace()))
               {
                  throw new IllegalStateException("Namespace mismatch in data source \"" +
                     ds.getName() + "\" (expected \"" + metadata.getNamespace() +
                     "\", got \"" + version.getNamespace() + "\")");
               }
            }
            else
            {
               if (!ObjUtil.equal(version.getNamespace(), dsVersion.getNamespace()))
               {
                  throw new IllegalStateException("Namespace mismatch in data source \"" +
                     ds.getName() + "\" (expected \"" + version.getNamespace() +
                     "\", got \"" + dsVersion.getNamespace() + "\")");
               }

               if (!ObjUtil.equal(version.getVersion(), dsVersion.getVersion()))
               {
                  throw new IllegalStateException("Version mismatch in data source \"" +
                     ds.getName() + "\" (expected \"" + version.getVersion() +
                     "\", got \"" + dsVersion.getVersion() + "\")");
               }
            }

            if (dsVersion.isUpgradable() || bForce)
            {
               dataSourceSet.add(ds);
            }
         }
      }
View Full Code Here

         {
            throw new PersistenceException("err.persistence.noStorageVersion",
               new Object[]{db.getName()});
         }

         SchemaVersion version = new SchemaVersion();

         version.setNamespace(Primitive.toString(getBind(namespaceColumn).getValue(rs, 0, this)));
         version.setVersion(Primitive.toString(getBind(versionColumn).getValue(rs, 1, this)));

         Integer step = Primitive.toInteger(getBind(stepColumn).getValue(rs, 2, this));

         version.setStep((step == null) ? -1 : step.intValue());

         Boolean upgradable = Primitive.toBoolean(getBind(upgradableColumn).getValue(rs, 3, this));

         version.setUpgradable((upgradable == null) ? false : upgradable.booleanValue());

         Boolean test = Primitive.toBoolean(getBind(testColumn).getValue(rs, 4, this));

         version.setTest((test == null) ? false : test.booleanValue());

         // has to be done while still have data in ResultSet on DB2
         Boolean unicode = isUnicode((RelationalSchema)schema, rs, 1); // 1 == "namespace" column
         boolean bUnicode = db.isUnicode();
View Full Code Here

         RelationalSchemaTest.addHint(schema, "test2");
         RelationalSchemaTest.addHint(schema, "test3");
      }

      RelationalSchemaUpgradeState state = new RelationalSchemaUpgradeState(schema, null, null);
      SchemaVersion version = new SchemaVersion();
      RelationalSchemaUpgrade upgrade = new RelationalSchemaUpgrade();
      SQLAppender origAppender = m_manager.getSQLAppender();

      upgrade.addStep(step);
      upgrade.setUpgrade(new Upgrade(null));
View Full Code Here

      upgrade.validate(getMetadata(), null);

      VersionUpgrade firstVersion = upgrade.getFirstVersion();
      Lookup stateMap = Upgrade.getInitialState(firstVersion);
      SchemaVersion version = new SchemaVersion();

      version.setNamespace(getMetadata().getNamespace());
      version.setUpgradable(true);

      for (VersionUpgrade u = firstVersion; u != null; u = u.getNext())
      {
         version.setVersion(u.getName());
         version.setStep(0);

         if (u.getName() == null)
         {
            u.apply(Upgrade.getState(stateMap, u));
         }
View Full Code Here

TOP

Related Classes of nexj.core.persistence.SchemaVersion

Copyright © 2018 www.massapicom. 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.