private void initIndex() { for(IndexInfo index : IndexInfo.getInternalIndexes()){ addIndex(index); } }
@JsonIgnore public void addIndex(IndexInfo index) { options.addIndex(index); }
@JsonProperty("indexes") @JsonDeserialize(using = MetaClassConverters.MetaIndexDeserializer.class) void setIndexes(Collection<IndexInfo> indexes) { this.indexes.clear(); this.fieldToIndexesMap.clear(); for (IndexInfo index : indexes) { addIndex(index); } initIndex(); }
public void deleteIndex(CMSPriority p, String repoName, String metaclassName, String indexName, MetadataContext context) { logger.info("cms deleteIndex: {}, {}, {}, {}", new Object[] { repoName, metaclassName, indexName, context.getSourceIp() }); checkServerState(p, true); Repository repo = repositoryService.getRepository(repoName); MetaOption options = new MetaOption(); IndexInfo ii = new IndexInfo(indexName); options.addIndex(ii); context.setDbConfig(dbConfig); repo.getMetadataService().updateMetaOption(metaclassName, options, context); updateMetadataIndexOnBranch(metaclassName, context, repo); }
public void addIndex(CMSPriority p, String repoName, String metaclassName, List<IndexInfo> index, MetadataContext context) { String[] indexNames = new String[index.size()]; for (int i = 0; i < index.size(); i++) { indexNames[i] = index.get(i).getIndexName(); } logger.info("cms addIndex: {}, {}, {}, {}", new Object[] { repoName, metaclassName, indexNames, context.getSourceIp() }); checkServerState(p, true); Repository repo = repositoryService.getRepository(repoName); MetaOption options = new MetaOption(); for (IndexInfo ii : index) { options.addIndex(ii); } context.setDbConfig(dbConfig); repo.getMetadataService().updateMetaOption(metaclassName, options, context); try { updateMetadataIndexOnBranch(metaclassName, context, repo); } catch (CmsDalException e) { for (IndexInfo ii : index) { context.setOptionChangeMode(UpdateOptionMode.DELETE); deleteIndex(p, repoName, metaclassName, ii.getIndexName(), context); } throw e; } }
public void addReferenceIndexes() { Collection<MetaField> fields = getClassFields(); for (MetaField field : fields) { if (field.getDataType() == DataTypeEnum.RELATIONSHIP && ((MetaRelationship) field).getRelationType() != RelationTypeEnum.Embedded) { String indexName = IndexInfo.INDEX_PREFIX + field.getName() + IndexInfo.INDEX_POSTFIX; IndexInfo relationshipIndex = new IndexInfo(indexName, true); relationshipIndex.addKeyField(field.getName()); options.addIndex(relationshipIndex); } } }
for (IndexInfo ii : newIndexes) { IndexInfo newIndex = new IndexInfo(ii.getIndexName()); tempOption.addIndex(newIndex);
MetaOption options = new MetaOption(); IndexInfo ii = new IndexInfo(HistoryMetaClass.INDEX_NAME); options.addIndex(ii); metaService.updateMetaOption(HistoryMetaClass.NAME, options, context);
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(); }
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()); }
newOption.addIndex(newIndex);
@Test public void testUpdateChangeIndex() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionChangeIndex"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName2"); newIndex.getKeyList().add(attribute.getName()); newIndex.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.UPDATE); metaService.updateMetaOption(metaClass.getName(), newOption, context); MetaClass getMeta = metaService.getMetaClass(metaClass.getName()); Assert.assertEquals(3, getMeta.getIndexes().size());// check no new index added Assert.assertTrue(getMeta.getIndexByName(index.getIndexName()).getIndexOptions().size() == 1); Assert.assertTrue(getMeta.getIndexByName(index.getIndexName()).getIndexOptions().get(0) == IndexOptionEnum.unique); }
@Test public void testUpdateAddIndexWithInvalidKey() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionAddInvalidIndex"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName2"); newIndex.getKeyList().add("invalid_name"); newIndex.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.ADD); try { metaService.updateMetaOption(metaClass.getName(), newOption, context); } catch (IndexOptionOperationException e) { Assert.assertTrue(e.getMessage().contains("index indexName2 key list contains non-existing field")); } }
@Test public void testUpdateAddIndex() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionAddIndex"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName3"); newIndex.getKeyList().add(attribute.getName()); newIndex.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.ADD); metaService.updateMetaOption(metaClass.getName(), newOption, context); MetaClass getMeta = metaService.getMetaClass(metaClass.getName()); Assert.assertEquals(4, getMeta.getIndexes().size()); Assert.assertTrue(getMeta.getIndexNames().contains(newIndex.getIndexName())); Assert.assertEquals(1, getMeta.getVersion()); }
@Test(expected=IndexExistsException.class) public void testUpdateAddIndexAlreadyExisting() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionAddIndexAlreadyExisitng"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); index.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.ADD); metaService.updateMetaOption(metaClass.getName(), newOption, context); }
@Test(expected = IndexNotExistsException.class) public void testUpdateChangeIndexNotExists() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionChangeIndexNotExists"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName3");//an not existing index index.getKeyList().add(attribute.getName()); index.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.UPDATE); metaService.updateMetaOption(metaClass.getName(), newOption, context); }
@Test(expected = IndexNotExistsException.class) public void testUpdateRemoveIndexNotExists() { MetaClass metaClass = createMetaClass(); metaClass.setName("removeOptionIndexNotExists"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName3");//an not exsisting index index.getKeyList().add(attribute.getName()); index.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.DELETE); metaService.updateMetaOption(metaClass.getName(), newOption, context); }
@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);