Package org.apache.manifoldcf.jdbc

Examples of org.apache.manifoldcf.jdbc.IDynamicResultSet


    // Do the substitution
    ArrayList paramList = new ArrayList();
    StringBuilder sb = new StringBuilder();
    substituteQuery(ts.idQuery,vm,sb,paramList);

    IDynamicResultSet idSet;

    String queryText = sb.toString();
    long startQueryTime = System.currentTimeMillis();
    // Contract for IDynamicResultset indicates that if successfully obtained, it MUST
    // be closed.
    try
    {
      idSet = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ServiceInterruption e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }

    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = idSet.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad seed query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          activities.addSeedDocument(idValue);
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      idSet.close();
    }
  }
View Full Code Here


      versionsReturned[j] = "";
      j++;
    }

    // Fire off the query!
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);
      // Now, go through resultset
      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad version query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          o = row.getValue(JDBCConstants.versionReturnColumnName);
          String versionValue;
          // Null version is OK; make it a ""
          if (o == null)
            versionValue = "";
          else
          {
            // A real version string!  Any acls must be added to the front, if they are present...
            sb = new StringBuilder();
            packList(sb,acls,'+');
            if (acls.length > 0)
            {
              sb.append('+');
              pack(sb,defaultAuthorityDenyToken,'+');
            }
            else
              sb.append('-');

            sb.append(JDBCConnection.readAsString(o)).append("=").append(ts.dataQuery);
            versionValue = sb.toString();
          }
          // Versions that are "", when processed, will have their acls fetched at that time...
          versionsReturned[((Integer)map.get(idValue)).intValue()] = versionValue;
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      result.close();
    }

    return versionsReturned;
  }
