コード例 #1
0
 private StoreData buildStoreDataWithTable(ClassMetaData cmd, DatastoreTable table) {
   MappedStoreData sd = new MappedStoreData(cmd, table, false);
   registerStoreData(sd);
   sd.setDatastoreContainerObject(table);
   table.manageClass(cmd);
   return sd;
 }
コード例 #2
0
  /**
   * This method requires synchronization so that we don't end up registering the same property more
   * than once.
   */
  @Override
  protected synchronized StoreData newStoreData(ClassMetaData cmd, ClassLoaderResolver clr) {
    InheritanceStrategy strat = cmd.getInheritanceMetaData().getStrategy();

    // The overarching rule for supported inheritance strategies is that we
    // don't split the state of an object across multiple entities.
    // TODO This is all nonsense. This datastore only allows "COMPLETE_TABLE" really so ignore the
    // inheritance
    // and remove the need for DatastoreClass
    if (strat == InheritanceStrategy.SUBCLASS_TABLE) {
      // Table mapped into the table(s) of subclass(es)
      // Just add the SchemaData entry with no table - managed by subclass
      return buildStoreDataWithNoTable(cmd);
    } else if (strat == InheritanceStrategy.COMPLETE_TABLE) {
      if (cmd.isAbstract()) {
        // Abstract class with "complete-table" so gets no table
        return buildStoreDataWithNoTable(cmd);
      }
      return buildStoreData(cmd, clr);
    } else if (strat == InheritanceStrategy.NEW_TABLE
        && (cmd.getSuperAbstractClassMetaData() == null
            || cmd.getSuperAbstractClassMetaData().getInheritanceMetaData().getStrategy()
                == InheritanceStrategy.SUBCLASS_TABLE)) {
      // New Table means you store your fields and your fields only (no fields from superclasses).
      // This only ok if you don't have a persistent superclass or your persistent superclass has
      // delegated responsibility for storing its fields to you.
      return buildStoreData(cmd, clr);
    } else if (MetaDataUtils.isNewOrSuperclassTableInheritanceStrategy(cmd)) {
      // Table mapped into table of superclass
      // Find the superclass - should have been created first
      AbstractClassMetaData[] managingCmds = getClassesManagingTableForClass(cmd, clr);
      DatastoreTable superTable;
      if (managingCmds != null && managingCmds.length == 1) {
        MappedStoreData superData =
            (MappedStoreData) storeDataMgr.get(managingCmds[0].getFullClassName());
        if (superData != null) {
          // Specify the table if it already exists
          superTable = (DatastoreTable) superData.getDatastoreContainerObject();
          return buildStoreDataWithTable(cmd, superTable);
        }
      }
    }

    // TODO Don't do this. GAE basically supports "complete-table" always so we should just ignore
    // any
    // inheritance metadata that implies otherwise.
    boolean jpa = getApiAdapter().getName().equalsIgnoreCase("JPA");
    String unsupportedMsg =
        GAE_LOCALISER.msg(
            jpa ? "AppEngine.BadInheritance.JPA" : "AppEngine.BadInheritance.JDO",
            cmd.getInheritanceMetaData().getStrategy().toString(),
            cmd.getFullClassName(),
            getApiAdapter().getName());
    throw new UnsupportedInheritanceStrategyException(unsupportedMsg);
  }