Package nexj.core.util

Examples of nexj.core.util.Lookup


    * @param context The context.
    */
   protected void serializeValues(Writer writer, InvocationContext context)
   {
      TransferObject tobj = new TransferObject(m_map.size());
      Lookup identityMap = null;

      for (Lookup.Iterator itr = m_map.valueIterator(); itr.hasNext();)
      {
         Object value = itr.next();
         String sName = (String)itr.getKey();
View Full Code Here


      // operations

      public TransferObject getMessage()
      {
         Lookup identityMap = new HashTab();
         TransferObject tobj;

         if (m_accessor instanceof Metaclass)
         {
            tobj = new TransferObject(((Metaclass)m_accessor).getName(), 0);
View Full Code Here

    * @param session Session identifier
    * @return
    */
   public static boolean isKeyExpired(InvocationContext context, Pair key, Object session)
   {
      Lookup sessionMap = (Lookup)context.getGlobalCache().get(key);

      if (sessionMap != null)
      {
         Timestamp tsExpiration = (Timestamp)sessionMap.get(session);

         if (tsExpiration != null && tsExpiration.getTime() > context.getUnitOfWork().getTime())
         {
            return false;
         }
View Full Code Here

         reader.invoke("load", LOAD_ATTRIBUTES);

         // Check if the data has changed
         Pair key = null;
         String sKey = (String)reader.getValue("key");
         Lookup sessionMap = null;

         if (sKey != null)
         {
            key = getLookupKey(m_context, sKey);

            if (!isKeyExpired(m_context, key, reader.getValue("session")))
            {
               return setEmptyResult(reader);
            }
         }

         if (!isEnabled(reader))
         {
            return setEmptyResult(reader);
         }

         Symbol classSym = (Symbol)reader.getValue("class");
         Pair attributes = (Pair)reader.getValue("attributes");
         Object where = reader.getValue("where");
         Pair orderBy = (Pair)reader.getValue("orderBy");
         Number count = (Number)reader.getValue("count");
         Number offset = (Number)reader.getValue("offset");
         Boolean xlock = (Boolean)reader.getValue("xlock");
         Pair bookmark = (Pair)reader.getValue("bookmark");
         Boolean next = (Boolean)reader.getValue("next");
         Boolean inclusive = (Boolean)reader.getValue("inclusive");
         List parentList = (List)reader.getValue("parents");
         Object args = reader.getValue("event");
         Metaclass metaclass = m_context.getMetadata().getMetaclass(classSym.getName());
         Object[] argArray = null;
         Event event = null;

         if (args instanceof Pair)
         {
            argArray = Pair.toArray((Pair)args);
            event = (Event)metaclass.getSelector((Symbol)argArray[0]).getMember(argArray.length - 1);
            argArray[0] = metaclass;

            Argument result = event.getResult();

            if (result != null && !result.getType().isPrimitive())
            {
               metaclass = (Metaclass)result.getType();
            }
         }
         else if (args instanceof String)
         {
            event = (Event)metaclass.getSelector((String)args).getMember(6);
            argArray = new Object[]{metaclass, attributes, where, orderBy, count, offset, xlock};
         }

         metaclass.checkReadAccess(m_context.getPrivilegeSet());

         Pair security = metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet());

         metaclass.checkExpressionAccess(where,  m_context.getPrivilegeSet());

         if (parentList != null)
         {
            List assocList = (List)reader.getValue("associations");
            boolean bConj = false;

            for (int i = parentList.size() - 1; i >= 0; --i)
            {
               Accessor parent = (Accessor)parentList.get(i);
               InstanceList resultList = (InstanceList)parent.getValue("results");

               if (resultList == null || resultList.size() == 0)
               {
                  return setEmptyResult(reader);
               }

               Object assoc = assocList.get(i);

               if (assoc !=  null && !(assoc instanceof Pair))
               {
                  assoc = new Pair(assoc);
               }

               Instance parentInstance = resultList.getInstance(0);
               Metaclass parentMetaclass = parentInstance.getMetaclass();

               // Check for attributes without persistence mappings
               if (i == 0)
               {
                  Metaclass containerMetaclass = parentMetaclass;

                  for (Pair pair = (Pair)assoc; pair != null; pair = pair.getNext())
                  {
                     Attribute attribute = containerMetaclass.findAttribute((Symbol)pair.getHead());

                     if (attribute == null)
                     {
                        break;
                     }

                     attribute.checkReadAccess(m_context.getPrivilegeSet());

                     if (!attribute.isPersistent() &&
                        !attribute.getType().isPrimitive() &&
                        event == null &&
                        ((Metaclass)attribute.getType()).findEvent("read", 6)
                           .findAction("main").getDeclarator().getBase() == null)
                     {
                        if (parentList.size() > 1)
                        {
                           throw new InvalidQueryException("err.persistence.multipleParentsWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        if (where != null || bookmark != null || orderBy != null)
                        {
                           throw new InvalidQueryException("err.persistence.whereWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        resultList = new InstanceArrayList();
                        collectAssociatedInstances((Pair)assoc, parentInstance, resultList);

                        int nOffset = (offset == null) ? 0 : offset.intValue();
                        int nCount = (count == null) ? -1 : count.intValue();

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

                        if (nCount < 0 || nCount > resultList.size() - nOffset)
                        {
                           nCount = resultList.size() - nOffset;

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

                        if (nOffset > 0 || resultList.size() > nCount)
                        {
                           InstanceList list = new InstanceArrayList(nCount);

                           for (int k = 0; k < nCount; ++k)
                           {
                              list.add(resultList.getInstance(k + nOffset), InstanceList.REPLACE | InstanceList.DIRECT);
                           }

                           resultList = list;
                        }

                        if (next != null && !next.booleanValue())
                        {
                           resultList.reverse();
                        }

                        for (int k = 0; k < nCount; ++k)
                        {
                           resultList.getInstance(k).invoke("load", attributes);
                        }

                        reader.setValue("results", resultList);

                        return resultList;
                     }

                     if (attribute.getType().isPrimitive())
                     {
                        break;
                     }

                     containerMetaclass = (Metaclass)attribute.getType();
                  }
               }

               assoc = new Pair(Symbol.ATAT, new Pair(parentMetaclass.getSymbol(), assoc));

               Pair cond = Pair.binary(Symbol.EQ, assoc, parentInstance.getOID());

               if (bConj)
               {
                  where = new Pair(cond, where);
               }
               else if (where != null)
               {
                  where = new Pair(cond, new Pair(where));
                  bConj = true;
               }
               else
               {
                  where = cond;
               }
            }

            if (bConj)
            {
               where = new Pair(Symbol.AND, where);
            }
         }

         // Handle the bookmark
         boolean bNext = true;

         if (next != null && orderBy != null)
         {
            bNext = next.booleanValue();

            if (!bNext)
            {
               // Flip sort order
               Pair pair = orderBy;
               Pair last = orderBy = null;

               for (; pair != null; pair = pair.getNext())
               {
                  Pair head = (Pair)pair.getHead();
                  Pair item = new Pair(new Pair(head.getHead(),
                     Boolean.valueOf(!((Boolean)head.getTail()).booleanValue())));

                  if (last == null)
                  {
                     orderBy = item;
                  }
                  else
                  {
                     last.setTail(item);
                  }

                  last = item;
               }
            }

            // The bookmark has the following format: (value1 ... valueN)
            // If values are missing, then the start or the end of the recordset is
            // retrieved, depending on the value of next (inclusive is ignored in this case)

            if (bookmark != null)
            {
               where = addBookmarkToWhere(where, orderBy, bookmark, inclusive);
            }
         }

         // This takes care of the bookmark attributes access rights
         metaclass.checkOrderByAccess(orderBy, m_context.getPrivilegeSet());
         attributes = Pair.nconc(security, attributes);

         InstanceList resultList;
        
         if (event != null)
         {
            setValue(event, "attributes", argArray, attributes);
            setValue(event, "where", argArray, where);
            setValue(event, "orderBy", argArray, orderBy);

            resultList = (InstanceList)event.invoke(argArray, m_context.getMachine());
         }
         else
         {
            resultList = (InstanceList)metaclass.invoke("read",
               new Object[]{attributes, where, orderBy, count, offset, xlock});
         }

         if (!bNext)
         {
            resultList.reverse();
         }

         reader.setValue("results", resultList);

         if (key != null)
         {
            Lookup cacheMap = null;

            if (sessionMap == null)
            {
               sessionMap = new SoftHashTab(1);
               cacheMap = new HashTab(1);
            }

            synchronized (sessionMap)
            {
               sessionMap.put(reader.getValue("session"),
                  new Timestamp(m_context.getUnitOfWork().getTime() +
                     ((Number)reader.getValue("expiration")).longValue()));
            }

            if (cacheMap != null)
            {
               cacheMap.put(key, sessionMap);
               m_context.getGlobalCache().update(null, cacheMap, m_context.getUnitOfWork().getTime());
            }
         }

         return resultList;
View Full Code Here

         {
            Object rules = metaclass.invoke("loadRules", new Object[]{instance.getMetaclass(), sName});

            constructor = (Function)metaclass.invoke("compile", new Object[]{instance.getMetaclass(), sName, rules});

            Lookup map = new HashTab(1);

            map.put(key, constructor);
            m_context.getGlobalCache().update(null, map, m_context.getUnitOfWork().getTime());
         }
         finally
         {
            m_context.setSecure(bSecureSaved);
View Full Code Here

      schema.setPortable(false);

      try
      {
         Lookup tableMap = new HashTab();

         dbmeta = m_connection.getMetaData();

         // Read the tables

         if (progress != null)
         {
            progress.progress("info.sql.schemaManager.readingTables", null, 0);
         }

         sCatalogName = toDatabaseCase(sCatalogName);
         sSchemaPattern = toDatabaseCase(sSchemaPattern);
         sTablePattern = toDatabaseCase(sTablePattern);

         rs = dbmeta.getTables(sCatalogName, sSchemaPattern, sTablePattern, new String[]{"TABLE"});

         if (progress != null)
         {
            progress.progress("info.sql.schemaManager.readingTables", null, 0.01);
         }

         while (rs.next())
         {
            String sReadCatalogName = rs.getString("TABLE_CAT");
            String sSchemaName = toMetadataCase(rs.getString("TABLE_SCHEM"));
            String sTableName = rs.getString("TABLE_NAME");

            if (!isValidTableName(sTableName))
            {
               continue;
            }

            if (nameSet != null && !nameSet.contains(sTableName))
            {
               continue;
            }

            sTableName = toMetadataCase(sTableName);

            Table table = new Table(schema);

            table.setName(getFullTableName(sSchemaName, sTableName));
            table.setDescription(rs.getString("REMARKS"));
            table.setType(Table.EXTERNAL);
            ++nTableCount;

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Read table \"" + ((sReadCatalogName == null) ? "" : sReadCatalogName) +
                  "." + ((sSchemaName == null) ? "" : sSchemaName) + "." + sTableName +
                  "\" -> \"" + table.getName() + "\"");
            }

            try
            {
               schema.addTable(table);
               tableMap.put(table, new String[]{sReadCatalogName, sSchemaName});
               bPortable &= isPortable(table);
            }
            catch (MetadataException e)
            {
               s_logger.error("Cannot add table \"" + table.getName() + "\"", e);
            }
         }

         rs.close();
         rs = null;

         if (nTableCount == 0)
         {
            nTableCount = 1;
         }

         // Read the columns

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

         // Read the indexes

         nCurTable = 0;

         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();
            String[] names = (String[])tableMap.get(table);
            Index index = null;
            boolean bIgnore = false;
           
            if (progress != null)
            {
               progress.progress("info.sql.schemaManager.readingIndexes", new Object[]{table.getName()},
                  0.20 + 0.50 * (nCurTable++ / nTableCount));
            }

            rs = getIndexInfo(
                    names[0], toDatabaseCase(names[1]), toDatabaseCase(table.getTableName()));

            while (rs.next())
            {
               String sIndexName = toMetadataCase(rs.getString("INDEX_NAME"));

               if (sIndexName == null)
               {
                  continue;
               }
              
               String sColumnName = rs.getString("COLUMN_NAME");
               boolean bAscending = !"D".equals(rs.getString("ASC_OR_DESC"));
               boolean bUnique = !rs.getBoolean("NON_UNIQUE");
               int nType = rs.getInt("TYPE");

               sIndexName = generateIndexName(table.getTableName(), sIndexName, null);

               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Read index column \"" + sIndexName + "." +
                     sColumnName + "\", ascending=" + bAscending);
               }

               if (index != null && !index.getName().equals(sIndexName))
               {
                  if (!bIgnore)
                  {
                     if (addIndex(table, index))
                     {
                        bPortable &= isPortable(index);
                     }
                  }

                  index = null;
                  bIgnore = false;
               }

               if (index == null)
               {
                  index = new Index(sIndexName, (nType == DatabaseMetaData.tableIndexClustered)
                                                ? Index.CLUSTER : Index.BTREE, table);
                  index.setUnique(bUnique);
               }

               if (!isValidColumnName(sColumnName))
               {
                  if (isCaseInsensitive(sColumnName))
                  {
                     sColumnName = getCaseSensitiveName(sColumnName);
                  }
                  else if (isFunctionalIndexSupported())
                  {
                     String sExpr = rs.getString("EXPR");

                     if (sExpr != null && sExpr.length() != 0)
                     {
                        String sName = getCaseSensitiveNameFromExpression(sExpr);

                        if (sName == null)
                        {
                           bIgnore = true;
                        }
                        else
                        {
                           sColumnName = sName;
                        }
                     }
                  }
                  else
                  {
                     bIgnore = true;
                  }
               }

               sColumnName = toMetadataCase(sColumnName);

               if (!bIgnore)
               {
                  try
                  {
                     index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), bAscending));
                  }
                  catch (MetadataException e)
                  {
                     s_logger.error("Cannot find column \"" + sColumnName +
                        "\", ignoring index \"" + sIndexName + "\"", e);
                     bIgnore = true;
                  }
               }
            }

            if (index != null && !bIgnore)
            {
               if (addIndex(table, index))
               {
                  bPortable &= isPortable(index);
               }
            }

            rs.close();
            rs = null;

            // Read the primary key

            rs = getPrimaryKeys(names[0], names[1], table.getTableName());
            index = null;
            bIgnore = false;

            try
            {
               while (rs.next())
               {
                  String sColumnName = toMetadataCase(rs.getString("COLUMN_NAME"));
                 
                  if (index == null)
                  {
                     String sIndexName = rs.getString("PK_NAME");

                     if (sIndexName == null)
                     {
                        sIndexName = table.getName() + ".PK";
                        index = new Index(sIndexName, Index.BTREE, table);
                     }
                     else
                     {
                        sIndexName = generateIndexName(table.getTableName(), sIndexName, "PK");
                        index = table.findIndex(sIndexName);

                        if (index == null)
                        {
                           index = new Index(sIndexName, Index.BTREE, table);
                        }
                        else
                        {
                           table.setPrimaryKey(index);
                           bIgnore = true;

                           break;
                        }
                     }
                  }

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Read primary key column \"" + index.getName() + "." + sColumnName + "\"");
                  }

                  index.setUnique(true);
                  index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), true));
               }
            }
            catch (MetadataException e)
            {
               s_logger.error("Cannot add primary key to table \"" + table.getName() + "\"", e);
               bIgnore = true;
            }

            if (index != null)
            {
               if (!bIgnore)
               {
                  if (addIndex(table, index))
                  {
                     table.setPrimaryKey(index);
                     bPortable &= isPortable(index);
                  }
               }
            }
            else
            {
               for (int i = 0; i < table.getIndexCount(); ++i)
               {
                  index = table.getIndex(i);
                 
                  if (index.isUnique())
                  {
                     table.setPrimaryKey(index);
                    
                     break;
                  }
               }
            }
           
            if (s_logger.isDebugEnabled())
            {
               if (table.getPrimaryKey() != null)
               {
                  s_logger.debug("The primary key of table \"" + table.getName() +
                     "\" is \"" + table.getPrimaryKey().getName() + "\"");
               }
               else
               {
                  s_logger.debug("Table \"" + table.getName() + "\" has no primary key");
               }
            }

            rs.close();
            rs = null;
         }

         // Read the foreign keys

         nCurTable = 0;

         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();
            String[] names = (String[])tableMap.get(table);
            Index index = null;
            boolean bIgnore = false;

            if (progress != null)
            {
View Full Code Here

      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())
         {
View Full Code Here

      SQLAppender outerAppender = m_appender;
      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);
