test_class.declarator: mockTable1 = mockHelper.createMock("mockTable1", ITableInfo.class)
test_class.modifier: private
test_class.original_string: private ITableInfo mockTable1 = mockHelper.createMock("mockTable1", ITableInfo.class);
test_class.type: ITableInfo
test_class.var_name: mockTable1
test_class.declarator: mockTable2 = mockHelper.createMock("mockTable2", ITableInfo.class)
test_class.modifier: private
test_class.original_string: private ITableInfo mockTable2 = mockHelper.createMock("mockTable2", ITableInfo.class);
test_class.type: ITableInfo
test_class.var_name: mockTable2
test_class.declarator: mockTable3 = mockHelper.createMock("mockTable3", ITableInfo.class)
test_class.modifier: private
test_class.original_string: private ITableInfo mockTable3 = mockHelper.createMock("mockTable3", ITableInfo.class);
test_class.type: ITableInfo
test_class.var_name: mockTable3
test_class.declarator: mockSQLDatabaseMetaData =
  		mockHelper.createMock("mockSQLDatabaseMetaData", SQLDatabaseMetaData.class)
test_class.modifier: private
test_class.original_string: private SQLDatabaseMetaData mockSQLDatabaseMetaData =
  		mockHelper.createMock("mockSQLDatabaseMetaData", SQLDatabaseMetaData.class);
test_class.type: SQLDatabaseMetaData
test_class.var_name: mockSQLDatabaseMetaData
test_class.file: sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilitiesTest.java
test_class.identifier: SQLUtilitiesTest
test_class.superclass: extends BaseSQuirreLJUnit4TestCase
test_case.body: @Test
  	public void testGetInsertionOrder() throws SQLException
  	{
  
  		ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>();
  
  		expect(mockTable1.getSimpleName()).andStubReturn("mockTable1");
  		expect(mockTable1.getImportedKeys()).andStubReturn(null);
  		expect(mockTable1.getExportedKeys()).andStubReturn(null);
  		
  		expect(mockTable2.getSimpleName()).andStubReturn("mockTable2");
  		expect(mockTable2.getImportedKeys()).andStubReturn(null);
  		expect(mockTable2.getExportedKeys()).andStubReturn(null);
  
  		
  		expect(mockTable3.getSimpleName()).andStubReturn("mockTable3");
  		expect(mockTable3.getImportedKeys()).andStubReturn(null);
  		expect(mockTable3.getExportedKeys()).andStubReturn(null);
  		
  		tables.add(mockTable1);
  		tables.add(mockTable2);
  		tables.add(mockTable3);
  
  		final ForeignKeyInfo[] noFkArray = new ForeignKeyInfo[0];
  		
  		expect(mockSQLDatabaseMetaData.getImportedKeysInfo(mockTable1)).andStubReturn(noFkArray);
  		mockTable1.setImportedKeys(noFkArray);
  		expect(mockSQLDatabaseMetaData.getExportedKeysInfo(mockTable1)).andStubReturn(noFkArray);
  		mockTable1.setExportedKeys(noFkArray);
  		
  		expect(mockSQLDatabaseMetaData.getImportedKeysInfo(mockTable2)).andStubReturn(noFkArray);
  		mockTable2.setImportedKeys(noFkArray);
  		expect(mockSQLDatabaseMetaData.getExportedKeysInfo(mockTable2)).andStubReturn(noFkArray);
  		mockTable2.setExportedKeys(noFkArray);
  
  		expect(mockSQLDatabaseMetaData.getImportedKeysInfo(mockTable3)).andStubReturn(noFkArray);
  		mockTable3.setImportedKeys(noFkArray);
  		expect(mockSQLDatabaseMetaData.getExportedKeysInfo(mockTable3)).andStubReturn(noFkArray);
  		mockTable3.setExportedKeys(noFkArray);
  		
  		mockHelper.replayAll();
  
  		try
  		{
  			List<ITableInfo> result =
  				SQLUtilities.getInsertionOrder(tables, mockSQLDatabaseMetaData, new ProgressCallBackAdaptor());
  			Assert.assertEquals(tables.size(), result.size());
  		}
  		catch (Exception e)
  		{
  			fail("Unexpected exception: " + e.getMessage());
  		}
  
  		mockHelper.verifyAll();
  	}
