Guest User

ReverseMapping workaround

a guest
Dec 12th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. public static Map<Class<?>, String> runReverseMapping(JDBCConfiguration jconf) {
  2.         String hookId = UUID.randomUUID().toString();
  3.  
  4.         jconf.setId(hookId);
  5.  
  6.         //>-cc (customizerClass) is how we get the ReverseMappingTool instance later on
  7.         Options rmOpts = new Options();
  8.         String argString = String.format(... "-cc %s" ..., //
  9.                 HookPropertiesReverseCustomizer.class.getName());
  10.         rmOpts.setFromCmdLine(StringUtils.split(argString, " "));
  11.  
  12.         try {
  13.             ReverseMappingTool.run(jconf, new String[0], rmOpts);
  14.         } catch (IOException e) {
  15.             // Can happen if writing files fails or loading customization file fails.
  16.             // Currently uninterested in either.
  17.             // e.printStackTrace();
  18.         } catch (SQLException e) {
  19.             // SchemaGenerator will be responsible for this
  20.             // TODO Should we throw an AnzoException here? Probably
  21.             e.printStackTrace();
  22.         }
  23.  
  24.         ReverseMappingTool gotTool = HookPropertiesReverseCustomizer.popTool(hookId);
  25. ...
  26. }
  27.  
  28. ---------------------------------------------
  29.  
  30. public class HookPropertiesReverseCustomizer extends PropertiesReverseCustomizer {
  31.     private static Map<String, ReverseMappingTool> idToTool = new HashMap<>();
  32.  
  33.     @Override
  34.     public void setTool(ReverseMappingTool tool) {
  35.         super.setTool(tool);
  36.         idToTool.put(tool.getConfiguration().getId(), tool);
  37.     }
  38.  
  39.     public static ReverseMappingTool popTool(String id) {
  40.         return idToTool.remove(id);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment