Package nexj.core.meta

Examples of nexj.core.meta.Metadata


   {
      Principal principal = m_request.getUserPrincipal();

      if (principal == null)
      {
         Metadata metadata = m_context.getMetadata();

         if (HTTPUtil.isAnonymousRequest(m_request, metadata))
         {
            principal = metadata.getAnonymousUser();
         }
      }

      return principal;
   }
View Full Code Here


    * @param bExclusive True to limit the exported classes to those in whereMap.
    * @return List of transfer object.
    */
   public List exportData(Set dataSourceSet, Lookup whereMap, boolean bExclusive)
   {
      Metadata metadata = m_context.getMetadata();
      List resultList = new ArrayList();
      Lookup identityMap = new IdentityHashTab();
      Lookup classMap = new HashTab();

      for (Iterator itr = metadata.getMetaclassIterator(); itr.hasNext();)
      {
         Metaclass metaclass = (Metaclass)itr.next();
         PersistenceMapping mapping = metaclass.getPersistenceMapping();
         Object where = resolve(metaclass, whereMap);

View Full Code Here

    * @param dataSourceSet Set of data sources to import. Null for all.
    * @param bEmpty True if the persistent storage is empty.
    */
   public void importData(InputStream istream, Set dataSourceSet, boolean bEmpty) throws Exception
   {
      Metadata metadata = m_context.getMetadata();
      List list = (List)input(istream);

      if (metadata.findMetaclass(Metadata.VERSION_CLASS_NAME) != null)
      {
         for (int i = 0, nCount = list.size(); i < nCount; ++i)
         {
            TransferObject tobj = (TransferObject)list.get(i);

            if (tobj.getClassName().equals(Metadata.VERSION_CLASS_NAME))
            {
               if (!metadata.getNamespace().equals(tobj.findValue("namespace")) ||
                  !metadata.getVersion().equals(tobj.findValue("version")))
               {
                  throw new IllegalArgumentException("Version mismatch: dump version " +
                     tobj.findValue("namespace") + '#' + tobj.findValue("version") +
                     ", metadata version " + metadata.getNamespace() + '#' +
                     metadata.getVersion());
               }

               break;
            }
         }
View Full Code Here

    * @param upgrade The upgrade metadata.
    * @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
            {
View Full Code Here

    * 2. From derived to base if base.derivation is not final.
    * 3. From base to all derived.
    */
   public void testNamespaceCopying()
   {
      Metadata metadata = m_context.getMetadata();

      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Referrer").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Derived_Referent").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Derived_Referrer").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Derived_Derived").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Base_Referent").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Base_Referrer").getRoot().getMapping())).getNamespace("xsd");
      ((RootXMLMessagePartMapping)(metadata.getMessage(
            "XML_Namespace_Base_Base").getRoot().getMapping())).getNamespace("xsd");
   }
View Full Code Here

         return null;
      }

      RelationalDatabase db = (RelationalDatabase)schema.getDataSource();
      Table table = ((RelationalSchema)schema).getVersionTable();
      Metadata metadata = m_context.getMetadata();

      if (metadata.getNamespace() == null || table == null)
      {
         return null;
      }

      Column namespaceColumn = table.getColumn("namespace");
