Package nexj.core.meta.xml

Examples of nexj.core.meta.xml.XMLMetadata


         {
            istream.close();
         }
      }

      XMLMetadata metadata = new XMLMetadata("new", root.toURL(), null, null, null);
      DataSourceType dstype = new DataSourceType("RelationalDatabase");

      dstype.setMetadata(metadata);
      dstype.setExporter(XMLRelationalMetadataExporter.class);
      m_database.setType(dstype);
      metadata.addDataSource(m_database);
      ((RelationalSchema)m_database.getSchema()).generateMetaclasses(getProperty("meta.prefix"), properties, null);

      for (Iterator itr = metadata.getMetaclassIterator(); itr.hasNext();)
      {
         Metaclass metaclass = (Metaclass)itr.next();

         File file = new File(dir, metaclass.getName() + ".meta");
         Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), XMLUtil.ENCODING);

         try
         {
            StringWriter swriter = new StringWriter(0x2000);

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Writing class \"" + metaclass.getName() +
                  "\" to file \"" + file.toString() + "\"");
            }

            new XMLMetadataExporter(swriter).exportMetaclass(metaclass);
            writer.write(XMLUtil.formatXML(swriter.toString()));
         }
         finally
         {
            writer.close();
         }
      }

      String sDescriptorFile = getProperty("meta.descfile");

      if (sDescriptorFile != null && sDescriptorFile.length() != 0)
      {
         StringWriter swriter = new StringWriter(0x2000);
         XMLWriter writer = new XMLWriter(swriter);

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Writing the repository descriptor to file \"" + sDescriptorFile + "\"");
         }

         writer.openElement("Metadata");
         writer.writeAttribute("version", "0");
         writer.closeElement();

         writer.startElement("Classes");

         List metaclassList = new ArrayList(metadata.getMetaclassCount());

         for (Iterator itr = metadata.getMetaclassIterator(); itr.hasNext();)
         {
            metaclassList.add(itr.next());
         }

         Collections.sort(metaclassList, new Comparator()
View Full Code Here


     
      try
      {
         StringWriter sw = new StringWriter(4096);
         new SOAPMarshaller(new InvocationContext(
            new XMLMetadata("", null, null, null, null))).serialize(obj, sw);

         String str = XMLUtil.formatXML(sw.toString());
         StringBuffer buf = new StringBuffer(4096);
         boolean bGenerate = StringUtil.parseBoolean(SysUtil.getConfigProperties().getProperty(REF_GENERATE_PROPERTY, "false"));
        
View Full Code Here

      assertEquals("User", readRequest.getMetaclass().getName());
   }

   public void testEvent() throws Exception
   {
      Metadata metadata = new XMLMetadata(null, null, null, null, null);
      Metaclass metaclass = new Metaclass("Test");
      Attribute attr = new Attribute("attr");
      Argument untyped = new Argument("untyped");
      Argument anytyped = new Argument("anytyped");
      Argument inttyped = new Argument("inttyped");
      Argument listtyped = new Argument("listtyped");
      Event protectedEv = new Event("protected");
      Event publicEv = new Event("public");
      Event staticEv = new Event("static");
      MockServer server = new MockServer(new Object[]{null});
      Timestamp ts =
         SOAPUtil.parseDateTime("1234-05-06T07:08:09", true, true, TimeZone.getDefault());

      attr.setType(Primitive.ANY);
      anytyped.setType(Primitive.ANY);
      inttyped.setType(Primitive.INTEGER);
      listtyped.setType(Primitive.STRING);
      listtyped.setCollection(true);
      protectedEv.setVisibility(Metaclass.PROTECTED);
      publicEv.addArgument(untyped);
      publicEv.addArgument(anytyped);
      publicEv.addArgument(inttyped);
      publicEv.addArgument(listtyped);
      staticEv.addArgument(untyped);
      staticEv.addArgument(anytyped);
      staticEv.addArgument(inttyped);
      staticEv.addArgument(listtyped);
      staticEv.setStatic(true);
      staticEv.setVarArg(true);
      metaclass.addAttribute(attr);
      metaclass.addEvent(protectedEv);
      metaclass.addEvent(publicEv);
      metaclass.addEvent(staticEv);
      metadata.addMetaclass(metaclass);

      // test protected event
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(metadata));
      String sElement = XSDGenerator.computeElementName(protectedEv);
      StringReader reader = new StringReader(
View Full Code Here

      column.setType(Primitive.TIMESTAMP); // something that's not a String
      column.setNullable(false);
      column.setConverter(converter);
      table.setName("TestTable");
      table.addColumn(column);
      dsType.setMetadata(new XMLMetadata(null, null, null, null, null));
      ds.setType(dsType);
      schema.addTable(table);
      schema.setDataSource(ds);
      schema.generateMetaclasses(null, null, null);
      assertFalse(schema.getMetaclass("TestTable").getAttribute("testColumn").isRequired());
View Full Code Here

         RootXMLMessagePartMapping rootMapping = (RootXMLMessagePartMapping)xmlMapping;
         LookupDeque schemaResourceMap = rootMapping.getSchemaResourceMap();

         if (schemaResourceMap != null && message.getMetadata() instanceof XMLMetadata)
         {
            XMLMetadata xmlMetadata = (XMLMetadata)message.getMetadata();
            XMLMetadataHelper helper = xmlMetadata.getHelper();
            StringBuilder buf = new StringBuilder();
            boolean bAppended = false;

            for (Lookup.Iterator itr = schemaResourceMap.iterator(); itr.hasNext(); )
            {
View Full Code Here

   {
      m_loader = loader;
      m_helper = loader.getHelper();

      final VirtualMapping mapping = new VirtualMapping();
      final XMLMetadata metadata = loader.getMetadata();
      final String sURLPrefix = "class:" + metaclass.getName() + ".persistence";
      int nCookie = m_helper.pushMarker(MetadataValidationException.TYPE_NAME, "ServiceMapping");

      m_helper.pushMarker("class", metaclass.getName());

      try
      {
         mapping.setMetaclass(metaclass);
         mapping.setDataSource(dataSource);

         XMLUtil.withFirstChildElement(element, "ServiceMapping",
            true, new XMLUtil.ElementHandler()
         {
            public void handleElement(Element element)
            {
               final ArrayList keyTypeList = new ArrayList(4);

               XMLUtil.withFirstChildElement(element, "KeyParts", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     XMLUtil.forEachChildElement(element, "KeyPart", new XMLUtil.ElementHandler()
                     {
                        public void handleElement(Element element)
                        {
                           keyTypeList.add(Primitive.find(XMLUtil.getReqStringAttr(element, "type")));

                           String sAttributeName = XMLUtil.getStringAttr(element, "attribute");

                           if (sAttributeName != null)
                           {
                              Attribute attribute = metaclass.getAttribute(sAttributeName);
                              VirtualPrimitiveMapping primitiveMapping = new VirtualPrimitiveMapping();

                              primitiveMapping.setObjectKeyPart(keyTypeList.size() - 1);
                              primitiveMapping.setAttribute(attribute);
                              mapping.addAttributeMapping(primitiveMapping);
                              primitiveMapping.validate(metadata, m_helper.getWarnings());
                           }
                        }
                     });

                     mapping.setKey((Primitive[])keyTypeList.toArray(new Primitive[keyTypeList.size()]));
                  }
               });

               XMLUtil.withFirstChildElement(element, "AttributeMappings", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     XMLUtil.forEachChildElement(element, "AttributeMapping", new XMLUtil.ElementHandler()
                     {
                        public void handleElement(Element element)
                        {
                           String sName = XMLUtil.getReqStringAttr(element, "name");
                           int nMaxLength = XMLUtil.getIntAttr(element, "maxLength", 0);
                           final Attribute attribute = metaclass.getAttribute(sName);
                           AttributeMapping attrMapping;

                           if (attribute.getType().isPrimitive())
                           {
                              VirtualPrimitiveMapping primitiveMapping = new VirtualPrimitiveMapping();

                              attrMapping = primitiveMapping;

                              if (element.hasAttribute("attributes"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"attributes", sName, metaclass.getName()});
                              }

                              if (XMLUtil.getBooleanAttr(element, "objectSourceKey", false))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"objectSourceKey", sName, metaclass.getName()});
                              }

                              if (element.hasAttribute("destinationKey"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"destinationKey", sName, metaclass.getName()});
                              }

                              if (nMaxLength != 0)
                              {
                                 if (attribute.getType() != Primitive.BINARY && attribute.getType() != Primitive.STRING)
                                 {
                                    throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                       new Object[]{attribute.getName(), metaclass.getName()});
                                 }

                                 primitiveMapping.setMaxLength(nMaxLength);
                              }
                           }
                           else
                           {
                              final VirtualClassMapping classMapping = new VirtualClassMapping();

                              attrMapping = classMapping;

                              classMapping.setComposition((Pair)m_helper.parse(
                                 XMLUtil.getStringAttr(element, "attributes"),
                                 true, null, null, metadata.getGlobalEnvironment()
                              ));

                              final boolean bObjectSourceKey = XMLUtil.getBooleanAttr(element, "objectSourceKey", false);
                              final String sDestinationKeyName = XMLUtil.getStringAttr(element, "destinationKey");

                              if (nMaxLength != 0)
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }

                              loader.addPersistenceMappingFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    Metaclass type = (Metaclass)attribute.getType();
                                    PersistenceMapping assocClassMapping = type.getPersistenceMapping();

                                    if (assocClassMapping == null)
                                    {
                                       throw new MetadataException("err.meta.missingAssocPersistenceMapping",
                                          new Object[]{attribute.getName(), metaclass.getName(), type.getName()});
                                    }

                                    classMapping.setSourceKey((bObjectSourceKey) ? mapping.getObjectKey() : new VirtualKey(attribute));
                                    classMapping.setDestinationKey(assocClassMapping.addForeignKey(sDestinationKeyName, classMapping));
                                 }
                              });

                              loader.addComponentFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    classMapping.validate(metadata, m_helper.getWarnings());
                                 }
                              });
                           }

                           attrMapping.setAttribute(attribute);
                           mapping.addAttributeMapping(attrMapping);
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "SortKeys", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     XMLUtil.forEachChildElement(element, "SortKey", new XMLUtil.ElementHandler()
                     {
                        public void handleElement(Element element)
                        {
                           mapping.addSortKey(
                              (Pair)m_helper.parse(XMLUtil.getReqStringAttr(element, "attributes"), true,
                                 mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()),
                              XMLUtil.getBooleanAttr(element, "unique", false)
                           );
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "ReadMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final ReadMapping readMapping = mapping.getReadMapping();

                     XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
                     {
                        private int m_nOrdinal = 0;

                        public void handleElement(Element element)
                        {
                           final String sReadPrefix = sURLPrefix + ".read." + m_nOrdinal;
                           Object whereExpr = m_helper.parse(
                              XMLUtil.getStringAttr(element, "where"),
                              false, sReadPrefix + "$where", mapping.getTextPositionMap(), Symbol.ELSE, metadata.getGlobalEnvironment()
                           );
                           Pair variables = (Pair)m_helper.parse(
                              XMLUtil.getStringAttr(element, "variables"),
                              true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
                           );
                           final ReadMappingCase readMappingCase = new ReadMappingCase();

                           readMappingCase.setWhere(whereExpr);
                           readMappingCase.setVariables(variables);

                           XMLUtil.withFirstChildElement(element, "Read", true, new XMLUtil.ElementHandler()
                           {
                              public void handleElement(Element element)
                              {
                                 readMappingCase.setReadScript(loadScript(element, sReadPrefix + "$read", mapping.getTextPositionMap()));
                              }
                           });

                           XMLUtil.withFirstChildElement(element, "Close", false, new XMLUtil.ElementHandler()
                           {
                              public void handleElement(Element element)
                              {
                                 readMappingCase.setCloseScript(loadScript(element, sReadPrefix + "$close", mapping.getTextPositionMap()));
                              }
                           });

                           readMapping.addCase(readMappingCase);
                           m_nOrdinal += 1;
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "CreateMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final WorkMapping operation = new WorkMapping(metaclass);

                     operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
                     operation.setScript(loadScript(element, sURLPrefix + ".create", mapping.getTextPositionMap()));
                     mapping.setCreateMapping(operation);
                  }
               });

               XMLUtil.withFirstChildElement(element, "UpdateMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final UpdateMapping updateMapping = new UpdateMapping(mapping);

                     XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
                     {
                        private int m_nOrdinal = 0;

                        public void handleElement(Element element)
                        {
                           final UpdateMappingCase update = new UpdateMappingCase(metaclass);

                           update.setBatch(XMLUtil.getBooleanAttr(element, "batch", update.isBatch()));
                           update.setDirty(XMLUtil.getBooleanAttr(element, "dirty", update.isDirty()));
                           update.setFull(XMLUtil.getBooleanAttr(element, "full", update.isFull()));

                           Pair attributes = (Pair)m_helper.parse(
                              XMLUtil.getStringAttr(element, "attributes"),
                              true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
                           );

                           update.setScript(loadScript(element, sURLPrefix + ".update." + m_nOrdinal, mapping.getTextPositionMap()));
                           updateMapping.addCase(update, attributes);
                           m_nOrdinal += 1;
                        }
                     });

                     mapping.setUpdateMapping(updateMapping);
                  }
               });

               XMLUtil.withFirstChildElement(element, "DeleteMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final WorkMapping operation = new WorkMapping(metaclass);

                     operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
                     operation.setScript(loadScript(element, sURLPrefix + ".delete", mapping.getTextPositionMap()));
                     mapping.setDeleteMapping(operation);
                  }
               });

               // Key Generator
               final String sKeyGeneratorName = XMLUtil.getStringAttr(element, "keyGenerator");

               if (sKeyGeneratorName != null)
               {
                  loader.addComponentFixup(new ContextFixup(m_helper)
                  {
                     public void fixup()
                     {
                        mapping.setKeyGenerator(metadata.getComponent(sKeyGeneratorName));
                     }
                  });
               }

               mapping.setDerived(XMLUtil.getBooleanAttr(element, "derived", mapping.isDerived()));
