@Override protected XMLPersistenceMetaDataParser newXMLParser(boolean loading) { XMLPersistenceMappingParser parser = new XMLPersistenceMappingParser ((JDBCConfiguration) repos.getConfiguration()); // strict mode means we're using a separate mapping parser, so if // we're adapting parse metadata hints if (strict && loading) parser.setMappingOverride(((MappingRepository) repos). getStrategyInstaller().isAdapting()); return parser; }
/** * Start processing <code>entity-result</code> node. * Pushes the {@link QueryResultMapping.PCResult} * onto the stack as current element. */ private boolean startEntityResult(Attributes attrs) throws SAXException { Class<?> entityClass = classForName(attrs.getValue("entity-class")); String discriminator = DBIdentifier.newColumn(attrs.getValue("discriminator-column"), delimit()).getName(); QueryResultMapping parent = (QueryResultMapping) currentElement(); QueryResultMapping.PCResult result = parent.addPCResult(entityClass); if (!StringUtils.isEmpty(discriminator)) result.addMapping(PCResult.DISCRIMINATOR, discriminator); pushElement(result); return true; }
@Override protected void reset() { super.reset(); clearColumnInfo(); clearClassInfo(); clearSecondaryTableInfo(); _override = null; _schema = null; _resultIdx = 0; }
/** * Parse join-column. */ private boolean startJoinColumn(Attributes attrs) throws SAXException { // only join cols in a join table join field table to class table; // others act as data fk cols if (currentParent() != JOIN_TABLE) return startColumn(attrs); if (_joinCols == null) _joinCols = new ArrayList<Column>(3); _joinCols.add(parseColumn(attrs)); return true; }
@Override protected void endSystemMappingElement(String name) throws SAXException { MappingTag tag = _elems.get(name); if (tag == null) { if ("schema".equals(name)) _schema = currentText(); return; } switch (tag) { case SQL_RESULT_SET_MAPPING: endSQLResultSetMapping(); break; case ENTITY_RESULT: endEntityResult(); break; } }
/** * Start processing <code>sql-result-set-mapping</code> node. * Pushes the {@link QueryResultMapping} onto the stack as current element. */ private boolean startSQLResultSetMapping(Attributes attrs) { String name = attrs.getValue("name"); Log log = getLog(); if (log.isTraceEnabled()) log.trace(_loc.get("parse-sqlrsmapping", name)); MappingRepository repos = (MappingRepository) getRepository(); QueryResultMapping result = repos.getCachedQueryResultMapping (null, name); if (result != null && log.isWarnEnabled()) log.warn(_loc.get("override-sqlrsmapping", name, currentLocation())); result = repos.addQueryResultMapping(null, name); result.setListingIndex(_resultIdx++); addComments(result); Object cur = currentElement(); Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null; result.setSource(getSourceFile(), scope, result.SRC_XML); pushElement(result); return true; }
Object elem = currentElement(); FieldMapping fm = null; if (elem instanceof ClassMapping) fm = getAttributeOverride((ClassMapping) elem); else { FieldMapping basefm = (FieldMapping) elem; fm = getAttributeOverrideForEmbeddable(basefm, _override, false); if (fm == null) { DeferredEmbeddableOverrides dfm = getDeferredFieldMappingInfo( AnnotationPersistenceMappingParser. getEmbeddedClassType(basefm, _override), basefm, _override, true); dfm._defCols = _cols; dfm._defTable = DBIdentifier.newTable(_colTable, delimit()); dfm._attrName = _override; dfm._unique = _unique; fm.getValueInfo().setColumns(_cols); if (_colTable != null) fm.getMappingInfo().setTableIdentifier(DBIdentifier.newTable(_colTable, delimit())); setUnique(fm); clearColumnInfo(); _override = null;
Object elem = currentElement(); FieldMapping fm = null; if (elem instanceof FieldMapping) { if (_override != null) { FieldMapping basefm = (FieldMapping) elem; fm = getAttributeOverrideForEmbeddable(basefm, _override, false); if (fm == null) { DeferredEmbeddableOverrides dfm = getDeferredFieldMappingInfo( AnnotationPersistenceMappingParser. getEmbeddedClassType(basefm, _override), fm = getAttributeOverride(cm); fm.getElementMapping().getValueInfo().setColumns(_cols); clearColumnInfo();
private boolean endName() { String name = this.currentText(); if (StringUtils.isNotEmpty(name)) { Object current = currentElement(); if (current instanceof Unique) { Unique unq = (Unique)current; unq.setIdentifier(DBIdentifier.newConstraint(name, delimit())); } } return true; }
/** * Parse enumerated. */ private void endEnumerated() { String text = currentText(); if (StringUtils.isEmpty(text)) return; EnumType type = Enum.valueOf(EnumType.class, text); FieldMapping fm = (FieldMapping) currentElement(); String strat = EnumValueHandler.class.getName() + "(StoreOrdinal=" + String.valueOf(type == EnumType.ORDINAL) + ")"; fm.getValueInfo().setStrategy(strat); }
/** * Parse join-column. */ private boolean startJoinColumn(Attributes attrs) throws SAXException { // only join cols in a join table join field table to class table; // others act as data fk cols Object currentParent = currentParent(); if (currentParent == COLLECTION_TABLE) { FieldMapping fm = (FieldMapping) peekElement(); Column col = parseColumn(attrs); List<Column> colList = fm.getMappingInfo().getColumns(); if (colList.isEmpty()) { colList = new ArrayList<Column>(); fm.getMappingInfo().setColumns(colList); } colList.add(col); fm.getMappingInfo().setColumns(colList); return true; } if (currentParent != JOIN_TABLE) return startColumn(attrs); if (_joinCols == null) _joinCols = new ArrayList<Column>(3); _joinCols.add(parseColumn(attrs)); return true; }
/** * Parse discriminator-value. */ private void endDiscriminatorValue() { String val = currentText(); if (StringUtils.isEmpty(val)) return; ClassMapping cm = (ClassMapping) currentElement(); cm.getDiscriminator().getMappingInfo().setValue(val); if (Modifier.isAbstract(cm.getDescribedType().getModifiers()) && getLog().isInfoEnabled()) { getLog().info( _loc.get("discriminator-on-abstract-class", cm .getDescribedType().getName())); } }
/** * Parse primary-key-join-column. */ private boolean startPrimaryKeyJoinColumn(Attributes attrs) throws SAXException { Column col = parseColumn(attrs); col.setFlag(Column.FLAG_PK_JOIN, true); // pk join columns on fields act as field cols if (currentElement() instanceof FieldMapping) { if (_cols == null) _cols = new ArrayList<Column>(3); _cols.add(col); } else if (currentParent() == SECONDARY_TABLE) { // pk join columns in secondary table acts as join cols if (_joinCols == null) _joinCols = new ArrayList<Column>(3); _joinCols.add(col); } else { // must be pk join cols from this class to superclass if (_supJoinCols == null) _supJoinCols = new ArrayList<Column>(3); _supJoinCols.add(col); } return true; }
@Override protected void endSystemMappingElement(String name) throws SAXException { MappingTag tag = _elems.get(name); if (tag == null) { if ("schema".equals(name)) { _schema = currentText(); getRepository().getMetaDataFactory().getDefaults().setDefaultSchema(_schema); } return; } switch (tag) { case SQL_RESULT_SET_MAPPING: endSQLResultSetMapping(); break; case ENTITY_RESULT: endEntityResult(); break; } }
/** * Set attribute override into proper mapping. */ private void endAttributeOverride() throws SAXException { Object elem = currentElement(); FieldMapping fm; if (elem instanceof ClassMapping) fm = getAttributeOverride((ClassMapping) elem); else fm = getAttributeOverride((FieldMapping) elem); if (_cols != null) { fm.getValueInfo().setColumns(_cols); if (_colTable != null) fm.getMappingInfo().setTableName(_colTable); setUnique(fm); } clearColumnInfo(); _override = null; }
/** * Set the secondary table information back to the owning class mapping. */ private void endSecondaryTable() { ClassMapping cm = (ClassMapping) currentElement(); ClassMappingInfo info = cm.getMappingInfo(); info.setSecondaryTableJoinColumns(DBIdentifier.newTable(_secondaryTable, delimit()), _joinCols); clearSecondaryTableInfo(); }
fm.getMappingInfo().setTableIdentifier(DBIdentifier.newTable(_colTable, delimit())); setUnique(fm); clearColumnInfo();
/** * Start tracking secondary table information and columns */ private boolean startSecondaryTable(Attributes attrs) throws SAXException { _secondaryTable = toTableIdentifier(attrs.getValue("schema"), attrs.getValue("name")).getName(); ((ClassMapping)currentElement()).getMappingInfo() .addSecondaryTable(DBIdentifier.newTable(_secondaryTable)); return true; }
/** * Start processing <code>entity-result</code> node. * Pushes the {@link QueryResultMapping.PCResult} * onto the stack as current element. */ private boolean startEntityResult(Attributes attrs) throws SAXException { Class entityClass = classForName(attrs.getValue("entity-class")); String discriminator = attrs.getValue("discriminator-column"); QueryResultMapping parent = (QueryResultMapping) currentElement(); QueryResultMapping.PCResult result = parent.addPCResult(entityClass); if (!StringUtils.isEmpty(discriminator)) result.addMapping(result.DISCRIMINATOR, discriminator); pushElement(result); return true; }
/** * Process a <code>field-result</code> node. */ private boolean startFieldResult(Attributes attrs) throws SAXException { String fieldName = attrs.getValue("name"); String columnName = DBIdentifier.newColumn(attrs.getValue("column"), delimit()).getName(); QueryResultMapping.PCResult parent = (QueryResultMapping.PCResult) currentElement(); parent.addMapping(fieldName, columnName); return true; }