ASF Bugzilla – Attachment 19311 Details for
Bug 19203
ValueIndexer for Multi-Byte Numeric Types Broken
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Rebuild collection/index utility
CollectionCopy.java (text/plain), 6.39 KB, created by
Natalia Shilenkova
on 2006-12-27 18:10:29 UTC
(
hide
)
Description:
Rebuild collection/index utility
Filename:
MIME Type:
Creator:
Natalia Shilenkova
Created:
2006-12-27 18:10:29 UTC
Size:
6.39 KB
patch
obsolete
>package org.apache.xindice.tools; > >import org.apache.xindice.xml.dom.DOMParser; >import org.apache.xindice.core.filer.BTreeFiler; >import org.apache.xindice.core.filer.BTreeCallback; >import org.apache.xindice.core.data.Value; >import org.apache.xindice.core.data.Key; >import org.apache.xindice.core.Database; >import org.apache.xindice.core.Collection; >import org.apache.xindice.core.DBException; >import org.apache.xindice.core.indexer.Indexer; >import org.apache.xindice.util.Configuration; >import org.apache.xindice.util.XindiceException; > >import java.io.File; >import java.io.IOException; > >public class CollectionCopy { > private static Database db; > private static String path; > private static boolean removeBackupFiles; > private static final int CMD_COPY = 1; > private static final int CMD_INDEX = 2; > private static int command; > > public static void main(String[] args) throws Exception { > if (args.length < 2 || !("copy".equals(args[0]) || "index".equals(args[0])) || > args[1] == null || args[1].length() == 0) { > usage(); > return; > } > > command = "copy".equals(args[0]) ? CMD_COPY : CMD_INDEX; > String dbLocation = args[1]; > if (args.length > 2 && args[2].equals("--remove")) { > removeBackupFiles = true; > } > > > String config = "<root-collection dbroot='" + dbLocation + "/' name='" + dbLocation + "'/>"; > db = new Database(); > > try { > db.setConfig(new Configuration(DOMParser.toDocument(config))); > > path = db.getCollectionRoot().getPath(); > processChildCollections("/"); > > } finally { > db.close(); > } > } > > private static void usage() { > System.out.println("Commands:"); > System.out.println("copy <db location> [--remove]"); > System.out.println("index <db location>"); > } > > private static void processChildCollections(String colRoot) throws IOException, XindiceException { > Collection col = null; > String[] colNames = null; > > System.out.println("Getting child collections for " + colRoot); > try { > // Get a Collection reference > col = db.getCollection(colRoot); > if (col == null) { > System.out.println("Error fetching collection '" + colRoot + "'"); > } else { > processCollection(col, colRoot); > colNames = col.listCollections(); > } > } catch (Exception e) { > System.out.println("Got an excefption when processing collection: " + > (col != null ? col.getName() : "unknown")); > e.printStackTrace(); > > } > > if (colNames != null) { > for (int i = 0; i < colNames.length; i++) { > processChildCollections(colRoot + colNames[i] + "/"); > } > } > } > > private static void processCollection(Collection col, String location) throws XindiceException, IOException { > switch (command) { > case CMD_INDEX: > rebuildIndex(col); > break; > > case CMD_COPY: > rebuildCollection(col, location, col.getName()); > break; > } > } > > private static void rebuildCollection(Collection col, String location, String name) throws XindiceException, IOException { > if (!(col.getFiler() instanceof BTreeFiler)) { > System.out.println("Filer for collection " + location + " is not BTreeFiler. Skipping..."); > return; > } > > // close collection and its filer > col.close(); > > System.out.println("Processing collection " + location); > > File root = new File(path + location); > > String fileName = path + location + "/" + name; > new File(fileName + ".tbl").renameTo(new File(fileName + ".old.tbl")); > > BTreeCopy filer = new BTreeCopy(); > filer.setLocation(root, name + ".old"); > filer.setConfig(col.getFiler().getConfig()); > > if (!filer.exists()) { > System.out.println("Filer for " + fileName + ".old.tbl does not exists"); > return; > } > > BTreeFiler newFiler = new BTreeFiler(); > newFiler.setLocation(root, name); > newFiler.setConfig(col.getFiler().getConfig()); > if (newFiler.exists()) { > System.out.println("Filer for " + fileName + ".tbl already exists"); > return; > } > > newFiler.create(); > > try { > filer.open(); > newFiler.open(); > > filer.copy(newFiler); > > if (removeBackupFiles) { > filer.deleteFile(); > } > } finally { > try { > filer.close(); > } catch (Exception e) { > e.printStackTrace(); > } > try { > newFiler.close(); > } catch (Exception e) { > e.printStackTrace(); > } > } > } > > private static void rebuildIndex(Collection col) throws DBException { > if (col.getFiler() != null) { > String[] list = col.listIndexers(); > for (int i = 0; i < list.length; i++) { > Indexer idx = col.getIndexer(list[i]); > Configuration idxConf = idx.getConfig(); > System.out.println("Rebuilding index " + list[i] + " for collection " + col.getName()); > col.dropIndexer(idx); > col.createIndexer(idxConf); > } > } > } > > private static class BTreeCopy extends BTreeFiler { > private Value getValue(long pointer) throws IOException { > return super.readValue(pointer); > } > > private void copy(BTreeFiler newFiler) throws XindiceException, IOException { > query(null, new CopyCallback(this, newFiler)); > } > > private void deleteFile() { > getFile().delete(); > } > } > > private static class CopyCallback implements BTreeCallback { > BTreeCopy filer; > BTreeFiler newFiler; > > public CopyCallback(BTreeCopy filer, BTreeFiler newFiler) { > this.filer = filer; > this.newFiler = newFiler; > } > > public boolean indexInfo(Value value, long pointer) { > try { > Value v = filer.getValue(pointer); > newFiler.writeRecord(new Key(value), v); > } catch (Exception e) { > e.printStackTrace(); > } > > return true; > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 19203
:
19143
|
19145
|
19309
|
19310
| 19311