View Full Code Here

                     defaultsMap,
                     '/'));
      assertEquals("[non-collection:default-value]", output.toString());

      // set schema.getMetadata().isTestEnvironment() return value for test
      XMLMetadata metadata = new XMLMetadata(null, null, null, null, null);
      DataSourceType dsType = new DataSourceType(null);
      DataSource ds = new DataSource(null) {};

      dsType.setMetadata(metadata);
      ds.setType(dsType);
      schema.setDataSource(ds);

      // iftest enabled
      metadata.setTestEnvironment(true);
      output.getBuffer().setLength(0);
      IOUtil.copy(output,
                  new SQLSchemaManager.DatabaseTemplateSubstReader(
                     new StringReader("[${iftest:${valid-key}}]"),
                     schema,
                     valueMap,
                     defaultsMap,
                     '/'));
      assertEquals("[valid-value]", output.toString());

      // iftest disabled
      metadata.setTestEnvironment(false);
      output.getBuffer().setLength(0);
      IOUtil.copy(output,
                  new SQLSchemaManager.DatabaseTemplateSubstReader(
                     new StringReader("[${iftest:${valid-key}}]"),
                     schema,
View Full Code Here

   public void testViewScriptUpgradeMismtch()
   {
      Upgrade upgrade = new Upgrade(null);
      RelationalSchemaUpgrade version = new RelationalSchemaUpgrade("test");
      XMLMetadata metadata = new XMLMetadata(null, null, null, null, null);
      RelationalDatabase ds = new RelationalDatabase(null);
      RelationalSchema schema = new RelationalSchema();
      CreateTableStep step = new CreateTableStep(); // only step that can populate ViewScript
      Table table = new Table(schema);
      SQLScript finalScript = new SQLScript();
      SQLScript upgradeScript = new SQLScript();
      SQLStatement finalStmt = new SQLStatement();
      SQLStatement upgradeStmt = new SQLStatement();

      upgradeStmt.addAdapter("*", m_database.getSchema().getDataSource().getType());
      finalStmt.addAdapter("*", m_database.getSchema().getDataSource().getType());
      upgradeStmt.setSQL("upgrade view SQL");
      finalStmt.setSQL("final view SQL");
      upgradeScript.addStatement(upgradeStmt);
      finalScript.addStatement(finalStmt);
      table.setName("testTable");
      table.setType(Table.VIEW);
      step.setName(table.getName());
      step.setType(table.getType());
      step.setViewScript(upgradeScript);
      schema.addTable(table);
      schema.setDataSource(ds);
      ds.setAdapter(m_database.getSchema().getDataSource().getAdapter());
      ds.setSchema(schema);
      ds.setType(new DataSourceType(null));
      ds.getType().setMetadata(metadata);
      version.setDataSource(ds);
      version.addStep(step);
      metadata.setVersion(version.getName());
      upgrade.setMetadata(metadata);
      upgrade.addVersion(version);
      table.setViewScript(finalScript);

      try
View Full Code Here

      DataSourceAdapter invalid = new DataSourceAdapter("InvalidAdapter");
      DataSourceAdapter valid = new DataSourceAdapter("ValidAdapter");
      RelationalDatabase ds = new RelationalDatabase("DataSource");
      RelationalSchema schema = new RelationalSchema();
      final Upgrade upgrade = new Upgrade(null);
      XMLMetadata metadata = new XMLMetadata(null, null, null, null, null)
      {
         public Upgrade getUpgrade(String sName) { return upgrade; }
      };
      SQLSchemaManager manager = m_adapter.createSchemaManager();
      RelationalSchemaUpgrade upgradeVersion;

      ds.setAdapter(valid);
      ds.setComponent(new Component("Component"));
      ds.setSchema(schema);
      ds.setType(new DataSourceType("DataSourceType"));
      ds.getType().setMetadata(metadata);
      ds.getType().addAdapter(ds.getAdapter());
      ds.getType().addAdapter(invalid);
      ((RelationalDatabaseFragment)ds.getDefaultFragment()).setDatabase("Database");
      metadata.addDataSource(ds);
      manager.setSQLAppender(manager.new SQLWriterAppender(buf));
      schema.setVersionTable(new Table(schema));
      schema.getVersionTable().setName("VersionTable");
      schema.addTable(schema.getVersionTable());
      upgrade.setMetadata(metadata);

      // setup for first upgrade version
      ExecStep execStep = new ExecStep(); // step lacking match for current adapter
      SQLScript stepScript = new SQLScript();
      SQLStatement stepStmt = new SQLStatement();

      stepStmt.addAdapter(invalid.getName(), ds.getType());
      stepStmt.setSQL("SQLStatement SQL");
      stepScript.addStatement(stepStmt);
      execStep.getScriptHolder().addScript(stepScript);

      // single incompatible step
      metadata.setVersion("1-step");
      upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
      upgradeVersion.addStep(execStep);
      upgradeVersion.setDataSource(ds);
      upgrade.addVersion(upgradeVersion);

      try
      {
         upgrade.validate(null, null); // must fail since an incompatible step "1-step" exists
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      try
      {
         manager.upgrade(schema, null); //must fail since no compatible versions found to start with
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      try
      {
         manager.upgrade(schema, "1-step"); // must fail since step "1-step" is incompatible
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      // setup for second upgrade version
      SupportAdapterStep adapterStep = new SupportAdapterStep();
      CreateTableStep createTableStep = new CreateTableStep(); // step has match for current adapter
      Table table = new Table(schema);
      SQLScript tableScript = new SQLScript();
      SQLStatement tableStmtInvalid = new SQLStatement();
      SQLStatement tableStmtValid = new SQLStatement();

      tableStmtInvalid.addAdapter(invalid.getName(), ds.getType());
      tableStmtInvalid.setSQL("SQLStatement Table SQL Invalid");
      tableStmtValid.addAdapter(ds.getAdapter().getName(), ds.getType());
      tableStmtValid.setSQL("SQLStatement Table SQL Valid");
      tableScript.addStatement(tableStmtValid);
      tableScript.addStatement(tableStmtInvalid);
      tableScript.addStatement(stepStmt);
      table.setName("Table");
      table.setType(Table.VIEW);
      table.setViewScript(tableScript);
      schema.addTable(table);
      createTableStep.setName(table.getName());
      createTableStep.setType(table.getType());
      createTableStep.setViewScript(tableScript);
      adapterStep.setAdapter(invalid);

      // incompatible step -> compatible step
      metadata.setVersion("2-step");
      upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
      upgradeVersion.addStep(adapterStep);
      upgradeVersion.addStep(createTableStep);
      upgradeVersion.setDataSource(ds);
      upgrade.addVersion(upgradeVersion);

      try
      {
         upgrade.validate(null, null); // must fail since an incompatible step "1-step" exists
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      try
      {
         manager.upgrade(schema, null); // must fail since an incompatible step "1-step" exists
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      buf.getBuffer().setLength(0);
      ds.setAdapter(invalid);
      manager.upgrade(schema, "2-step"); // validation of invalid adapter should not be prevented
      AssertUtil.assertContained(tableStmtInvalid.getSQL(), buf.toString());
      ds.setAdapter(valid);

      try
      {
         manager.upgrade(schema, "2-step"); // must fail since validating current adapter from start
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      adapterStep.setAdapter(ds.getAdapter());
      upgrade.validate(null, null); // must pass since adapter validation from "2-step"
      buf.getBuffer().setLength(0);
      manager.upgrade(schema, null); // must upgrade starting from "2-step"
      AssertUtil.assertContained(tableStmtValid.getSQL(), buf.toString());

      // setup for third upgrade version
      CreateColumnStep createColumnStep = new CreateColumnStep(); // step lacking match for adapter
      Column column = new Column("Column", table);
      ColumnOutline outline = new ColumnOutline(column.getName());

      column.setType(Primitive.INTEGER);
      table.addColumn(column);
      outline.setType(column.getType());
      createColumnStep.setOutline(outline);
      createColumnStep.setTableName(table.getName());
      createColumnStep.getScriptHolder().addScript(stepScript);

      // incompatible step -> compatible step -> incompatible step
      metadata.setVersion("3-step");
      upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
      upgradeVersion.addStep(createColumnStep);
      upgradeVersion.setDataSource(ds);
      upgrade.addVersion(upgradeVersion);

      try
View Full Code Here

TOP

Related Classes of nexj.core.meta.xml.XMLMetadata

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.