View Full Code Here

      }
      i++;
    }

    // Execute the query
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad document query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String id = JDBCConnection.readAsString(o);
          String version = (String)map.get(id);
          if (version != null)
          {
            // This document was marked as "not scan only", so we expect to find it.
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("JDBC: Document data result found for '"+id+"'");
            o = row.getValue(JDBCConstants.urlReturnColumnName);
            if (o != null)
            {
              // This is not right - url can apparently be a BinaryInput
              String url = JDBCConnection.readAsString(o);
              boolean validURL;
              try
              {
                // Check to be sure url is valid
                new java.net.URI(url);
                validURL = true;
              }
              catch (java.net.URISyntaxException e)
              {
                validURL = false;
              }

              if (validURL)
              {
                // Process the document itself
                Object contents = row.getValue(JDBCConstants.dataReturnColumnName);
                // Null data is allowed; we just ignore these
                if (contents != null)
                {
                  // We will ingest something, so remove this id from the map in order that we know what we still
                  // need to delete when all done.
                  map.remove(id);
                  String contentType;
                  o = row.getValue(JDBCConstants.contentTypeReturnColumnName);
                  if (o != null)
                    contentType = JDBCConnection.readAsString(o);
                  else
                    contentType = null;
                 
                  if (contentType == null || activities.checkMimeTypeIndexable(contentType))
                  {
                    if (contents instanceof BinaryInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("application/octet-stream");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      BinaryInput bi = (BinaryInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = bi.getStream();
                        try
                        {
                          rd.setBinary(is,bi.getLength());
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else if (contents instanceof CharacterInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("text/plain; charset=utf-8");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      CharacterInput ci = (CharacterInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = ci.getUtf8Stream();
                        try
                        {
                          rd.setBinary(is,ci.getUtf8StreamLength());
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else
                    {
                      // Turn it into a string, and then into a stream
                      String value = contents.toString();
                      try
                      {
                        byte[] bytes = value.getBytes("utf-8");
                        RepositoryDocument rd = new RepositoryDocument();

                        // Default content type is text/plain for character data
                        if (contentType == null)
                          rd.setMimeType("text/plain");
                        else
                          rd.setMimeType(contentType);
                       
                        applyAccessTokens(rd,version,spec);
                        applyMetadata(rd,row);

                        InputStream is = new ByteArrayInputStream(bytes);
                        try
                        {
                          rd.setBinary(is,bytes.length);
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                  }
                  else
                    Logging.connectors.warn("JDBC: Document '"+id+"' excluded because of mime type - skipping");
                }
                else
                  Logging.connectors.warn("JDBC: Document '"+id+"' seems to have null data - skipping");
              }
              else
                Logging.connectors.warn("JDBC: Document '"+id+"' has an illegal url: '"+url+"' - skipping");
            }
            else
              Logging.connectors.warn("JDBC: Document '"+id+"' has a null url - skipping");
          }
        }
        finally
        {
          row.close();
        }
      }
      // Now, go through the original id's, and see which ones are still in the map.  These
      // did not appear in the result and are presumed to be gone from the database, and thus must be deleted.
      i = 0;
      while (i < documentIdentifiers.length)
      {
        if (!scanOnly[i])
        {
          String documentIdentifier = documentIdentifiers[i];
          if (map.get(documentIdentifier) != null)
          {
            // This means we did not see it (or data for it) in the result set.  Delete it!
            activities.deleteDocument(documentIdentifier,versions[i]);
          }
        }
        i++;
      }

    }
    finally
    {
      result.close();
    }
  }
View Full Code Here

    // Do the substitution
    ArrayList paramList = new ArrayList();
    StringBuilder sb = new StringBuilder();
    substituteQuery(ts.idQuery,vm,sb,paramList);

    IDynamicResultSet idSet;

    String queryText = sb.toString();
    long startQueryTime = System.currentTimeMillis();
    // Contract for IDynamicResultset indicates that if successfully obtained, it MUST
    // be closed.
    try
    {
      idSet = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ServiceInterruption e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }

    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = idSet.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad seed query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          activities.addSeedDocument(idValue);
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      idSet.close();
    }
  }
View Full Code Here

      versionsReturned[j] = "";
      j++;
    }

    // Fire off the query!
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);
      // Now, go through resultset
      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad version query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          o = row.getValue(JDBCConstants.versionReturnColumnName);
          String versionValue;
          // Null version is OK; make it a ""
          if (o == null)
            versionValue = "";
          else
          {
            // A real version string!  Any acls must be added to the front, if they are present...
            sb = new StringBuilder();
            packList(sb,acls,'+');
            if (acls.length > 0)
            {
              sb.append('+');
              pack(sb,defaultAuthorityDenyToken,'+');
            }
            else
              sb.append('-');

            sb.append(JDBCConnection.readAsString(o)).append("=").append(ts.dataQuery);
            versionValue = sb.toString();
          }
          // Versions that are "", when processed, will have their acls fetched at that time...
          versionsReturned[((Integer)map.get(idValue)).intValue()] = versionValue;
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      result.close();
    }

    return versionsReturned;
  }
