private void dropTables(DataMap map, DataNode dataNode, MockOperationObserver observer) {
   Collection<DbEntity> ent = map.getDbEntities();
   Iterator<DbEntity> iterator = ent.iterator();
   while (iterator.hasNext()) {
     Collection<String> collectionDrop =
         dataNode.getAdapter().dropTableStatements(iterator.next());
     for (String s : collectionDrop) {
       SQLTemplate queryDrop = new SQLTemplate(Object.class, s);
       dataNode.performQueries(Collections.singletonList((Query) queryDrop), observer);
     }
   }
 }
  private DbEntity createOneTable(DataNode dataNode) {
    DataMap map = node.getEntityResolver().getDataMap("sus-map");
    Collection<DbEntity> ent = map.getDbEntities();
    DbEntity entity = ent.iterator().next();
    String template = dataNode.getAdapter().createTable(entity);

    SQLTemplate query = new SQLTemplate(Object.class, template);
    MockOperationObserver observer = new MockOperationObserver();

    setStrategy(null, dataNode);

    dataNode.performQueries(Collections.singletonList((Query) query), observer);
    return entity;
  }
  private void withOneTableForThrowOnPartialAndMixStrategy(String strategy) {
    DbEntity entity = null;
    String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    DataMap map = node.getEntityResolver().getDataMap("sus-map");
    MockOperationObserver observer = new MockOperationObserver();
    DataNode dataNode = createDataNode(map);

    DataNode dataNode2 = createDataNode(map);

    try {

      int sizeDB = getNameTablesInDB(dataNode).size();
      entity = createOneTable(dataNode);
      int sizeDB2 = getNameTablesInDB(dataNode).size();
      assertEquals(1, sizeDB2 - sizeDB);
      setStrategy(strategy, dataNode2);
      dataNode2.performQueries(Collections.singletonList((Query) query), observer);

    } catch (CayenneRuntimeException e) {
      assertNotNull(e);
    }
    try {
      dataNode2.performQueries(Collections.singletonList((Query) query), observer);
    } catch (CayenneRuntimeException e) {
      assertNotNull(e);
    } finally {

      if (entity != null) {

        Collection<String> template2 = dataNode.getAdapter().dropTableStatements(entity);
        Iterator<String> it = template2.iterator();
        List<Query> list = new ArrayList<Query>();
        while (it.hasNext()) {
          SQLTemplate q = new SQLTemplate(Object.class, it.next());
          list.add(q);
        }
        dataNode.performQueries(list, observer);
      }
    }
  }
 private Map<String, Boolean> getNameTablesInDB(DataNode dataNode) {
   String tableLabel = dataNode.getAdapter().tableTypeForTable();
   Connection con = null;
   Map<String, Boolean> nameTables = new HashMap<String, Boolean>();
   try {
     con = dataNode.getDataSource().getConnection();
     ResultSet rs = con.getMetaData().getTables(null, null, "%", new String[] {tableLabel});
     while (rs.next()) {
       String name = rs.getString("TABLE_NAME");
       nameTables.put(name, false);
     }
     rs.close();
   } catch (SQLException e) {
     throw new CayenneRuntimeException(e);
   } finally {
     try {
       con.close();
     } catch (SQLException e) {
       throw new CayenneRuntimeException(e);
     }
   }
   return nameTables;
 }