Package com.db4o.config

Examples of com.db4o.config.Configuration


  public void removeEntityStoreListener(DatabaseListener listener) {
    fEntityStoreListeners.remove(listener);
  }

  public void createDatabase(LongOperationMonitor progressMonitor) throws PersistenceException {
    Configuration config = createConfiguration();
    int workspaceVersion = getWorkspaceFormatVersion();
    boolean reindexRequired = false;

    SubMonitor subMonitor = null;
    try {
View Full Code Here


      db.commit();
  }

  private Configuration createConfiguration() {
    Configuration config = Db4o.newConfiguration();
    //TODO We can use dbExists to configure our parameters for a more
    //efficient startup. For example, the following could be used. We'd have
    //to include a file when we need to evolve the schema or something similar
    //config.detectSchemaChanges(false)

//    config.blockSize(8);
//    config.bTreeCacheHeight(0);
//    config.bTreeNodeSize(100);
//    config.diagnostic().addListener(new DiagnosticListener() {
//      public void onDiagnostic(Diagnostic d) {
//        System.out.println(d);
//      }
//    });
//    config.messageLevel(3);

    config.automaticShutDown(false);
  config.callbacks(false);
    config.activationDepth(2);
    config.flushFileBuffers(false);
    config.callConstructors(true);
    config.exceptionsOnNotStorable(true);
    configureAbstractEntity(config);
    config.objectClass(BookMark.class).objectField("fFeedLink").indexed(true); //$NON-NLS-1$
    config.objectClass(ConditionalGet.class).objectField("fLink").indexed(true); //$NON-NLS-1$
    configureFeed(config);
    configureNews(config);
    configureSearchMark(config);
    configureFolder(config);
    config.objectClass(NewsCounter.class).cascadeOnDelete(true);
    config.objectClass(Preference.class).cascadeOnDelete(true);
    config.objectClass(Preference.class).objectField("fKey").indexed(true); //$NON-NLS-1$
    return config;
  }
View Full Code Here

      idPropertiesMap.put(mark.getId(), mark.getProperties());
    }

    oc.close();

    Configuration c = Db4o.newConfiguration();

    /* core.model.types to core.persist */
    c.objectClass(IAttachment.class).rename(org.rssowl.core.persist.IAttachment.class.getName());
    c.objectClass(IBookMark.class).rename(org.rssowl.core.persist.IBookMark.class.getName());
    c.objectClass(ICategory.class).rename(org.rssowl.core.persist.ICategory.class.getName());
    c.objectClass(IFeed.class).rename(org.rssowl.core.persist.IFeed.class.getName());
    c.objectClass(IFolder.class).rename(org.rssowl.core.persist.IFolder.class.getName());
    c.objectClass(IImage.class).rename(org.rssowl.core.persist.IImage.class.getName());
    c.objectClass(ILabel.class).rename(org.rssowl.core.persist.ILabel.class.getName());
    c.objectClass(IMark.class).rename(org.rssowl.core.persist.IMark.class.getName());
    c.objectClass(INews.class).rename(org.rssowl.core.persist.INews.class.getName());
    c.objectClass(INews.State.class).rename(org.rssowl.core.persist.INews.State.class.getName());
    c.objectClass(IPerson.class).rename(org.rssowl.core.persist.IPerson.class.getName());
    c.objectClass(ISearchMark.class).rename(org.rssowl.core.persist.ISearchMark.class.getName());
    c.objectClass(ISource.class).rename(org.rssowl.core.persist.ISource.class.getName());

    /* core.model.internal.types to core.internal.persist */
    c.objectClass(AbstractEntity.class).rename(org.rssowl.core.internal.persist.AbstractEntity.class.getName());
    c.objectClass(Attachment.class).rename(org.rssowl.core.internal.persist.Attachment.class.getName());
    c.objectClass(BookMark.class).rename(org.rssowl.core.internal.persist.BookMark.class.getName());
    c.objectClass(Category.class).rename(org.rssowl.core.internal.persist.Category.class.getName());
    c.objectClass(ConditionalGet.class).rename(org.rssowl.core.internal.persist.ConditionalGet.class.getName());
    c.objectClass(Feed.class).rename(org.rssowl.core.internal.persist.Feed.class.getName());
    c.objectClass(Folder.class).rename(org.rssowl.core.internal.persist.Folder.class.getName());
    c.objectClass(Guid.class).rename(org.rssowl.core.internal.persist.Guid.class.getName());
    c.objectClass(Image.class).rename(org.rssowl.core.internal.persist.Image.class.getName());
    c.objectClass(Label.class).rename(org.rssowl.core.internal.persist.Label.class.getName());
    c.objectClass(Mark.class).rename(org.rssowl.core.internal.persist.Mark.class.getName());
    c.objectClass(News.class).rename(org.rssowl.core.internal.persist.News.class.getName());
    c.objectClass(ExtendableType.class).rename(org.rssowl.core.internal.persist.AbstractEntity.class.getName());
    c.objectClass(Person.class).rename(org.rssowl.core.internal.persist.Person.class.getName());
    c.objectClass(SearchMark.class).rename(org.rssowl.core.internal.persist.SearchMark.class.getName());
    c.objectClass(Source.class).rename(org.rssowl.core.internal.persist.Source.class.getName());

    /* Search-related classes*/
    c.objectClass(SearchSpecifier.class).rename(org.rssowl.core.persist.SearchSpecifier.class.getName());
    c.objectClass(SearchCondition.class).rename(org.rssowl.core.internal.persist.SearchCondition.class.getName());
    c.objectClass(ISearchField.class).rename(org.rssowl.core.persist.ISearchField.class.getName());
    c.objectClass(SearchField.class).rename(org.rssowl.core.internal.persist.SearchField.class.getName());
    c.objectClass(SearchValueType.class).rename(org.rssowl.core.internal.persist.SearchValueType.class.getName());

    /* Counter */
    c.objectClass(Counter.class).rename(org.rssowl.core.internal.persist.service.Counter.class.getName());

    oc = Db4o.openFile(c, dbFileName);
    oc.close();
    /* 10 */
    progressMonitor.worked(10);

    oc = Db4o.openFile(configFactory.createConfiguration(), dbFileName);

    /* Preference */
    for (Preference pref : oc.query(Preference.class)) {
      oc.activate(pref, Integer.MAX_VALUE);
      oc.ext().set(convertPref(pref), Integer.MAX_VALUE);
      oc.delete(pref);
    }
    oc.commit();
    /* 20 */
    progressMonitor.worked(10);

    for (org.rssowl.core.persist.ISearchField searchField : oc.query(org.rssowl.core.internal.persist.SearchField.class))   {
      oc.activate(searchField, Integer.MAX_VALUE);
      String entityName = searchField.getEntityName();
      entityName = entityName.replace("core.model.types", "core.persist");
      MigrationHelper.setField(searchField, "fEntityName", entityName);
      oc.ext().set(searchField, Integer.MAX_VALUE);
    }
    oc.commit();
    /* 30 */
    progressMonitor.worked(10);

    for (org.rssowl.core.persist.ISearchCondition searchCond : oc.query(org.rssowl.core.internal.persist.SearchCondition.class))   {
      oc.activate(searchCond, Integer.MAX_VALUE);
      int searchSpecOrdinal = searchCond.getSpecifier().ordinal();
      org.rssowl.core.persist.SearchSpecifier searchSpec = org.rssowl.core.persist.SearchSpecifier.values()[searchSpecOrdinal];
      MigrationHelper.setField(searchCond, "fSpecifier", searchSpec);
      oc.ext().set(searchCond, Integer.MAX_VALUE);
    }
    oc.commit();
    /* 40 */
    progressMonitor.worked(10);

    List<org.rssowl.core.persist.IFolder> folders = new ArrayList<org.rssowl.core.persist.IFolder>();
    for (org.rssowl.core.persist.IFolder folder : oc.query(org.rssowl.core.internal.persist.Folder.class))   {
      oc.activate(folder, Integer.MAX_VALUE);
      List<IFolderChild> children = new ArrayList<IFolderChild>(getFolderChildren(folder, "fFolders"));
      MigrationHelper.setField(folder, "fFolders", null);
      children.addAll(getFolderChildren(folder, "fMarks"));
      MigrationHelper.setField(folder, "fMarks", null);
      MigrationHelper.setField(folder, "fChildren", children);
      folders.add(folder);
    }
    /* Only save folders once they have all been updated */
    for (org.rssowl.core.persist.IFolder folder : folders)   {
      oc.ext().set(folder, Integer.MAX_VALUE);
    }

    List<org.rssowl.core.persist.IMark> marks = new ArrayList<org.rssowl.core.persist.IMark>();
    for (org.rssowl.core.persist.IMark mark : oc.query(org.rssowl.core.internal.persist.Mark.class))   {
      oc.activate(mark, Integer.MAX_VALUE);
      org.rssowl.core.persist.IFolder parent = (org.rssowl.core.persist.IFolder) MigrationHelper.getFieldValue(mark, "fFolder");
      MigrationHelper.setField(mark, "fFolder", null);
      MigrationHelper.setField(mark, "fParent", parent);

      /*
       * If ISearchMark contains a search condition with INews.State, replace
       * it with an EnumSet<INews.State>.
       */
      if (mark instanceof org.rssowl.core.persist.ISearchMark) {
        org.rssowl.core.persist.ISearchMark searchMark = (org.rssowl.core.persist.ISearchMark) mark;
        EnumSet<org.rssowl.core.persist.INews.State> states = EnumSet.noneOf(org.rssowl.core.persist.INews.State.class);
        List<ISearchCondition> searchConds = new ArrayList<ISearchCondition>();
        for (ISearchCondition searchCond : searchMark.getSearchConditions()) {
          org.rssowl.core.persist.ISearchField searchField = searchCond.getField();
          if (searchField.getEntityName().equals(org.rssowl.core.persist.INews.class.getName()) && searchField.getId() == INews.STATE)  {
            states.add((org.rssowl.core.persist.INews.State) searchCond.getValue());
          }
          else {
            searchConds.add(searchCond);
          }
        }
        if (!states.isEmpty()) {
          IModelFactory factory = InternalOwl.getDefault().getModelFactory();
          org.rssowl.core.persist.ISearchField field = factory.createSearchField(INews.STATE, org.rssowl.core.persist.INews.class.getName());
          searchConds.add(factory.createSearchCondition(field, org.rssowl.core.persist.SearchSpecifier.IS, states));
          MigrationHelper.setField(mark, "fSearchConditions", searchConds);
        }
      }

      marks.add(mark);
    }
    /* Only save folders once they have all been updated */
    for (org.rssowl.core.persist.IMark mark : marks)   {
      oc.ext().set(mark, Integer.MAX_VALUE);
    }

    oc.commit();
    /* 80 */
    progressMonitor.worked(40);

    for (Map.Entry<Long, Map<String, ?>> entry : idPropertiesMap.entrySet()) {
      Query query = oc.query();
      query.constrain(org.rssowl.core.internal.persist.AbstractEntity.class);
      query.descend("fId").constrain(entry.getKey()); //$NON-NLS-1$
      List<?> list = query.execute();
      org.rssowl.core.internal.persist.AbstractEntity entity = (org.rssowl.core.internal.persist.AbstractEntity) list.get(0);
      oc.activate(entity, Integer.MAX_VALUE);
      for (Map.Entry<String, ?> valueEntry : entry.getValue().entrySet()) {
        entity.setProperty(valueEntry.getKey(), valueEntry.getValue());
      }
      oc.ext().set(entity, Integer.MAX_VALUE);
    }
    /* 90 */
    progressMonitor.worked(10);
    oc.close();

    /* Disable indices to force them to be re-created */
    Configuration config = configFactory.createConfiguration();
    config.objectClass(org.rssowl.core.internal.persist.BookMark.class).objectField("fFeedLink").indexed(false); //$NON-NLS-1$
    config.objectClass(org.rssowl.core.internal.persist.ConditionalGet.class).objectField("fLink").indexed(false); //$NON-NLS-1$
    config.objectClass(org.rssowl.core.internal.persist.Preference.class).objectField("fKey").indexed(false); //$NON-NLS-1$
    config.objectClass(org.rssowl.core.internal.persist.Feed.class).objectField("fLinkText").indexed(false);
    config.objectClass(org.rssowl.core.internal.persist.News.class).objectField("fLinkText").indexed(false); //$NON-NLS-1$
    config.objectClass(org.rssowl.core.internal.persist.News.class).objectField("fGuidValue").indexed(false);
    config.objectClass(org.rssowl.core.internal.persist.News.class).objectField("fFeedLink").indexed(false); //$NON-NLS-1$
    config.objectClass(org.rssowl.core.internal.persist.News.class).objectField("fStateOrdinal").indexed(false); //$NON-NLS-1$
    oc = Db4o.openFile(config, dbFileName);

    /* Access classes with index */
    ObjectSet<org.rssowl.core.internal.persist.BookMark> markSet = oc.query(org.rssowl.core.internal.persist.BookMark.class);
    if (markSet.hasNext())
