Package nexj.core.util

Examples of nexj.core.util.HashTab2D


         return null;
      }

      if (m_instanceRefMap == null)
      {
         m_instanceRefMap = new HashTab2D(32);
         m_refq = new ReferenceQueue();
      }
      else
      {
         removeStaleReferences();
View Full Code Here


    */
   public void addReplicationFragment(Instance instance, String sFragmentName)
   {
      if (m_replicationSet == null)
      {
         m_replicationSet = new HashTab2D();
      }

      if (sFragmentName == null)
      {
         sFragmentName = "";
View Full Code Here

      {
         dropObject(objArray[i]);
      }

      Lookup2D/*<String, Integer, List<Table>>*/ tableMap =
         new HashTab2D/*<String, Integer, List<Table>>*/(schema.getTableCount());

      if (metadata.isTestEnvironment())
      {
         Upgrade upgrade = metadata.getUpgrade("Main");
         VersionUpgrade version = upgrade.getFirstVersion();
         Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(version);

         version = findFirstVersion(version, stateMap, (RelationalDatabase)schema.getDataSource());

         for (VersionUpgrade u = version; u != null; u = u.getNext())
         {
            if (u instanceof RelationalSchemaUpgrade)
            {
               RelationalSchemaUpgrade rsu = (RelationalSchemaUpgrade)u;

               if (rsu.getDataSource().getSchema() == schema)
               {
                  RelationalSchemaUpgradeState state =
                     (RelationalSchemaUpgradeState)Upgrade.getState(stateMap, u);

                  for (int i = 0, nCount = rsu.getStepCount(); i < nCount; ++i)
                  {
                     rsu.getStep(i).apply(state); // apply every every step off this upgrade
                  }

                  addDropTable(tableMap, state.getSchema()); // add any differing definitions
               }
            }
         }
      }

      // Need to remove tables from schema prior to dropTable() so that dependency resolution works
      // as expected. For this a modifiable RelationalSchema is required.
      addDropTable(tableMap, (RelationalSchema)schema.clone());

      List/*<Table>*/ tableList = new ArrayList/*<Table>*/();

      for (Iterator/*<List<Table>>*/ itr = tableMap.valueIterator(); itr.hasNext();)
      {
         tableList.addAll((Collection)itr.next());
      }

      Collections.sort(tableList, TABLE_COMPARATOR); // sort table array in predictable order
View Full Code Here

         rs = dbmeta.getColumns(sCatalogName, sSchemaPattern, sTablePattern, "%");
         lastTable = null;
         nCurTable = 0;

         Lookup2D caseInsensitiveSet = new HashTab2D(); // Object[Table][String]

         while (rs.next())
         {
            Table table = schema.findTable(
               getFullTableName(toMetadataCase(rs.getString("TABLE_SCHEM")),
                                toMetadataCase(rs.getString("TABLE_NAME"))));

            if (table == null)
            {
               continue;
            }

            if (progress != null && table != lastTable)
            {
               lastTable = table;
               caseInsensitiveSet.clear();
               progress.progress("info.sql.schemaManager.readingColumns", new Object[]{table.getName()},
                  0.05 + 0.15 * (nCurTable++ / nTableCount));
            }

            String sColName = toMetadataCase(rs.getString("COLUMN_NAME"));
            String sName = null;

            if (sColName != null)
            {
               sName = getCaseSensitiveName(sColName);

               if (isCaseInsensitive(sColName))
               {
                  caseInsensitiveSet.put(table, sName, Boolean.TRUE);
               }
            }

            if (!isValidColumnName(sColName))
            {
               continue;
            }

            Column column = new Column(sName, table);

            column.setNullable(rs.getInt("NULLABLE") != DatabaseMetaData.columnNoNulls);
            column.setDescription(rs.getString("REMARKS"));

            String sTypeName = rs.getString("TYPE_NAME");
            int nType = rs.getInt("DATA_TYPE");
            int nPrecision = rs.getInt("COLUMN_SIZE");
            int nScale = rs.getInt("DECIMAL_DIGITS");
            byte nAllocation = Column.FIXED;
            Primitive type = null;
           
            switch (nType)
            {
               case Types.BIGINT:
                  type = Primitive.LONG;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.BINARY:
                  type = Primitive.BINARY;
                  nScale = 0;
                  break;
              
               case Types.BIT:
               case Types.BOOLEAN:
                  type = Primitive.BOOLEAN;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.BLOB:
               case Types.LONGVARBINARY:
                  type = Primitive.BINARY;
                 
                  if (nPrecision <= 0x4000)
                  {
                     nPrecision = Integer.MAX_VALUE;
                  }

                  nScale = 0;
                  nAllocation = (nType == Types.BLOB) ? Column.LOCATOR : Column.VARYING;
                  break;

               case Types.CHAR:
                  sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);

                  if (sTypeName.equals("uniqueidentifier"))
                  {
                     type = Primitive.BINARY;
                     nPrecision = 16;
                     nScale = 0;
                  }
                  else
                  {
                     type = Primitive.STRING;
                     nScale = 0;
                  }

                  break;

               case Types.CLOB:
               case Types.LONGVARCHAR:
                  type = Primitive.STRING;
                    
                  if (nPrecision <= 0x4000)
                  {
                     nPrecision = Integer.MAX_VALUE;
                  }
  
                  nScale = 0;
                  nAllocation = (nType == Types.CLOB) ? Column.LOCATOR : Column.VARYING;
                  break;
              
               case Types.DATE:
               case Types.TIME:
               case Types.TIMESTAMP:
                  type = Primitive.TIMESTAMP;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.DECIMAL:
               case Types.NUMERIC:
                  type = Primitive.DECIMAL;
                 
                  if (nScale == 0 && nPrecision <= 20)
                  {
                     if (nPrecision <= 10)
                     {
                        type = Primitive.INTEGER;

                        if (nPrecision <= 3)
                        {
                           nPrecision = 1;
                        }
                        else if (nPrecision <= 5)
                        {
                           nPrecision = 2;
                        }
                        else
                        {
                           nPrecision = 0;
                        }
                     }
                     else
                     {
                        type = Primitive.LONG;
                        nPrecision = 0;
                     }
                  }

                  break;

               case Types.DOUBLE:
               case Types.FLOAT:
                  type = Primitive.DOUBLE;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.INTEGER:
                  type = Primitive.INTEGER;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.SMALLINT:
                  type = Primitive.INTEGER;
                  nPrecision = 2;
                  nScale = 0;
                  break;

               case Types.TINYINT:
                  type = Primitive.INTEGER;
                  nPrecision = 1;
                  nScale = 0;
                  break;

               case Types.REAL:
                  type = Primitive.FLOAT;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.VARBINARY:
                  type = Primitive.BINARY;
                  nScale = 0;
                  nAllocation = Column.VARYING;
                  break;

               case Types.VARCHAR:
                  type = Primitive.STRING;
                  nScale = 0;
                  nAllocation = Column.VARYING;
                  break;

               default:
                  sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);

                  if (sTypeName.equals("nchar"))
                  {
                     type = Primitive.STRING;
                     nPrecision >>= 1;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("nvarchar2") || sTypeName.equals("nvarchar"))
                  {
                     type = Primitive.STRING;
                     nPrecision >>= 1;
                     nScale = 0;
                     nAllocation = Column.VARYING;
                  }
                  else if (sTypeName.equals("binary_double"))
                  {
                     type = Primitive.DOUBLE;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("binary_float"))
                  {
                     type = Primitive.FLOAT;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.startsWith("timestamp"))
                  {
                     type = Primitive.TIMESTAMP;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("nclob") || sTypeName.equals("clob"))
                  {
                     type = Primitive.STRING;
                    
                     if (nPrecision <= 0x4000)
                     {
                        nPrecision = Integer.MAX_VALUE;
                     }
  
                     nScale = 0;
                     nAllocation = Column.LOCATOR;
                  }
                  else if (sTypeName.equals("blob"))
                  {
                     type = Primitive.BINARY;
                       
                     if (nPrecision <= 0x4000)
                     {
                        nPrecision = Integer.MAX_VALUE;
                     }
     
                     nScale = 0;
                     nAllocation = Column.LOCATOR;
                  }
              
                  break;
            }

            if (nPrecision < 0)
            {
               nPrecision = 0;
            }

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Read column \"" + table.getName() + "." + column.getName() + "\" " +
                  sTypeName + "(" + rs.getInt("COLUMN_SIZE") + "," + rs.getInt("DECIMAL_DIGITS") +
                  "), SQLType=" + nType + " -> " + ((type == null) ? "ignored: unsupported type" : type.getName() +
                  "(" + nPrecision + "," + nScale + "), allocation=" + nAllocation));
            }

            if (type != null)
            {
               column.setType(type);
               column.setPrecision(nPrecision);
               column.setScale(nScale);
               column.setAllocation(nAllocation);

               try
               {
                  table.addColumn(column);
                  bPortable &= isPortable(column);
               }
               catch (MetadataException e)
               {
                  s_logger.error("Cannot add column \"" + column.getName() + "\"", e);
               }
            }
         }

         rs.close();
         rs = null;

         // Set the case-sensitive columns

         for (Iterator tableItr = tableMap.iterator(); tableItr.hasNext();)
         {
            Table table = (Table)tableItr.next();

            for (int i = 0; i < table.getColumnCount(); ++i)
            {
               Column column = table.getColumn(i);

               if (!caseInsensitiveSet.contains(table, column.getName()))
               {
                  column.setCaseInsensitive(false);
               }
            }
         }
