Package nexj.core.meta.persistence

Examples of nexj.core.meta.persistence.DataSource


    * @return The loaded persistence mapping object.
    */
   public PersistenceMapping loadPersistenceMappingDetails(Element element, Metaclass metaclass)
   {
      String sDataSource = XMLUtil.getReqStringAttr(element, "dataSource");
      DataSource dataSource = m_metadata.getDataSource(sDataSource);
      return ((XMLPersistenceMetadataLoader)m_helper.getClassInstance(dataSource.getType().getLoader()))
         .loadMapping(element, metaclass, dataSource, XMLMetadataLoader.this);
   }
View Full Code Here


                     return XMLUtil.getReqStringAttr(element, "dataSource");
                  }

                  public void handleElement(Element connectionElement, String sDataSource)
                  {
                     DataSource source = m_metadata.getDataSource(sDataSource);
                     String sExpectedElement = m_metadata.getDataSourceTypeElement(source.getType()) + "Connection";

                     if (!sExpectedElement.equals(connectionElement.getNodeName()))
                     {
                        throw new MetadataException("err.meta.dataSourceConnectionElement",
                           new Object[]{connectionElement.getNodeName(), source.getName(),
                           sConnectionsName, sExpectedElement});
                     }

                     if (!connectionSet.add(source))
                     {
                        throw new MetadataException("err.meta.dupDataSourceConnection", new Object[]{sDataSource});
                     }

                     String sAdapter = XMLUtil.getStringAttr(connectionElement, "adapter");

                     if (sAdapter != null)
                     {
                        source.setAdapter(source.getType().getAdapter(sAdapter));
                     }

                     source.setReadLimit(XMLUtil.getIntAttr(connectionElement, "readLimit", source.getReadLimit()));

                     //Load DataSource-specific attributes.
                     ((XMLPersistenceMetadataLoader)m_helper.getClassInstance(source.getType().getLoader()))
                        .loadConnection(connectionElement, source, XMLMetadataLoader.this);
                  }
               });
            }
         });
      }

      //Call loadConnection to initialize DataSources with no entry in the .connections file.
      for (Iterator itr = m_metadata.getDataSourceIterator(); itr.hasNext();)
      {
         DataSource source = (DataSource)itr.next();

         if (!connectionSet.contains(source))
         {
            int nCookie = getHelper().pushMarker(MetadataValidationException.TYPE_NAME, "DataSourceConnection");
            getHelper().pushMarker("dataSourceConnection", source.getName());

            try
            {
               ((XMLPersistenceMetadataLoader)m_helper.getClassInstance(source.getType().getLoader()))
                  .loadConnection(null, source, XMLMetadataLoader.this);
            }
            catch (MetadataException e)
            {
               m_helper.addException(e);
View Full Code Here

      Arrays.sort(dataSourceArray, Named.COMPARATOR);

      for (i = 0; i < dataSourceArray.length; ++i)
      {
         DataSource dataSource = dataSourceArray[i];

         if (dataSource.getType().getExporter() != null)
         {
            getPersistenceMetadataExporter(dataSource)
               .exportJ2EEDescriptor(dataSource, nPart, sNamespace, nContainer, nContext);
         }
      }
View Full Code Here

      String sOriginalContents = format(doc);
      Element datasources = doc.getDocumentElement();

      for (Iterator dsItr = m_metadata.getDataSourceIterator(); dsItr.hasNext();)
      {
         DataSource ds = (DataSource)dsItr.next();

         if (ds.isEnabled() && ds instanceof RelationalDatabase)
         {
            RelationalDatabase db = (RelationalDatabase)ds;

            for (Iterator fragmentItr = db.getFragmentIterator(); fragmentItr.hasNext();)
            {
View Full Code Here

      }

      // Database connections require user and password
      for (Iterator dsItr = m_metadata.getDataSourceIterator(); dsItr.hasNext();)
      {
         DataSource ds = (DataSource)dsItr.next();

         if (ds.isEnabled() && ds instanceof RelationalDatabase)
         {
            RelationalDatabase dataBase = (RelationalDatabase)ds;

            for (Iterator fragmentItr = dataBase.getFragmentIterator(); fragmentItr.hasNext();)
            {
View Full Code Here

      // inject a stream outputting component into every DataSource so none hits DB
      for (Iterator/*<DataSource>*/ itr = getDataSourceIterator(dataSourceSet);
           itr.hasNext();)
      {
         DataSource ds = (DataSource)itr.next();

         // only support RelationalDatabase for SQL dump
         if (!(ds instanceof RelationalDatabase))
         {
            continue; // skip DataSources without any Metaclasses mapped to them
         }

         importDataSourceSet.add(ds);

         SQLAdapter adapter = (SQLAdapter)ds.getComponent().getInstance(m_context);

         adapterList.add(adapter); //reference locally so not GCed
         adapter.setConnectionFactory(outCF); // override adapter's SQLConnectionFactory
      }

View Full Code Here

      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);
            }
         }
      }

      if (dataSourceSet.isEmpty())
      {
         throw new IllegalStateException("No upgradable data sources");
      }

      if (version == null)
      {
         throw new IllegalStateException("Unavailable persistent storage version");
      }

      VersionUpgrade lastUpgrade = upgrade.getVersion(version.getVersion());
      Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(lastUpgrade);

      version.setUpgradable(true);
      lastUpgrade.apply(Upgrade.getState(stateMap, lastUpgrade)); // advance to finished current ver

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

         if (u.getName() == null)
         {
            u.apply(Upgrade.getState(stateMap, u));

            continue;
         }

         if (u instanceof SchemaUpgrade)
         {
            SchemaUpgrade su = (SchemaUpgrade)u;

            dataSource = su.getDataSource();

            if (dataSourceSet.contains(dataSource))
            {
               PersistenceAdapter adapter = (PersistenceAdapter)dataSource.getComponent().getInstance(m_context);

               adapter.upgrade(su, Upgrade.getState(stateMap, su), version);
            }
            else
            {
               su.apply(Upgrade.getState(stateMap, su));
            }
         }
         else if (u instanceof ScriptUpgrade)
         {
            Function fun = ((ScriptUpgrade)u).getFunction();

            if (fun != null)
            {
               if (u.getNext() == null)
               {
                  // Script upgrade must be run with metadata matching the final or previous data version
                  m_context.getMachine().invoke(fun, (Pair)null);
                  m_context.getUnitOfWork().commit(false); // precommit the UOW
               }
               else
               {
                  throw new UnsupportedOperationException(
                     "Unable to run script upgrade for version " + u.getName() +
                     ", temporarily revert metadata used by the upgrade to version "
                     + u.getName() + " before retrying upgrade.");
               }
            }
         }

         version.setStep(-1);

         for (Iterator itr = dataSourceSet.iterator(); itr.hasNext();)
         {
            DataSource ds = (DataSource)itr.next();

            if (ds != dataSource)
            {
               ((PersistenceAdapter)ds.getComponent().getInstance(m_context))
                  .setVersion(ds.getSchema(), version);
            }
         }
      }

      for (Lookup.Iterator itr = stateMap.valueIterator(); itr.hasNext();)
View Full Code Here

   /**
    * @return The default relational database.
    */
   protected RelationalDatabase getDefaultDatabase()
   {
      DataSource ds = m_metadata.getDataSource("DefaultRelationalDatabase");

      if (ds instanceof RelationalDatabase && ds.isEnabled())
      {
         return (RelationalDatabase)ds;
      }

      return null;
View Full Code Here

    * @return The data source object.
    * @throws MetadataLookupException if the data source does not exist.
    */
   public DataSource getDataSource(String sName)
   {
      DataSource dataSource = (DataSource)m_dataSourceMap.get(sName);

      if (dataSource != null)
      {
         return dataSource;
      }
View Full Code Here

        
         assertTrue(tempDir1.mkdir());
         assertTrue(dataDir1.mkdir());
         assertTrue(jrnlDir1.mkdir());
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(2, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
         FileDataSourceFragment fragment1 = (FileDataSourceFragment)ds.getFragment("fragment1");
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
View Full Code Here

TOP

Related Classes of nexj.core.meta.persistence.DataSource

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.