View Full Code Here

            // supported collections
            if ("indexspace".equals(sCollection) ||
                "longspace".equals(sCollection) ||
                "tablespace".equals(sCollection))
            {
               Lookup/*<Object, String>*/ valueMap =
                  new HashTab/*<Object, String>*/(m_schema.getTableCount() + 1);

               putNotNull(valueMap, findValue("indexspace", null), "indexspace"); // add default

               for (Iterator/*<Table>*/ itr = m_schema.getTableIterator(); itr.hasNext();)
               {
                  putNotNull(valueMap, ((Table)itr.next()).getIndexspaceName(), "indexspace");
               }

               putNotNull(valueMap, findValue("longspace", null), "longspace"); // add default

               for (Iterator/*<Table>*/ itr = m_schema.getTableIterator(); itr.hasNext();)
               {
                  putNotNull(valueMap, ((Table)itr.next()).getLongspaceName(), "longspace");
               }

               putNotNull(valueMap, findValue("tablespace", null), "tablespace"); // add default

               for (Iterator/*<Table>*/ itr = m_schema.getTableIterator(); itr.hasNext();)
               {
                  putNotNull(valueMap, ((Table)itr.next()).getTablespaceName(), "tablespace");
               }

               List/*<String>*/ valueList = new ArrayList/*<String>*/(valueMap.size());

               for (Lookup.Iterator/*<Object, String>*/ itr = valueMap.iterator(); itr.hasNext();)
               {
                  if (itr.next() instanceof String && itr.getValue().equals(sCollection))
                  {
                     valueList.add(itr.getKey());
                  }
View Full Code Here

       * Verify that ordinal mapping of parts has all required parts before
       * optional parts begin. Also verify that there are no mappings that
       * map to the same CSV field name.
       */
      boolean bOnRequired = true;
      Lookup fieldNames = new HashTab(m_cachedPartsArray.length);
     
      for (int nPartIndex=0; nPartIndex < m_cachedPartsArray.length; nPartIndex++)
      {
         if (m_cachedPartsArray[nPartIndex] != null)
         {
            if (!bOnRequired && m_cachedPartsArray[nPartIndex].isRequired())
            {
               throw new MetadataException("err.meta.integration.csv.cannotMixRequiredAndOptionalParts",
                  new Object[]{m_cachedPartsArray[nPartIndex].getFullPath()});
            }
           
            bOnRequired = m_cachedPartsArray[nPartIndex].isRequired();
           
            CSVMessagePartMapping partMapping = (CSVMessagePartMapping)m_cachedPartsArray[nPartIndex].getMapping();
            MessagePart partWithSameFieldName = (MessagePart)fieldNames.get(partMapping.getField());
           
            if (partWithSameFieldName != null)
            {
               throw new MetadataException("err.meta.integration.csv.duplicateFieldNames",
                  new Object[]{
                     partWithSameFieldName.getFullPath(),
                     m_cachedPartsArray[nPartIndex].getFullPath(),
                     partMapping.getField()
                  });
            }
            else
            {
               fieldNames.put(partMapping.getField(), m_cachedPartsArray[nPartIndex]);
            }
         }
      }
     
      m_fieldNamePartMap = fieldNames;
View Full Code Here

TOP

Related Classes of nexj.core.util.Lookup

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.