View Full Code Here

   {
      Context contextSaved = ThreadContextHolder.getContext();

      try
      {
         Metadata metadata = Repository.getMetadata();
         boolean bFirstRun = true;
         int nTestCaseCount = 0;
         int nFailureCount = 0;
         int nErrorCount = 0;
         m_unitTestLogger.begin();

         // Now that support has been added for a real JMS engine in Teee, we must set JMSSender
         // to not use it as most unit tests don't expect it and rely on synchronous message delivery.
         for (Iterator itr = metadata.getChannelIterator(); itr.hasNext(); )
         {
            Channel channel = (Channel)itr.next();

            if (channel instanceof MessageQueue)
            {
               MessageQueue mq = (MessageQueue)channel;

               if (mq.isSendable())
               {
                  ((JMSSender)mq.getSender().getInstance(null)).setEnabled(false);
               }
            }
         }

         boolean bReady = false;

         for (int nUnitTest = 0; nUnitTest < m_unitTestList.size(); ++nUnitTest)
         {
            boolean bInit = m_globalEnv == null;

            if (bInit)
            {
               m_globalEnv = new GlobalEnvironment(metadata.getGlobalEnvironment());
            }

            InvocationContext context = (InvocationContext)metadata.getComponent("System.InvocationContext").getInstance(null);

            context.setAudited(false);
            context.initialize(null, m_globalEnv);
            context.setLocale(m_locale);

            Machine machine = context.getMachine();

            if (bInit)
            {
               InputStream istream = null;
               Reader reader = null;

               try
               {
                  istream = URLUtil.openResource(UnitTest.class, INITIAL_SCRIPT);
                  reader = new BufferedReader(new InputStreamReader(istream, XMLUtil.ENCODING));
                  Intrinsic.load(reader, INITIAL_SCRIPT_URL, machine);
               }
               catch (IOException e)
               {
                  throw new MetadataException("err.meta.resourceOpen", new Object[]{INITIAL_SCRIPT}, e);
               }
               finally
               {
                  IOUtil.close(reader);
                  IOUtil.close(istream);
               }
            }

            UnitTest utest = (UnitTest)m_unitTestList.get(nUnitTest);

            for (Iterator argItr = new ArgumentIterator(context, utest); argItr.hasNext(); )
            {
               Object[] variableArray = (Object[])argItr.next();
               String sTestArguments = formatLoopVariables(variableArray, utest.getLoopCount());
               DataLoader dataLoader = new DataLoader(context);
               URL dumpURL = getDumpURL(utest);
               boolean bResetDB = dumpURL != null;

               m_unitTestLogger.begin(utest, sTestArguments);

               if (bResetDB && !bReady)
               {
                  if (m_container != null)
                  {
                     m_container.suspend();
                  }

                  bReady = true;

                  if (nUnitTest == 0)
                  {
                     try
                     {
                        dataLoader.recreateSchema((Set)null);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                  }
                  else
                  {
                     bFirstRun = false;
                  }
               }

               byte nMode = utest.getMode();
               int nTestCase = 0;

               if (utest.hasInitializer())
               {
                  ++nTestCase;
               }

               if (utest.hasFinalizer())
               {
                  ++nTestCase;
               }

               Object[] functionObjArray = null;

               if (utest.getFunction() != null)
               {
                  functionObjArray = (Object[])context.getMachine().invoke(utest.getFunction(), variableArray);
               }

               boolean bFirstTestCase = true;

               for (Iterator itr = utest.getUnitTestCaseIterator(); itr.hasNext();
                  bFirstRun = false, bFirstTestCase = false, bResetDB = dumpURL != null && nMode != UnitTest.MODE_DIRTY)
               {
                  UnitTestCase testCase = (UnitTestCase)itr.next();

                  if (!isEnabled(utest, testCase))
                  {
                     nTestCase++;
                     continue;
                  }

                  if (bResetDB)
                  {
                     if (!bFirstTestCase && m_container != null)
                     {
                        m_container.suspend();
                     }

                     if (!bFirstRun)
                     {
                        try
                        {
                           dataLoader.deleteData((Set)null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(utest, e);

                           return;
                        }
                     }

                     InputStream in = null;

                     try
                     {
                        in = new BufferedInputStream(URLUtil.openStream(dumpURL));
                        dataLoader.importData(in, true);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                     finally
                     {
                        IOUtil.close(in);
                        in = null;
                     }
                  }

                  context.complete(true);
                  context.getMachine().cleanup();
                  context.initUnitOfWork();

                  final InvocationContext testContext = (InvocationContext)metadata
                     .getComponent("System.InvocationContext").getInstance(null);

                  try
                  {
                     testContext.setAudited(false);
View Full Code Here

    * Tests fragment replication of creates, updates, and deletes
    * with the file persistence adapter.
    */
   public void testFragmentReplicationUpdateDelete() throws Exception
   {
      Metadata metadata = loadMetadata("filestoragefragment");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         File tempDir1 = new File(mainDir, "temp1");
         File dataDir1 = new File(mainDir, "data1");
         File jrnlDir1 = new File(mainDir, "journal1");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
         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());
        
         fragment1.debugSettings(dataDir1.getAbsolutePath(),
            tempDir1.getAbsolutePath(),
            jrnlDir1.getAbsolutePath());
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation (\u4e2d\u6587) data.".getBytes("utf-8")));
        
         // Replicate
View Full Code Here

    * read, update, and delete statements. Uses adapter to
    * verify that the operations are performed successfully.
    */
   public void testCreateReadUpdateDelete() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data.".getBytes("utf-8")));
        
         commit(context);
View Full Code Here

   /**
    * Tests that the adapter can create multiple files in one transaction.
    */
   public void testCreateMultiple() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data for 'a'.".getBytes("utf-8")));
        
         Instance b = (Instance)testFPA.invoke("new");
View Full Code Here

TOP

Related Classes of nexj.core.meta.Metadata

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.