View Full Code Here

   
    fireDatabaseEvent(new DatabaseEvent(fObjectContainer, fLock), true);
  }

  private void configure() {
    Configuration globalConfig = Db4o.configure();
    globalConfig.callbacks(false);
//    globalConfig.blockSize(8);
//    globalConfig.bTreeCacheHeight(0);
//    globalConfig.bTreeNodeSize(100);
//    globalConfig.diagnostic().addListener(new DiagnosticListener() {
//      public void onDiagnostic(Diagnostic d) {
//        System.out.println(d);
//      }
//    });
    globalConfig.messageLevel(0);
    globalConfig.activationDepth(1);
    globalConfig.flushFileBuffers(false);
    globalConfig.callConstructors(true);
    globalConfig.exceptionsOnNotStorable(true);
    globalConfig.objectClass(AbstractEntity.class).objectField("fId").indexed(true); //$NON-NLS-1$
    globalConfig.objectClass(AbstractEntity.class).objectField("fId").cascadeOnActivate(true); //$NON-NLS-1$
    globalConfig.objectClass(BookMark.class).objectField("fFeedId").indexed(true); //$NON-NLS-1$
    globalConfig.objectClass(ConditionalGet.class).objectField("fLink").indexed(true); //$NON-NLS-1$
//    globalConfig.objectClass(IPerson.class).cascadeOnUpdate(true);
//    globalConfig.objectClass(IImage.class).cascadeOnUpdate(true);
//    globalConfig.objectClass(ILabel.class).cascadeOnUpdate(true);
//    globalConfig.objectClass(ICategory.class).cascadeOnUpdate(true);
//    globalConfig.objectClass(ISource.class).cascadeOnUpdate(true);
    configureFeed();
    configureNews();
    configureSearchMark();
    configureFolder();
    globalConfig.objectClass(Preference.class).cascadeOnDelete(true);
    globalConfig.objectClass(Preference.class).objectField("fKey").indexed(true); //$NON-NLS-1$
  }
