public void traverse(IMetadataVisistor visitor) { for (String fieldName : visitor.getVisitFields(this)) { MetaField field = getFieldByName(fieldName); visitor.processField(this, field); } visitor.processOption(this, this.getOptions(), graph); }
private void validateIndex(MetaClass meta, Map<String, MetaClass> metas, MetaClassGraph tempGraph) { // checkIndexSize(); MetadataContext metaContext = new MetadataContext(); metaContext.setOptionChangeMode(UpdateOptionMode.VALIDATE); if(metas.isEmpty()) { // existed MetadataOptionValidator validator = new MetadataOptionValidator(new MetaOption(), metaContext); validator.processOption(meta, meta.getOptions(), tempGraph); } else { // newOptions MetadataOptionValidator validator = new MetadataOptionValidator(metas.get(meta.getName()).getOptions(), metaContext); MetaClass existedMetaClass = meta.getMetadataService().getMetaClass(meta.getName()); validator.processOption(existedMetaClass == null ? meta : existedMetaClass, meta.getOptions(), tempGraph); } // for (IndexInfo index : getClassIndexes()) { // index.validate(); // } } }
private Collection<IndexInfo> getEmbededIndexes(MetaClass metaClass, MetaClassGraph graph) { Collection<IndexInfo> embedIndexes = new ArrayList<IndexInfo>(); Collection<MetaField> fields = metaClass.getClassFields(); for (MetaField field : fields) { if (field.getDataType() == DataTypeEnum.RELATIONSHIP && ((MetaRelationship) field).getRelationType() == RelationTypeEnum.Embedded) { MetaRelationship relationship = (MetaRelationship) field; String refDataType = relationship.getRefDataType(); MetaClass targetMeta = graph.getMetaClass(refDataType); if (targetMeta != null) { // add reference indexes targetMeta.addReferenceIndexes(); // add self indexes Collection<IndexInfo> targetIndexes = new ArrayList<IndexInfo>(targetMeta.getOptions().getIndexes()); // add nested embed indexes targetIndexes.addAll(getEmbededIndexes(targetMeta, graph)); for (IndexInfo targetIndex : targetIndexes) { embedIndexes.add(new IndexInfo(targetIndex, relationship)); } } } } return embedIndexes; }
for (String idxName : ancestor.getOptions().getIndexNames()) { if (!ancestoreIndexes.containsKey(idxName)) { ancestoreIndexes.put(idxName, ancestor.getOptions().getIndexByName(idxName)); for (IndexInfo idx : meta.getOptions().getIndexes()) { if (idx.isInternal()) { continue;
private void setUpMetaClass(MetaClass m, MetaClassGraph newGraph) { // set metaservice for metaclass m.setMetadataService(this); m.setMetaclassGraph(newGraph); //setup metaservice for metafields for (MetaField f : m.getClassFields()) { if (f.getDataType() == MetaField.DataTypeEnum.RELATIONSHIP) { ((MetaRelationship)f).setMetadataService(this); ((MetaRelationship)f).setSourceDataType(m.getName()); } } List<String> classPrimaryKeys = m.getOptions().getPrimaryKeys(); if (!classPrimaryKeys.isEmpty()) { // add indexes for primary key IndexInfo ii = new IndexInfo(IndexInfo.PK_INDEX, true); for (String pk : classPrimaryKeys) { ii.addKeyField(pk); } ii.addOption(IndexOptionEnum.unique); m.getOptions().addIndex(ii); } m.addReferenceIndexes(); }
String parent = meta.getParent(); IMetadataService metadataService = meta.getMetadataService(); MetaOption options = meta.getOptions(); Map<String, MetaField> fieldNameIndex = meta.getFieldNameIndex(); if (name == null || MetaClass.getReservedMetaName().contains(name)) {
for (IndexInfo info : meta.getOptions().getIndexes()) {
public Collection<IndexInfo> getIndexesOnField(MetaClass meta, String fieldName) { List<IndexInfo> indexesOnField = meta.getOptions().getIndexesByFieldName(fieldName); // List<IndexInfo> indexesOnField = options.getIndexesByFieldName(fieldName); MetaClass mp = meta.getParentMetaClass(); if (mp != null) { indexesOnField.addAll(mp.getIndexesOnField(fieldName)); } // add a dummy embed field's oidIndex for QueryCostAnalysor MetaField field = meta.getFieldByName(fieldName); if (field != null && field.getDataType() == DataTypeEnum.RELATIONSHIP && ((MetaRelationship) field).getRelationType() == RelationTypeEnum.Embedded) { MetaRelationship relationship = (MetaRelationship) field; relationship.setMetadataService(meta.getMetadataService()); MetaClass targetMeta = relationship.getRefMetaClass(); Collection<IndexInfo> embedIndexes = targetMeta.getIndexesOnField(InternalFieldEnum.ID.getName()); if (!embedIndexes.isEmpty()) { IndexInfo embedIndex = new IndexInfo(field.getName(), true); embedIndex.addKeyField(field.getName()); indexesOnField.add(embedIndex); } } return indexesOnField; }
String parent = meta.getParent(); IMetadataService metadataService = meta.getMetadataService(); MetaOption options = meta.getOptions(); Map<String, MetaField> fieldNameIndex = meta.getFieldNameIndex(); String repository = meta.getRepository();
@Test public void testDeleteEnsureIndex() { IMetadataService metaService = repoService.getRepository(RAPTOR_REPO).getMetadataService(); MetaClass metaClass = metaService.getMetaClass(indexMetaName); if (metaClass == null) { metaClass = createMetaClassWithIndex(indexMetaName, idxName, metaService); } int count = getCollectionIndexMap(metaClass).size(); //no indexes added, means we are going to delete a index MetaOption metaOption = metaClass.getOptions(); IndexInfo index = metaOption.getIndexByName(idxName); metaOption.dropIndex(index); List<MetaClass> metas = new ArrayList<MetaClass>(); metas.add(metaClass); persistenceService.ensureIndex(metas, raptorContext, true); Map<String, DBObject> indexMap = getCollectionIndexMap(metaClass); Assert.assertEquals(1, count - indexMap.size()); Assert.assertFalse(indexMap.containsKey(idxName)); }
@Test public void testDeleteEnsureIndex() { IMetadataService metaService = repoService.getRepository(RAPTOR_REPO).getMetadataService(); MetaClass metaClass = metaService.getMetaClass(indexMetaName); if (metaClass == null) { metaClass = createMetaClassWithIndex(indexMetaName, idxName, metaService); } int count = getCollectionIndexMap(metaClass).size(); //no indexes added, means we are going to delete a index MetaOption metaOption = metaClass.getOptions(); IndexInfo index = metaOption.getIndexByName(idxName); metaOption.dropIndex(index); List<MetaClass> metas = new ArrayList<MetaClass>(); metas.add(metaClass); persistenceService.ensureIndex(metas, raptorContext, true); Map<String, DBObject> indexMap = getCollectionIndexMap(metaClass); Assert.assertEquals(1, count - indexMap.size()); Assert.assertFalse(indexMap.containsKey(idxName)); }
ii.addKeyField(HistoryMetaClass.EntityId); ii.addKeyField(HistoryMetaClass.EntityVersion); historyMeta.getOptions().addIndex(ii);
@Test(expected = IllegalIndexException.class) public void testValidateForUpdateField_indexSize1() { int maxIndexSize = CMSConsts.MAX_INDEXES_PER_META_CLASS; MetaClass mClass = new MetaClass(); mClass.setName("TestIndexSize"); mClass.setRepository(RAPTOR_PAAS); MetaOption metaOption = mClass.getOptions(); for (int i = 0; i <= maxIndexSize; i++) { MetaAttribute attr = new MetaAttribute(); attr.setName("field" + i); IndexInfo index = new IndexInfo("index" + i); metaOption.addIndex(index); } IMetadataService metaService = repo.getMetadataService(); metaService.createMetaClass(mClass, new MetadataContext()); }
@Test(expected = IllegalIndexException.class) public void testValidateForUpdateField_indexSize2() { int defaultSystemMaxIndexSize = CMSConsts.MAX_INDEXES_PER_META_CLASS; MetaClass mClass = new MetaClass(); mClass.setName("TestIndexSize"); mClass.setRepository(RAPTOR_PAAS); MetaOption metaOption = mClass.getOptions(); int maxIndexSizePerRepo = defaultSystemMaxIndexSize + 1; repo.getOptions().setMaxNumOfIndexes(maxIndexSizePerRepo); for (int i = 0; i <= maxIndexSizePerRepo; i++) { MetaAttribute attr = new MetaAttribute(); attr.setName("field" + i); IndexInfo index = new IndexInfo("index" + i); metaOption.addIndex(index); } IMetadataService metaService = repo.getMetadataService(); try { metaService.createMetaClass(mClass, new MetadataContext()); } catch (IllegalIndexException e) { throw e; } finally { repo.getOptions().setMaxNumOfIndexes(null); } }
ii.addKeyField(EntityId); ii.addKeyField(EntityVersion); historyMetaClass.getOptions().addIndex(ii);
metaClass.addIndex(ii2); metaClass.getOptions().addPrimaryKey(ma3.getName());