public void testDBGeneratorStrategy() throws Exception {

    String template = "SELECT #result('id' 'int') FROM SUS1";
    SQLTemplate query = new SQLTemplate(Object.class, template);

    DataMap map = node.getEntityResolver().getDataMap("sus-map");
    DataNode dataNode = createDataNode(map);
    int sizeDB = getNameTablesInDB(dataNode).size();
    MockOperationObserver observer = new MockOperationObserver();
    try {

      generateDBWithDBGeneratorStrategy(dataNode, query, observer);
      int sizeDB2 = getNameTablesInDB(dataNode).size();
      assertEquals(2, sizeDB2 - sizeDB);
      dataNode.performQueries(Collections.singletonList((Query) query), observer);
      int sizeDB3 = getNameTablesInDB(dataNode).size();
      assertEquals(sizeDB2, sizeDB3);
    } finally {
      DataNode dataNode2 = createDataNode(map);
      dataNode2.setSchemaUpdateStrategy(
          (SchemaUpdateStrategy)
              Class.forName(dataNode2.getSchemaUpdateStrategyName()).newInstance());
      dropTables(map, dataNode2, observer);
    }
    assertEquals(getNameTablesInDB(dataNode).size(), sizeDB);
  }
  public void testMixedStrategyTableNoExist() throws Exception {

    String template = "SELECT #result('id' 'int') FROM SUS1";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    DataMap map = node.getEntityResolver().getDataMap("sus-map");
    DataNode dataNode = createDataNode(map);
    int sizeDB = getNameTablesInDB(dataNode).size();
    MockOperationObserver observer = new MockOperationObserver();

    setStrategy(ThrowOnPartialOrCreateSchemaStrategy.class.getName(), dataNode);

    try {
      dataNode.performQueries(Collections.singletonList((Query) query), observer);
      Map<String, Boolean> nameTables = getNameTablesInDB(dataNode);
      assertTrue(nameTables.get("sus1") != null || nameTables.get("SUS1") != null);
      int sizeDB2 = getNameTablesInDB(dataNode).size();
      assertEquals(2, sizeDB2 - sizeDB);
      dataNode.performQueries(Collections.singletonList((Query) query), observer);
      int sizeDB3 = getNameTablesInDB(dataNode).size();
      assertEquals(sizeDB2, sizeDB3);
    } finally {
      DataNode dataNode2 = createDataNode(map);
      dataNode2.setSchemaUpdateStrategy(
          (SchemaUpdateStrategy)
              Class.forName(dataNode2.getSchemaUpdateStrategyName()).newInstance());
      dropTables(map, dataNode2, observer);
    }
    assertEquals(getNameTablesInDB(dataNode).size(), sizeDB);
  }
 private void setStrategy(String name, DataNode dataNode) {
   dataNode.setSchemaUpdateStrategyName(name);
   try {
     dataNode.setSchemaUpdateStrategy(
         (SchemaUpdateStrategy)
             Class.forName(dataNode.getSchemaUpdateStrategyName()).newInstance());
   } catch (Exception e) {
     throw new CayenneRuntimeException(e);
   }
 }
 private DataNode createDataNode(DataMap map) {
   Collection<DataMap> colection = new ArrayList<DataMap>();
   colection.add(map);
   DataNode dataNode = new DataNode();
   dataNode.setJdbcEventLogger(jdbcEventLogger);
   dataNode.setDataMaps(colection);
   dataNode.setAdapter(adapter);
   dataNode.setDataSource(dataSourceFactory.getSharedDataSource());
   dataNode.setDataSourceFactory(node.getDataSourceFactory());
   dataNode.setSchemaUpdateStrategyName(node.getSchemaUpdateStrategyName());
   dataNode.setEntityResolver(new EntityResolver(colection));
   return dataNode;
 }