View Full Code Here

      Field[] fieldArray = XSDSchema.class.getDeclaredFields();
      final int PUBLIC_FINAL_STATIC = Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC;

      try
      {
         m_itemMap = new HashTab2D(fieldArray.length);

         for (int i = 0; i < fieldArray.length; i++)
         {
            Field field = fieldArray[i];
View Full Code Here

       */
      public ObjectUnmarshaller(String sURI, String sType, ObjectAccessor[] accessorArray)
      {
         super(sURI, sType);
         m_accessorArray = accessorArray;
         m_accessorMap = new HashTab2D(accessorArray.length);

         for (int i = 0; i < accessorArray.length; ++i)
         {
            ObjectAccessor accessor = m_accessorArray[i];

View Full Code Here

         throw new IllegalArgumentException("Missing name on " + item + " being added to " + this);
      }

      if (m_itemMap == null)
      {
         m_itemMap = new HashTab2D();
      }

      if (m_itemMap.put(item.getName(), getTypeKey(item.getItemType()), item) != null)
      {
         throw new IllegalStateException("Redefinition of " + item + " in " + this);
View Full Code Here

      //  because '0' is end-of-list marker) @see nexj.core.rpc.soap.SOAPUnmarshaller#m_fixupArray
      m_nFixupCount = 2;
      m_nTop = 0;
      m_bEmpty = false;
      m_bIgnoreRoot = false;
      m_metaRefMap = new HashTab2D/*<String, OID, Integer>*/();
      m_fixupArray = new Object[48];
      m_indexArray = new int[48];
      m_arrayUnmshMap = new HashTab();
      m_idMap = new HashTab(); // object to map an xml:id -> id in m_fixupArray
      m_nsMap = new HashTab();
View Full Code Here

    */
   public Element mergeDescriptorElements(List baseList, List rootList) throws MetadataException
   {
      Document doc = XMLUtil.parse(new StringReader("<Metadata/>"));
      Element descriptorElement = doc.getDocumentElement();
      Lookup2D resourceMap = new HashTab2D();
      Lookup refNameMap = new LinkedHashTab();
      Lookup mixinMap = new LinkedHashTab();
      String sBaseNamespace = null;
      String sBaseVersion = null;
      String sBaseChecksum = null;
      String sBaseName = null;
      String sBaseRevision = null;
      String sBaseDescription = null;
      String sBaseCoreVersion = null;
      String sBaseModule = null;
      String sBaseOverride = null;
      String sRootNamespace = null;
      String sRootVersion = null;
      String sRootDescription = null;
      String sRootName = null;
      String sRootRevision = null;
      String sRootCoreVersion = null;
      String sRootModule = null;
      String sRootOverride = null;
      Element baseElement = getDescriptorElement(false);
      Element rootElement = getDescriptorElement(true);

      if (baseElement != null)
      {
         sBaseNamespace = XMLUtil.getReqStringAttr(baseElement, "namespace");
         sBaseVersion = XMLUtil.getReqStringAttr(baseElement, "version");
         sBaseName = XMLUtil.getReqStringAttr(baseElement, "name");
         sBaseRevision = XMLUtil.getReqStringAttr(baseElement, "revision");
         sBaseCoreVersion = XMLUtil.getStringAttr(baseElement, "coreVersion");
         sBaseModule = normalizeScope(XMLUtil.getStringAttr(baseElement, "module"));
         sBaseOverride = XMLUtil.getStringAttr(baseElement, "override");
         sBaseDescription = XMLUtil.getStringAttr(baseElement, "description");
         sBaseChecksum = getChecksum(false);
         addMixinElements(mixinMap, baseElement);
         addResourceElements(resourceMap, refNameMap, baseElement);
      }

      if (rootElement != null)
      {
         sRootNamespace = XMLUtil.getReqStringAttr(rootElement, "namespace");
         sRootVersion = XMLUtil.getReqStringAttr(rootElement, "version");
         sRootName = XMLUtil.getReqStringAttr(rootElement, "name");
         sRootRevision = XMLUtil.getReqStringAttr(rootElement, "revision");
         sRootCoreVersion = XMLUtil.getStringAttr(rootElement, "coreVersion");
         sRootModule = normalizeScope(XMLUtil.getStringAttr(rootElement, "module"));
         sRootOverride = XMLUtil.getStringAttr(rootElement, "override");
         sRootDescription = XMLUtil.getStringAttr(rootElement, "description");
         addMixinElements(mixinMap, rootElement);
         addResourceElements(resourceMap, refNameMap, rootElement);

         if (baseElement == null)
         {
            sBaseNamespace = XMLUtil.getStringAttr(rootElement, "baseNamespace");
            sBaseVersion = XMLUtil.getStringAttr(rootElement, "baseVersion");
            sBaseChecksum = XMLUtil.getStringAttr(rootElement, "baseChecksum");
         }
      }
      else
      {
         sRootNamespace = sBaseNamespace;
         sRootVersion = sBaseVersion;
         sRootName = sBaseName;
         sRootRevision = sBaseRevision;
         sRootModule = sBaseModule;
         sRootOverride = sBaseOverride;
         sRootDescription = sBaseDescription;
         sBaseNamespace = null;
         sBaseVersion = null;
         sBaseChecksum = null;
         sBaseModule = null;
         sBaseOverride = null;
         sBaseDescription = null;
      }

      if (sRootCoreVersion == null)
      {
         sRootCoreVersion = sBaseCoreVersion;
      }

      if (sRootNamespace != null)
      {
         descriptorElement.setAttribute("name", sRootName);
         descriptorElement.setAttribute("revision", sRootRevision);
         descriptorElement.setAttribute("namespace", sRootNamespace);
         descriptorElement.setAttribute("version", sRootVersion);

         if (sRootCoreVersion != null)
         {
            descriptorElement.setAttribute("coreVersion", sRootCoreVersion);
         }

         if (sRootModule != null)
         {
            descriptorElement.setAttribute("module", sRootModule);
         }

         if (sRootOverride != null)
         {
            descriptorElement.setAttribute("override", sRootOverride);
         }

         if (sRootDescription != null)
         {
            descriptorElement.setAttribute("description", sRootDescription);
         }
      }

      if (sBaseNamespace != null)
      {
         descriptorElement.setAttribute("baseNamespace", sBaseNamespace);
         descriptorElement.setAttribute("baseVersion", sBaseVersion);
         descriptorElement.setAttribute("baseChecksum", sBaseChecksum);
      }

      // Insert the mixin elements
      Element mixinsElement = doc.createElement("Mixins");

      descriptorElement.appendChild(mixinsElement);

      for (Iterator itr = mixinMap.valueIterator(); itr.hasNext(); )
      {
         Element mixinElement = XMLUtil.addChildElement(mixinsElement, null, "Mixin");
         NamedNodeMap map = ((Element)itr.next()).getAttributes();

         for (int i = 0, n = map.getLength(); i < n; ++i)
         {
            Attr attr = (Attr)map.item(i);

            mixinElement.setAttribute(attr.getName(), attr.getValue());
         }
      }

      // Instantiate all the container elements and place them in a map by name
      Lookup refMap = new HashTab(refNameMap.size());

      for (Lookup.Iterator itr = refNameMap.iterator(); itr.hasNext();)
      {
         Element element = doc.createElement((String)itr.next());

         descriptorElement.appendChild(element);
         refMap.put(itr.getKey(), element);
      }

      // Insert the reference elements
      for (Lookup2D.Iterator itr = resourceMap.valueIterator(); itr.hasNext();)
      {
         Element element = (Element)itr.next();
         Element refElement = doc.createElement((String)refNameMap.get(itr.getKey1()));

         ((Element)refMap.get(itr.getKey1())).appendChild(refElement);
View Full Code Here

TOP

Related Classes of nexj.core.util.HashTab2D

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.