test_case.class_method_signature: SQLUtilitiesTest.testGetInsertionOrder()
test_case.full_signature: @Test public void testGetInsertionOrder()
test_case.identifier: testGetInsertionOrder
test_case.invocations: andStubReturn expect getSimpleName andStubReturn expect getImportedKeys andStubReturn expect getExportedKeys andStubReturn expect getSimpleName andStubReturn expect getImportedKeys andStubReturn expect getExportedKeys andStubReturn expect getSimpleName andStubReturn expect getImportedKeys andStubReturn expect getExportedKeys add add add andStubReturn expect getImportedKeysInfo setImportedKeys andStubReturn expect getExportedKeysInfo setExportedKeys andStubReturn expect getImportedKeysInfo setImportedKeys andStubReturn expect getExportedKeysInfo setExportedKeys andStubReturn expect getImportedKeysInfo setImportedKeys andStubReturn expect getExportedKeysInfo setExportedKeys replayAll getInsertionOrder assertEquals size size fail getMessage verifyAll
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetInsertionOrder()
focal_class.declarator: s_log = LoggerController.createLogger(SQLUtilities.class)
focal_class.modifier: private final static
focal_class.original_string: private final static ILogger s_log = LoggerController.createLogger(SQLUtilities.class);
focal_class.type: ILogger
focal_class.var_name: s_log
focal_class.file: sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/SQLUtilities.java
focal_class.identifier: SQLUtilities
focal_class.class_method_signature: SQLUtilities.quoteIdentifier(String s)
focal_class.full_signature: public static String quoteIdentifier(String s)
focal_class.identifier: quoteIdentifier
focal_class.modifiers: public static
focal_class.parameters: (String s)
focal_class.return: String
focal_class.signature: String quoteIdentifier(String s)
focal_class.class_method_signature: SQLUtilities.getDeletionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.full_signature: public static List<ITableInfo> getDeletionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.identifier: getDeletionOrder
focal_class.modifiers: public static
focal_class.parameters: (List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.return: List<ITableInfo>
focal_class.signature: List<ITableInfo> getDeletionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.class_method_signature: SQLUtilities.getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.full_signature: public static List<ITableInfo> getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.identifier: getInsertionOrder
focal_class.modifiers: public static
focal_class.parameters: (List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.return: List<ITableInfo>
focal_class.signature: List<ITableInfo> getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_class.class_method_signature: SQLUtilities.getImportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.full_signature: public static ForeignKeyInfo[] getImportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.identifier: getImportedKeys
focal_class.modifiers: public static
focal_class.parameters: (ITableInfo ti, SQLDatabaseMetaData md)
focal_class.return: ForeignKeyInfo[]
focal_class.signature: ForeignKeyInfo[] getImportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.class_method_signature: SQLUtilities.getExportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.full_signature: public static ForeignKeyInfo[] getExportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.identifier: getExportedKeys
focal_class.modifiers: public static
focal_class.parameters: (ITableInfo ti, SQLDatabaseMetaData md)
focal_class.return: ForeignKeyInfo[]
focal_class.signature: ForeignKeyInfo[] getExportedKeys(ITableInfo ti, SQLDatabaseMetaData md)
focal_class.class_method_signature: SQLUtilities.reorderTables(List<ITableInfo> sandwiches)
focal_class.full_signature: private static void reorderTables(List<ITableInfo> sandwiches)
focal_class.identifier: reorderTables
focal_class.modifiers: private static
focal_class.parameters: (List<ITableInfo> sandwiches)
focal_class.return: void
focal_class.signature: void reorderTables(List<ITableInfo> sandwiches)
focal_class.class_method_signature: SQLUtilities.getExtFKParents(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.full_signature: public static List<String> getExtFKParents(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.identifier: getExtFKParents
focal_class.modifiers: public static
focal_class.parameters: (SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.return: List<String>
focal_class.signature: List<String> getExtFKParents(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.class_method_signature: SQLUtilities.getExtFKChildren(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.full_signature: public static List<String> getExtFKChildren(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.identifier: getExtFKChildren
focal_class.modifiers: public static
focal_class.parameters: (SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.return: List<String>
focal_class.signature: List<String> getExtFKChildren(SQLDatabaseMetaData md, List<ITableInfo> tables)
focal_class.class_method_signature: SQLUtilities.closeResultSet(ResultSet rs)
focal_class.full_signature: public static void closeResultSet(ResultSet rs)
focal_class.identifier: closeResultSet
focal_class.modifiers: public static
focal_class.parameters: (ResultSet rs)
focal_class.return: void
focal_class.signature: void closeResultSet(ResultSet rs)
focal_class.class_method_signature: SQLUtilities.closeResultSet(ResultSet rs, boolean closeStatement)
focal_class.full_signature: public static void closeResultSet(ResultSet rs, boolean closeStatement)
focal_class.identifier: closeResultSet
focal_class.modifiers: public static
focal_class.parameters: (ResultSet rs, boolean closeStatement)
focal_class.return: void
focal_class.signature: void closeResultSet(ResultSet rs, boolean closeStatement)
focal_class.class_method_signature: SQLUtilities.closeStatement(Statement stmt)
focal_class.full_signature: public static void closeStatement(Statement stmt)
focal_class.identifier: closeStatement
focal_class.modifiers: public static
focal_class.parameters: (Statement stmt)
focal_class.return: void
focal_class.signature: void closeStatement(Statement stmt)
focal_method.body: public static List<ITableInfo> getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback) throws SQLException
  	{
  		List<ITableInfo> result = new ArrayList<ITableInfo>();
  		// tables that are netiher children nor parents - utility tables
  		List<ITableInfo> unattached = new ArrayList<ITableInfo>();
  		// tables that have at least one parent table
  		List<ITableInfo> children = new ArrayList<ITableInfo>();
  		// tables that have at least one child table
  		List<ITableInfo> parents = new ArrayList<ITableInfo>();
  		// tables that have at least one child table and have a least one parent table
  		List<ITableInfo> sandwiches = new ArrayList<ITableInfo>();
  		ITableInfo lastTable = null;
  		try
  		{
  			for (ITableInfo table : tables)
  			{
  				lastTable = table;
  				callback.currentlyLoading(table.getSimpleName());
  				ForeignKeyInfo[] importedKeys = getImportedKeys(table, md);
  				ForeignKeyInfo[] exportedKeys = getExportedKeys(table, md);
  
  				if (importedKeys != null && importedKeys.length == 0 && exportedKeys.length == 0)
  				{
  					unattached.add(table);
  					continue;
  				}
  				if (exportedKeys != null && exportedKeys.length > 0)
  				{
  					if (importedKeys != null && importedKeys.length > 0)
  					{
  						sandwiches.add(table);
  					} else
  					{
  						parents.add(table);
  					}
  					continue;
  				}
  				if (importedKeys != null && importedKeys.length > 0)
  				{
  					children.add(table);
  				}
  			}
  			reorderTables(sandwiches);
  
  			for (ITableInfo info : unattached)
  			{
  				result.add(info);
  			}
  			for (ITableInfo info : parents)
  			{
  				result.add(info);
  			}
  			for (ITableInfo info : sandwiches)
  			{
  				result.add(info);
  			}
  			for (ITableInfo info : children)
  			{
  				result.add(info);
  			}
  			if (result.size() != tables.size())
  			{
  				s_log.error("getInsertionOrder(): failed to obtain a result table list " + "(" + result.size()
  					+ ") that is the same size as the input table " + "list (" + tables.size()
  					+ ") - returning the original unordered " + "list");
  				result = tables;
  			}
  		} catch (Exception e)
  		{
  			if (lastTable != null)
  			{
  				String tablename = lastTable.getSimpleName();
  				s_log.error("Unexpected exception while getting foreign key info for " + "table " + tablename, e);
  			} else
  			{
  				s_log.error("Unexpected exception while getting foreign key info ", e);
  			}
  			result = tables;
  		}
  		return result;
  	}
focal_method.class_method_signature: SQLUtilities.getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_method.full_signature: public static List<ITableInfo> getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_method.identifier: getInsertionOrder
focal_method.invocations: currentlyLoading getSimpleName getImportedKeys getExportedKeys add add add add reorderTables add add add add size size error size size getSimpleName error error
focal_method.modifiers: public static
focal_method.parameters: (List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)
focal_method.return: List<ITableInfo>
focal_method.signature: List<ITableInfo> getInsertionOrder(List<ITableInfo> tables, SQLDatabaseMetaData md,
  		ProgressCallBack callback)