private MongoDocument getDocument(String tblName) throws TranslatorException { if (this.relatedDocs.get(tblName) != null) { return this.relatedDocs.get(tblName); } Table tbl = this.metadata.getTable(this.table.getParent().getName(), tblName); MongoDocument doc = new MongoDocument(tbl, this.metadata); this.relatedDocs.put(tblName, doc); return doc; }
public Table getMergeTable() throws TranslatorException { String tblName = this.table.getProperty(MongoDBMetadataProcessor.MERGE, false); if (tblName == null) { return null; } Table mergeTable = this.metadata.getTable(this.table.getParent().getName(), tblName); return mergeTable; }
@Override public void visit(ColumnReference obj) { AbstractMetadataRecord record = obj.getMetadataObject(); if (record != null) { String name = record.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false); if (name != null) { try { Table t = this.metadata.getTable(name); String correlationName = obj.getTable().getCorrelationName(); String attrName = record.getProperty(JPAMetadataProcessor.RELATION_PROPERTY, false); String groupName = correlationName + Tokens.DOT + attrName; NamedTable nt = this.implicitGroups.get(groupName); if (nt == null) { nt = new NamedTable(groupName, "J_"+this.aliasCounter.getAndIncrement(), t); this.implicitGroups.put(groupName, nt); //$NON-NLS-1$ } } catch (TranslatorException e) { exceptions.add(e); } } } }
private DBCollection getCollection(String name) throws TranslatorException { return getCollection(this.metadata.getTable(this.visitor.mongoDoc.getTable().getParent().getName(), name)); } private DBCollection getCollection(Table table) {
static Table getComplexTableParentTable(RuntimeMetadata metadata, Table table) throws TranslatorException { for (Column c : table.getColumns()) { if (ODataMetadataProcessor.isPseudo(c)) { ForeignKey fk = table.getForeignKeys().get(0); String tableName = fk.getReferenceTableName(); if (tableName.indexOf('.') == -1) { tableName = fk.getReferenceKey().getParent().getFullName(); } return (Table)metadata.getTable(tableName); } } return table; }
static Column normalizePseudoColumn(RuntimeMetadata metadata, Column column) throws TranslatorException { if (ODataMetadataProcessor.isPseudo(column)) { Table table = (Table)column.getParent(); ForeignKey fk = table.getForeignKeys().get(0); for (int i = 0; i < fk.getColumns().size(); i++) { Column c = fk.getColumns().get(i); if (c.getName().equals(column.getName())) { String refColumn = fk.getReferenceColumns().get(i); String tableName = fk.getReferenceTableName(); if (tableName.indexOf('.') == -1) { tableName = fk.getReferenceKey().getParent().getFullName(); } Table refTable = metadata.getTable(tableName); return refTable.getColumnByName(refColumn); } } } return column; }
private void updateReferenceTables(DBCollection collection, MongoDocument mongoDoc, DBObject match, AggregationOptions options) throws TranslatorException { DBObject m = new BasicDBObject("$match", match); //$NON-NLS-1$ Cursor output = collection.aggregate(Arrays.asList(m), options); while(output.hasNext()) { DBObject row = output.next(); if (row != null) { for (MergeDetails ref:mongoDoc.getEmbeddedIntoReferences()) { DBCollection parent = getCollection(ref.getParentTable()); //DBObject parentmatch = new BasicDBObject(ref.getReferenceName()+".$id", row.get("_id")); //$NON-NLS-1$ //$NON-NLS-2$ DBObject parentmatch = buildParentMatch(row, ref); row.removeField("_id"); //$NON-NLS-1$ parent.update(parentmatch, new BasicDBObject("$set",new BasicDBObject(ref.getName(), row)), //$NON-NLS-1$ false, true, WriteConcern.ACKNOWLEDGED); // see if there are nested references Table parentTable = this.metadata.getTable(mongoDoc.getTable().getParent().getName(), ref.getParentTable()); MongoDocument parentMongoDocument = new MongoDocument(parentTable, this.metadata); if (parentMongoDocument.isEmbeddable()) { updateReferenceTables(parent, parentMongoDocument, parentmatch,options); } } } } }