1 22 23 28 29 package org.xquark.mapper.storage; 30 31 import java.sql.SQLException ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 import org.xml.sax.Locator ; 36 import org.xquark.mapper.RepositoryException; 37 import org.xquark.mapper.dbms.AbstractConnection; 38 import org.xquark.mapper.mapping.ColumnMapping; 39 import org.xquark.mapper.mapping.RepositoryMapping; 40 import org.xquark.mapper.metadata.StoragePathMetadata; 41 import org.xquark.schema.validation.SchemaValidationContext; 42 import org.xquark.xml.xdbc.XMLDBCException; 43 import org.xquark.xpath.NodeKind; 44 45 48 public class MapperTupleBuilder extends AbstractModelBuilder 49 { 50 private static final String RCSRevision = "$Revision: 1.1 $"; 51 private static final String RCSName = "$Name: $"; 52 53 public static boolean USE_EMPTY_STRING = false; 55 56 public MapperTupleBuilder(AbstractConnection connection, RepositoryMapping mapping, SchemaValidationContext schemaContext) throws XMLDBCException 57 { 58 super(connection, schemaContext); 59 storageBuffer = new StorageBuffer(mapping, "dummy", connection, batcher, this, USE_EMPTY_STRING); 60 } 61 62 public void setDocumentIDs(int docOID, String docID) 63 { 64 } 66 67 70 public void extraNode(byte type, StoragePathMetadata path, String data) 71 throws RepositoryException, SQLException 72 { 73 } 75 76 protected AbstractModelBuilder.AbstractModelNode getLogicalStructureNode(byte type, StoragePathMetadata path, String data, Locator locator) 77 throws SQLException , RepositoryException 78 { 79 AbstractModelBuilder.AbstractModelNode node = null; 80 81 short rank = 0; 83 List nodeTableMappings = null, nodeColumnMappings = null; 84 switch (type) 85 { 86 case NodeKind.ELEMENT: 87 if (stack.size() != 0) rank = getCurrentNode().incChildCount(); 89 91 case NodeKind.ATTRIBUTE: 92 nodeTableMappings = path.getTableMappings(); 93 nodeColumnMappings = path.getColumnMappings(); 94 break; 95 96 default : 97 } 98 99 node = (AbstractModelNode)stack.push(); 101 node.set(path, type, data, rank); 102 103 if (nodeTableMappings != null) 105 node.setTupleNode(storageBuffer.bufferizeNode(nodeTableMappings, locator)); 106 107 if (nodeColumnMappings != null) 109 { 110 Iterator it = nodeColumnMappings.iterator(); 114 ColumnMapping column = null; 115 int refIndex; 116 while (it.hasNext()) 117 { 118 column = (ColumnMapping)it.next(); 119 refIndex = column.getTableRefIndex(); 120 if (refIndex != -1) 121 storageBuffer.getTupleFactory(column.getTableIndex()).addMasterTuple(storageBuffer.getTupleFactory(refIndex).getTuple()); 122 } 123 } 124 125 return node; 126 } 127 128 protected AbstractModelBuilder.AbstractModelNode finalizeNode(Locator locator) 129 throws XMLDBCException, SQLException 130 { 131 AbstractModelBuilder.AbstractModelNode node = getCurrentNode(); 132 133 List nodeTableMappings = null, nodeColumnMappings = null; 135 switch (node.type) 136 { 137 case NodeKind.ELEMENT: 138 case NodeKind.ATTRIBUTE: 139 nodeTableMappings = node.getPath().getTableMappings(); 140 nodeColumnMappings = node.getPath().getColumnMappings(); 141 break; 142 default : 143 } 144 145 if (nodeColumnMappings != null) 147 { 148 Iterator it = nodeColumnMappings.iterator(); 149 ColumnMapping column = null; 150 151 while (it.hasNext()) 152 { 153 column = (ColumnMapping)it.next(); 154 storageBuffer.getTupleFactory(column.getTableIndex()).getTuple().addColumnMappingData(column, this); 155 } 156 } 157 158 if (nodeTableMappings != null) 160 node.getTupleNode().complete(); 161 162 if (node.type == NodeKind.ELEMENT) 164 { 165 169 storageBuffer.flush(); 172 } 173 return (AbstractModelNode)stack.pop(); 174 } 175 176 } 177 | Popular Tags |