Example #1
0
  @Test
  public void should_construct_schema_cache() {
    // GIVEN
    Collection<SchemaRule> rules = asList(hans, witch, gretel);
    SchemaCache cache = new SchemaCache(rules);

    // THEN
    assertEquals(asSet(hans, gretel), asSet(cache.schemaRulesForLabel(0)));
    assertEquals(asSet(witch), asSet(cache.schemaRulesForLabel(3)));
    assertEquals(asSet(rules), asSet(cache.schemaRules()));
  }
Example #2
0
  @Test
  public void should_to_retrieve_all_schema_rules() {
    // GIVEN
    Collection<SchemaRule> rules = asList();
    SchemaCache cache = new SchemaCache(rules);

    // WHEN
    cache.addSchemaRule(hans);
    cache.addSchemaRule(gretel);

    // THEN
    assertEquals(asSet(hans, gretel), asSet(cache.schemaRules()));
  }
Example #3
0
  @Test
  public void should_add_schema_rules_to_a_label() {
    // GIVEN
    Collection<SchemaRule> rules = asList();
    SchemaCache cache = new SchemaCache(rules);

    // WHEN
    cache.addSchemaRule(hans);
    cache.addSchemaRule(gretel);

    // THEN
    assertEquals(asSet(hans, gretel), asSet(cache.schemaRulesForLabel(0)));
  }
Example #4
0
  @Test
  public void shouldResolveIndexId() throws Exception {
    // Given
    Collection<SchemaRule> rules = asList();
    SchemaCache cache = new SchemaCache(rules);

    cache.addSchemaRule(newIndexRule(1l, 1, 2));
    cache.addSchemaRule(newIndexRule(2l, 1, 3));
    cache.addSchemaRule(newIndexRule(3l, 2, 2));

    // When
    long indexId = cache.indexId(new IndexDescriptor(1, 3));

    // Then
    assertThat(indexId, equalTo(2l));
  }
Example #5
0
 @Association
 public Collection<PostgreSchema> getSchemas(DBRProgressMonitor monitor) throws DBException {
   if (this != dataSource.getDefaultInstance()) {
     throw new DBException("Can't access non-default database");
   }
   // Get all schemas
   return schemaCache.getAllObjects(monitor, this);
 }
Example #6
0
  public PostgreDataType getDataType(String typeName) {
    if (typeName.endsWith("[]")) {
      // In some cases ResultSetMetadata returns it as []
      typeName = "_" + typeName.substring(0, typeName.length() - 2);
    }
    String alias = PostgreConstants.DATA_TYPE_ALIASES.get(typeName);
    if (alias != null) {
      typeName = alias;
    }
    {
      // First check system catalog
      final PostgreSchema schema = getCatalogSchema();
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }

    // Check schemas in search path
    final List<String> searchPath = dataSource.getSearchPath();
    for (String schemaName : searchPath) {
      final PostgreSchema schema = schemaCache.getCachedObject(schemaName);
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }
    // Check the rest
    for (PostgreSchema schema : schemaCache.getCachedObjects()) {
      if (searchPath.contains(schema.getName())) {
        continue;
      }
      final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
      if (dataType != null) {
        return dataType;
      }
    }
    log.debug("Data type '" + typeName + "' not found in database '" + getName() + "'");
    return null;
  }
Example #7
0
 public PostgreSchema getSchema(DBRProgressMonitor monitor, long oid) throws DBException {
   if (this != dataSource.getDefaultInstance()) {
     throw new DBException("Can't access non-default database");
   }
   for (PostgreSchema schema : schemaCache.getAllObjects(monitor, this)) {
     if (schema.getObjectId() == oid) {
       return schema;
     }
   }
   return null;
 }
Example #8
0
  @Override
  public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException {
    authIdCache.clearCache();
    accessMethodCache.clearCache();
    languageCache.clearCache();
    encodingCache.clearCache();
    tablespaceCache.clearCache();
    schemaCache.clearCache();

    cacheDataTypes(monitor);
    return this;
  }
Example #9
0
  @Test
  public void shouldResolveIndexDescriptor() throws Exception {
    // Given
    Collection<SchemaRule> rules = asList();
    SchemaCache cache = new SchemaCache(rules);

    cache.addSchemaRule(newIndexRule(1l, 1, 2));
    cache.addSchemaRule(newIndexRule(2l, 1, 3));
    cache.addSchemaRule(newIndexRule(3l, 2, 2));

    // When
    try {
      cache.indexDescriptor(9, 9);
      fail(
          "Should have thrown exception saying there's no index descriptor for that label/property");
    } catch (SchemaRuleNotFoundException e) { // Good
    }
    IndexDescriptor descriptor = cache.indexDescriptor(1, 3);

    // Then
    assertEquals(1, descriptor.getLabelId());
    assertEquals(3, descriptor.getPropertyKeyId());
  }
Example #10
0
  @Test
  public void should_remove_constraints() {
    // GIVEN
    Collection<SchemaRule> rules = asList();
    SchemaCache cache = new SchemaCache(rules);

    cache.addSchemaRule(uniquenessConstraintRule(0l, 1, 2, 133l));
    cache.addSchemaRule(uniquenessConstraintRule(1l, 3, 4, 133l));

    // WHEN
    cache.removeSchemaRule(0l);

    // THEN
    assertEquals(asSet(new UniquenessConstraint(3, 4)), asSet(cache.constraints()));

    assertEquals(asSet(), asSet(cache.constraintsForLabel(1)));

    assertEquals(asSet(), asSet(cache.constraintsForLabelAndProperty(1, 2)));
  }
 @Override
 public void expireSchemaElement(long schemaId) {
   cache.expireSchemaElement(schemaId);
 }
 @Override
 public EntryList getSchemaRelations(long schemaId, BaseRelationType type, Direction dir) {
   incAction(METRICS_RELATIONS, CacheMetricsAction.RETRIEVAL);
   return cache.getSchemaRelations(schemaId, type, dir);
 }
 @Override
 public Long getSchemaId(String schemaName) {
   incAction(METRICS_TYPENAME, CacheMetricsAction.RETRIEVAL);
   return cache.getSchemaId(schemaName);
 }
Example #14
0
 @Nullable
 @Override
 public PostgreSchema getDefaultObject() {
   return schemaCache.getCachedObject(dataSource.getActiveSchemaName());
 }
Example #15
0
 public PostgreSchema getSchema(DBRProgressMonitor monitor, String name) throws DBException {
   if (this != dataSource.getDefaultInstance()) {
     throw new DBException("Can't access non-default database");
   }
   return schemaCache.getObject(monitor, this, name);
 }
Example #16
0
 @Nullable
 PostgreSchema getCatalogSchema() {
   return schemaCache.getCachedObject(PostgreConstants.CATALOG_SCHEMA_NAME);
 }