Project

General

Profile

« Previous | Next » 

Revision 6416

Added by rnahf over 13 years ago

fixed logic wrt localID and docid. Implemented new method in IdentifierManager to getAllGUIDs from identifier table for implementation of loadAllKeys in ObjectPathMapLoader.

View differences:

src/edu/ucsb/nceas/metacat/dataone/hazelcast/ObjectPathMapLoader.java
57 57
	 * the data.  The doctype value for metadata can vary, but for data
58 58
	 * is always 'BIN', so using a simple if-then-else to separate
59 59
	 */
60
	private String pathToDocid(String docid) throws SQLException {
60
	private String pathToDocid(String localid) throws McdbDocNotFoundException  {
61 61
		
62
		String revType = dbUtil.getCurrentRevisionAndDocTypeForGivenDocument(docid);
63
		String[] rt = revType.split(";");
64
		String docType = rt[1];
65
		String revision = rt[0];
66
		if (docType.equals("BIN")) {
67
			return dataPath + FileUtil.getFS() + docid + "." + revision;
62
		Hashtable<String, Object> ht = im.getDocumentInfo(localid);
63
		if (ht.get("doctype").equals("BIN")) {
64
			return dataPath + FileUtil.getFS() + localid;
68 65
		} else {
69
			return metadataPath + FileUtil.getFS() + docid + "." + revision;
66
			return metadataPath + FileUtil.getFS() + localid;
70 67
		}		
71 68
	}
72 69

  
73 70
	
74 71
	/**
75 72
	 *  Implementation of hazelcast MapLoader interface method.
76
	 *  for the provided Identifier (as key), looks up the localID
77
	 *  and revision
73
	 *  For the provided Identifier (as key), returns the path to the
74
	 *  document on the local filesystem.  Returns null if it can't 
75
	 *  create the path. 
78 76
	 */
79 77
	@Override
80 78
	public String load(Identifier key) 
......
88 86
			// TODO Auto-generated catch block
89 87
			e.printStackTrace();
90 88
			return null;
91
		} catch (SQLException e) {
92
			// TODO Auto-generated catch block
93
			e.printStackTrace();
94 89
		}
95 90
		return path;
96 91
	}
97 92
	
98 93
	
99 94
	/**
100
	 *  Implementation of hazelcast MapLoader interface method.
95
	 *  Implementation of hazelcast MapLoader interface method.  This method loads
96
	 *  mappings for all Identifiers in the parameters.  Any Identifier not found
97
	 *  is not included in the resulting map.
101 98
	 */
102 99
	@Override
103 100
	public Map<Identifier, String> loadAll(Collection<Identifier> identifiers) {
......
109 106
				map.put(id, pathToDocid(docid));
110 107
				
111 108
			} catch (McdbDocNotFoundException e) {
112
				// TODO Auto-generated catch block
109
				// TODO should the map load an empty path instead of
110
				// leaving out the entire entry?
113 111
				e.printStackTrace();
114
			} catch (SQLException e) {
115
				// TODO Auto-generated catch block
116
				e.printStackTrace();
117 112
			}
118 113
		}
119 114
		return map;
......
121 116

  
122 117
	
123 118
	/**
124
	 * Hazelcast documents a few ways to implement this method, depending on specific
125
	 * usage.  Preloading all of the GUIDs may be an unnecessarily long operation,
126
	 * so this implementation returns NULL, and loading will be shifted to the other
127
	 * method calls.
119
	 * Return the full set of guids in the local metacat repository as
120
	 * dataone Identifiers.
121
	 * 
122
	 * (Hazelcast allows avoiding pre-loading by returning NULL, so consider
123
	 * re-implementing if that serves the purpose of this class better)
128 124
	 */
129 125
	@Override
130 126
	public Set<Identifier> loadAllKeys() {
131
		return null;
132

  
133
		/*  ---- this would be another way to implement, using existing methods
134
		 *  ---- in IdentifierManager, and DBUtil.  but it is still problematic
135
		 *  ---- in how it goes from docid to GUID wrt revisions
136
		 *  ---- 
137
		 *  ---- better would be a new call to the identifier table listing all GUIDs
138
		 *  ---- (from new method in IdentifierManager)
127
		
128
		List<String> guids = im.getAllGUIDs();
129
		
139 130
		Set<Identifier> set = Collections.synchronizedSet(new HashSet<Identifier>());
140
		
141
		List<String> docids = null;
142
		try {
143
			docids = im.getAllLocalIds();
144
			for(String docid : docids) {
145
				Identifier id = new Identifier();
146
				// TODO: need new query for going from localID to guid.
147
				id.setValue(im.getGUID(docid, im.getLatestRevForLocalId(docid)));
148
				set.add(id);
149
			}
150
		} catch (Exception e) {
151
			// TODO Auto-generated catch block
152
			e.printStackTrace();
131
		for (String guid : guids) {
132
			Identifier id = new Identifier();
133
			id.setValue(guid);
134
			set.add(id);
153 135
		}
154 136
		return set;
155
		*/
156 137
	}
157 138
}
src/edu/ucsb/nceas/metacat/IdentifierManager.java
643 643
     * @return a list of all local ids in metacat
644 644
     */
645 645
    public List<String> getAllLocalIds()
646
       throws Exception
646
    // seems to be an unnecessary and restrictive throw -rnahf 13-Sep-2011
647
    //    throws Exception
647 648
    {
648 649
        Vector<String> ids = new Vector<String>();
649 650
        String sql = "select docid from xml_documents";
......
678 679
        return ids;
679 680
    }
680 681
    
682
    
681 683
    /**
684
     * return a listing of all guids in the object store
685
     * @return a list of all GUIDs in metacat
686
     */
687
    public List<String> getAllGUIDs()
688
    {
689
        Vector<String> guids = new Vector<String>();
690
        String sql = "select guid from identifier";
691
        DBConnection dbConn = null;
692
        int serialNumber = -1;
693
        try 
694
        {
695
            // Get a database connection from the pool
696
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getAllGUIDs");
697
            serialNumber = dbConn.getCheckOutSerialNumber();
698

  
699
            // Execute the insert statement
700
            PreparedStatement stmt = dbConn.prepareStatement(sql);
701
            ResultSet rs = stmt.executeQuery();
702
            while (rs.next()) 
703
            {
704
                String guid = rs.getString(1);
705
                guids.add(guid);
706
            } 
707
            stmt.close();
708
        } 
709
        catch (SQLException e) 
710
        {
711
            logMetacat.error("Error while retrieving the guid: " 
712
                    + e.getMessage());
713
        } 
714
        finally 
715
        {
716
            // Return database connection to the pool
717
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
718
        }
719
        return guids;
720
    }
721
    
722
    
723
    
724
    /**
682 725
     * returns a list of system metadata-only guids since the given date
683 726
     * @return a list of system ids in metacat that do not correspond to objects
684 727
     * TODO: need to check which server they are on
......
743 786
        } catch (McdbDocNotFoundException e) {
744 787
        	// try system metadata only
745 788
        	try {
746
        		idExists = systemMetadataExisits(guid);
789
        		idExists = systemMetadataExists(guid);
747 790
            } catch (McdbDocNotFoundException e2) {
748 791
            	idExists = false;
749 792
            }
......
859 902
        return guid;
860 903
    }
861 904
    
862
    public boolean systemMetadataExisits(String guid)
905
    public boolean systemMetadataExists(String guid)
863 906
			throws McdbDocNotFoundException {
864 907
		logMetacat.debug("looking up system metadata for guid " + guid);
865 908
		boolean exists = false;

Also available in: Unified diff