View Full Code Here

      }
      i++;
    }

    // Execute the query
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad document query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String id = JDBCConnection.readAsString(o);
          String version = (String)map.get(id);
          if (version != null)
          {
            // This document was marked as "not scan only", so we expect to find it.
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("JDBC: Document data result found for '"+id+"'");
            o = row.getValue(JDBCConstants.urlReturnColumnName);
            if (o != null)
            {
              // This is not right - url can apparently be a BinaryInput
              String url = JDBCConnection.readAsString(o);
              boolean validURL;
              try
              {
                // Check to be sure url is valid
                new java.net.URI(url);
                validURL = true;
              }
              catch (java.net.URISyntaxException e)
              {
                validURL = false;
              }

              if (validURL)
              {
                // Process the document itself
                Object contents = row.getValue(JDBCConstants.dataReturnColumnName);
                // Null data is allowed; we just ignore these
                if (contents != null)
                {
                  // We will ingest something, so remove this id from the map in order that we know what we still
                  // need to delete when all done.
                  map.remove(id);
                  String contentType;
                  o = row.getValue(JDBCConstants.contentTypeReturnColumnName);
                  if (o != null)
                    contentType = JDBCConnection.readAsString(o);
                  else
                    contentType = null;
                 
                  if (contentType == null || activities.checkMimeTypeIndexable(contentType))
                  {
                    if (contents instanceof BinaryInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("application/octet-stream");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      BinaryInput bi = (BinaryInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = bi.getStream();
                        try
                        {
                          rd.setBinary(is,bi.getLength());
                          activities.ingestDocumentWithException(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else if (contents instanceof CharacterInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("text/plain; charset=utf-8");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      CharacterInput ci = (CharacterInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = ci.getUtf8Stream();
                        try
                        {
                          rd.setBinary(is,ci.getUtf8StreamLength());
                          activities.ingestDocumentWithException(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else
                    {
                      // Turn it into a string, and then into a stream
                      String value = contents.toString();
                      try
                      {
                        byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
                        RepositoryDocument rd = new RepositoryDocument();

                        // Default content type is text/plain for character data
                        if (contentType == null)
                          rd.setMimeType("text/plain");
                        else
                          rd.setMimeType(contentType);
                       
                        applyAccessTokens(rd,version,spec);
                        applyMetadata(rd,row);

                        InputStream is = new ByteArrayInputStream(bytes);
                        try
                        {
                          rd.setBinary(is,bytes.length);
                          activities.ingestDocumentWithException(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                  }
                  else
                    Logging.connectors.warn("JDBC: Document '"+id+"' excluded because of mime type - skipping");
                }
                else
                  Logging.connectors.warn("JDBC: Document '"+id+"' seems to have null data - skipping");
              }
              else
                Logging.connectors.warn("JDBC: Document '"+id+"' has an illegal url: '"+url+"' - skipping");
            }
            else
              Logging.connectors.warn("JDBC: Document '"+id+"' has a null url - skipping");
          }
        }
        finally
        {
          row.close();
        }
      }
      // Now, go through the original id's, and see which ones are still in the map.  These
      // did not appear in the result and are presumed to be gone from the database, and thus must be deleted.
      i = 0;
      while (i < documentIdentifiers.length)
      {
        if (!scanOnly[i])
        {
          String documentIdentifier = documentIdentifiers[i];
          if (map.get(documentIdentifier) != null)
          {
            // This means we did not see it (or data for it) in the result set.  Delete it!
            activities.deleteDocument(documentIdentifier);
          }
        }
        i++;
      }

    }
    finally
    {
      result.close();
    }
  }
View Full Code Here

      // Find user id
      ArrayList paramList = new ArrayList();
      StringBuilder sb = new StringBuilder();
      substituteQuery(idQuery, vm, sb, paramList);

      IDynamicResultSet idSet;
      try {
        idSet = connection.executeUncachedQuery(sb.toString(),paramList,-1);
      }
      catch (ServiceInterruption e)
      {
        return RESPONSE_UNREACHABLE;
      }
      catch (ManifoldCFException e)
      {
        throw e;
      }

      String uid;
      try {
        IDynamicResultRow row = idSet.getNextRow();
        if (row == null)
          return RESPONSE_USERNOTFOUND;
        try
        {
          Object oUid = row.getValue(JDBCConstants.idReturnColumnName);
          if (oUid == null)
            throw new ManifoldCFException("Bad id query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          uid = JDBCConnection.readAsString(oUid);
        }
        finally
        {
          row.close();
        }
      } finally {
        idSet.close();
      }

      if (uid.isEmpty()) {
        return RESPONSE_USERNOTFOUND;
      }

      // now check tokens
      vm = new VariableMap();
      addConstant(vm, JDBCConstants.tokenReturnVariable, JDBCConstants.tokenReturnColumnName);
      addVariable(vm, JDBCConstants.userNameVariable, userName);
      addVariable(vm, JDBCConstants.userIDVariable, uid);
      sb = new StringBuilder();
      paramList = new ArrayList();
      substituteQuery(tokenQuery, vm, sb, paramList);
     
      try {
        idSet = connection.executeUncachedQuery(sb.toString(),paramList,-1);
      }
      catch (ServiceInterruption e)
      {
        return RESPONSE_UNREACHABLE;
      }
      catch (ManifoldCFException e)
      {
        throw e;
      }

      ArrayList<String> tokenArray = new ArrayList<String>();
      try {
        while (true)
        {
          IDynamicResultRow row = idSet.getNextRow();
          if (row == null)
            break;
          try
          {
            Object oToken = row.getValue(JDBCConstants.tokenReturnColumnName);
            if (oToken == null)
              throw new ManifoldCFException("Bad token query; doesn't return $(TOKENCOLUMN) column.  Try using quotes around $(TOKENCOLUMN) variable, e.g. \"$(TOKENCOLUMN)\".");
            String token = JDBCConnection.readAsString(oToken);

            if (!token.isEmpty()) {
              tokenArray.add(token);
            }
          }
          finally
          {
            row.close();
          }
        }
      } finally {
        idSet.close();
      }
      return new AuthorizationResponse(tokenArray.toArray(new String[0]), AuthorizationResponse.RESPONSE_OK);
    }
    catch (ServiceInterruption e)
    {
View Full Code Here

    // Do the substitution
    ArrayList paramList = new ArrayList();
    StringBuilder sb = new StringBuilder();
    substituteQuery(ts.idQuery,vm,sb,paramList);

    IDynamicResultSet idSet;

    String queryText = sb.toString();
    long startQueryTime = System.currentTimeMillis();
    // Contract for IDynamicResultset indicates that if successfully obtained, it MUST
    // be closed.
    try
    {
      idSet = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ServiceInterruption e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }

    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startQueryTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = idSet.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad seed query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          activities.addSeedDocument(idValue);
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      idSet.close();
    }
  }
View Full Code Here

      versionsReturned[j] = "";
      j++;
    }

    // Fire off the query!
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);
      // Now, go through resultset
      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad version query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String idValue = JDBCConnection.readAsString(o);
          o = row.getValue(JDBCConstants.versionReturnColumnName);
          String versionValue;
          // Null version is OK; make it a ""
          if (o == null)
            versionValue = "";
          else
          {
            // A real version string!  Any acls must be added to the front, if they are present...
            sb = new StringBuilder();
            packList(sb,acls,'+');
            if (acls.length > 0)
            {
              sb.append('+');
              pack(sb,defaultAuthorityDenyToken,'+');
            }
            else
              sb.append('-');

            sb.append(JDBCConnection.readAsString(o)).append("=").append(ts.dataQuery);
            versionValue = sb.toString();
          }
          // Versions that are "", when processed, will have their acls fetched at that time...
          versionsReturned[((Integer)map.get(idValue)).intValue()] = versionValue;
        }
        finally
        {
          row.close();
        }
      }
    }
    finally
    {
      result.close();
    }

    return versionsReturned;
  }
View Full Code Here

      }
      i++;
    }

    // Execute the query
    IDynamicResultSet result;
    String queryText = sb.toString();
    long startTime = System.currentTimeMillis();
    // Get a dynamic resultset.  Contract for dynamic resultset is that if
    // one is returned, it MUST be closed, or a connection will leak.
    try
    {
      result = connection.executeUncachedQuery(queryText,paramList,-1);
    }
    catch (ManifoldCFException e)
    {
      // If failure, record the failure.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
      throw e;
    }
    try
    {
      // If success, record that too.
      activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY, null,
        createQueryString(queryText,paramList), "OK", null, null);

      while (true)
      {
        IDynamicResultRow row = result.getNextRow();
        if (row == null)
          break;
        try
        {
          Object o = row.getValue(JDBCConstants.idReturnColumnName);
          if (o == null)
            throw new ManifoldCFException("Bad document query; doesn't return $(IDCOLUMN) column.  Try using quotes around $(IDCOLUMN) variable, e.g. \"$(IDCOLUMN)\".");
          String id = JDBCConnection.readAsString(o);
          String version = (String)map.get(id);
          if (version != null)
          {
            // This document was marked as "not scan only", so we expect to find it.
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("JDBC: Document data result found for '"+id+"'");
            o = row.getValue(JDBCConstants.urlReturnColumnName);
            if (o != null)
            {
              // This is not right - url can apparently be a BinaryInput
              String url = JDBCConnection.readAsString(o);
              boolean validURL;
              try
              {
                // Check to be sure url is valid
                new java.net.URI(url);
                validURL = true;
              }
              catch (java.net.URISyntaxException e)
              {
                validURL = false;
              }

              if (validURL)
              {
                // Process the document itself
                Object contents = row.getValue(JDBCConstants.dataReturnColumnName);
                // Null data is allowed; we just ignore these
                if (contents != null)
                {
                  // We will ingest something, so remove this id from the map in order that we know what we still
                  // need to delete when all done.
                  map.remove(id);
                  String contentType;
                  o = row.getValue(JDBCConstants.contentTypeReturnColumnName);
                  if (o != null)
                    contentType = JDBCConnection.readAsString(o);
                  else
                    contentType = null;
                 
                  if (contentType == null || activities.checkMimeTypeIndexable(contentType))
                  {
                    if (contents instanceof BinaryInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("application/octet-stream");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      BinaryInput bi = (BinaryInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = bi.getStream();
                        try
                        {
                          rd.setBinary(is,bi.getLength());
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else if (contents instanceof CharacterInput)
                    {
                      // An ingestion will take place for this document.
                      RepositoryDocument rd = new RepositoryDocument();

                      // Default content type is application/octet-stream for binary data
                      if (contentType == null)
                        rd.setMimeType("text/plain; charset=utf-8");
                      else
                        rd.setMimeType(contentType);
                     
                      applyAccessTokens(rd,version,spec);
                      applyMetadata(rd,row);

                      CharacterInput ci = (CharacterInput)contents;
                      try
                      {
                        // Read the stream
                        InputStream is = ci.getUtf8Stream();
                        try
                        {
                          rd.setBinary(is,ci.getUtf8StreamLength());
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (java.net.SocketTimeoutException e)
                      {
                        throw new ManifoldCFException("Socket timeout reading database data: "+e.getMessage(),e);
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                    else
                    {
                      // Turn it into a string, and then into a stream
                      String value = contents.toString();
                      try
                      {
                        byte[] bytes = value.getBytes("utf-8");
                        RepositoryDocument rd = new RepositoryDocument();

                        // Default content type is text/plain for character data
                        if (contentType == null)
                          rd.setMimeType("text/plain");
                        else
                          rd.setMimeType(contentType);
                       
                        applyAccessTokens(rd,version,spec);
                        applyMetadata(rd,row);

                        InputStream is = new ByteArrayInputStream(bytes);
                        try
                        {
                          rd.setBinary(is,bytes.length);
                          activities.ingestDocument(id, version, url, rd);
                        }
                        finally
                        {
                          is.close();
                        }
                      }
                      catch (InterruptedIOException e)
                      {
                        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
                      }
                      catch (IOException e)
                      {
                        throw new ManifoldCFException("Error reading database data: "+e.getMessage(),e);
                      }
                    }
                  }
                  else
                    Logging.connectors.warn("JDBC: Document '"+id+"' excluded because of mime type - skipping");
                }
                else
                  Logging.connectors.warn("JDBC: Document '"+id+"' seems to have null data - skipping");
              }
              else
                Logging.connectors.warn("JDBC: Document '"+id+"' has an illegal url: '"+url+"' - skipping");
            }
            else
              Logging.connectors.warn("JDBC: Document '"+id+"' has a null url - skipping");
          }
        }
        finally
        {
          row.close();
        }
      }
      // Now, go through the original id's, and see which ones are still in the map.  These
      // did not appear in the result and are presumed to be gone from the database, and thus must be deleted.
      i = 0;
      while (i < documentIdentifiers.length)
      {
        if (!scanOnly[i])
        {
          String documentIdentifier = documentIdentifiers[i];
          if (map.get(documentIdentifier) != null)
          {
            // This means we did not see it (or data for it) in the result set.  Delete it!
            activities.deleteDocument(documentIdentifier,versions[i]);
          }
        }
        i++;
      }

    }
    finally
    {
      result.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.manifoldcf.jdbc.IDynamicResultSet

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.