View Full Code Here

    /* Assert File Permissions */
    checkDirPermissions();

    /* Create Configuration and check for Migration */
    Configuration config = createConfiguration(false);
    int workspaceVersion = getWorkspaceFormatVersion();
    MigrationResult migrationResult = new MigrationResult(false, false, false);

    SubMonitor subMonitor = null;
    try {
View Full Code Here

   * for the defrag process and <code>false</code> otherwise to return a normal
   * configuration suitable for the application.
   * @return Configuration
   */
  public static final Configuration createConfiguration(boolean forDefrag) {
    Configuration config = Db4o.newConfiguration();
    //TODO We can use dbExists to configure our parameters for a more
    //efficient startup. For example, the following could be used. We'd have
    //to include a file when we need to evolve the schema or something similar
    //config.detectSchemaChanges(false)

    //    config.blockSize(8);
    //    config.bTreeCacheHeight(0);
    //    config.bTreeNodeSize(100);
    //    config.diagnostic().addListener(new DiagnosticListener() {
    //      public void onDiagnostic(Diagnostic d) {
    //        System.out.println(d);
    //      }
    //    });

    config.setOut(new PrintStream(new ByteArrayOutputStream()) {
      @Override
      public void write(byte[] buf, int off, int len) {
        if (buf != null && len >= 0 && off >= 0 && off <= buf.length - len)
          CoreUtils.appendLogMessage(new String(buf, off, len));
      }
    });

    config.lockDatabaseFile(false);
    config.queries().evaluationMode(forDefrag ? QueryEvaluationMode.LAZY : QueryEvaluationMode.IMMEDIATE);
    config.automaticShutDown(false);
    config.callbacks(false);
    config.activationDepth(2);
    config.callConstructors(true);
    config.exceptionsOnNotStorable(true);
    configureAbstractEntity(config);
    config.objectClass(BookMark.class).objectField("fFeedLink").indexed(true); //$NON-NLS-1$
    config.objectClass(ConditionalGet.class).objectField("fLink").indexed(true); //$NON-NLS-1$
    configureFeed(config);
    configureNews(config);
    configureFolder(config);
    config.objectClass(Description.class).objectField("fNewsId").indexed(true); //$NON-NLS-1$
    config.objectClass(NewsCounter.class).cascadeOnDelete(true);
    config.objectClass(Preference.class).cascadeOnDelete(true);
    config.objectClass(Preference.class).objectField("fKey").indexed(true); //$NON-NLS-1$
    config.objectClass(SearchFilter.class).objectField("fActions").cascadeOnDelete(true); //$NON-NLS-1$

    if (isIBM_VM_1_6()) //See defect 733
      config.objectClass("java.util.MiniEnumSet").translate(new com.db4o.config.TSerializable()); //$NON-NLS-1$

    return config;
  }
View Full Code Here

  /**
   * @param databaseKey The encryption key to the database. Null if the database is not encrypted
   * @return A new Db4o Configuration object which is fully configured to Fred's desired database settings.
   */
  private Configuration getNewDatabaseConfiguration(DatabaseKey databaseKey) {
    Configuration dbConfig = Db4o.newConfiguration();
    /* On my db4o test node with lots of downloads, and several days old, com.db4o.internal.freespace.FreeSlotNode
     * used 73MB out of the 128MB limit (117MB used). This memory was not reclaimed despite constant garbage collection.
     * This is unacceptable, hence btree freespace. */
    dbConfig.freespace().useBTreeSystem();
    /*
     * HashMap: don't enable cascade on update/delete/activate, db4o handles this
     * internally through the TMap translator.
     */
    // LAZY appears to cause ClassCastException's relating to db4o objects inside db4o code. :(
    // Also it causes duplicates if we activate immediately.
    // And the performance gain for e.g. RegisterMeRunner isn't that great.
//    dbConfig.queries().evaluationMode(QueryEvaluationMode.LAZY);
    dbConfig.messageLevel(1);
    dbConfig.activationDepth(1);
    /* TURN OFF SHUTDOWN HOOK.
     * The shutdown hook does auto-commit. We do NOT want auto-commit: if a
     * transaction hasn't commit()ed, it's not safe to commit it. For example,
     * a splitfile is started, gets half way through, then we shut down.
     * The shutdown hook commits the half-finished transaction. When we start
     * back up, we assume the whole transaction has been committed, and end
     * up only registering the proportion of segments for which a RegisterMe
     * has already been created. Yes, this has happened, yes, it sucks.
     * Add our own hook to rollback and close... */
    dbConfig.automaticShutDown(false);
    /* Block size 8 should have minimal impact since pointers are this
     * long, and allows databases of up to 16GB.
     * FIXME make configurable by user. */
    dbConfig.blockSize(8);
    dbConfig.diagnostic().addListener(new DB4ODiagnosticListener());

    dbConfig.exceptionsOnNotStorable(false);

    System.err.println("Optimise native queries: "+dbConfig.optimizeNativeQueries());
    System.err.println("Query activation depth: "+dbConfig.activationDepth());

    // The database is encrypted.
    if(databaseKey != null) {
      IoAdapter baseAdapter = dbConfig.io();
      try {
        dbConfig.io(databaseKey.createEncryptingDb4oAdapter(baseAdapter));
      } catch (GlobalOnlyConfigException e) {
        // Fouled up after encrypting/decrypting.
        System.err.println("Caught "+e+" opening encrypted database.");
        e.printStackTrace();
        WrapperManager.restart();
View Full Code Here

* @author Sergio Bossa
*/
public class Db4oConfigurationFactory {
   
    public Configuration getConfiguration() {
        Configuration configuration = Db4o.configure();
        this.configureUser(configuration);
        this.configureFeedSubscription(configuration);
        this.configureOtherObjects(configuration);
        return configuration;
    }
View Full Code Here

    super(config);
  }

  @Override
  protected Configuration getConfiguration() {
    final Configuration c = Db4o.newConfiguration();
    //c.generateVersionNumbers(ConfigScope.GLOBALLY);
    c.updateDepth(3);
    return c;
  }
View Full Code Here

  /**
   * @return The desired db4o config instance to employ. May be overridden.
   */
  protected Configuration getConfiguration() {
    final Configuration c = Db4o.newConfiguration();
    c.generateVersionNumbers(ConfigScope.GLOBALLY);
    c.updateDepth(3);
    return c;
  }
View Full Code Here

TOP

Related Classes of com.db4o.config.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.