Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test
- {
- final static Logger logger = LoggerFactory.getLogger(Test.class);
- private static String host = "xenia.kubje.org";
- private static int port = 3306;
- private static String user = "jaka";
- private static String password = "...";
- private static String clusterName = "jaka_icluster";
- public static void main( String[] args ) throws Exception
- {
- Map<String, String> commonConfig = new HashMap<String, String>();
- commonConfig.put(PersistenceUnitProperties.LOGGING_LEVEL, "FINER"); // FINEST
- logger.info("Creating cluster EMF...");
- Map<String, String> clusterEmfConfig = new HashMap<String, String>(commonConfig);
- clusterEmfConfig.put(PersistenceUnitProperties.JDBC_DRIVER, "com.mysql.jdbc.Driver");
- clusterEmfConfig.put(PersistenceUnitProperties.JDBC_USER, user);
- clusterEmfConfig.put(PersistenceUnitProperties.JDBC_PASSWORD, password);
- clusterEmfConfig.put(PersistenceUnitProperties.JDBC_URL, "jdbc:mysql://"+host+":"+port+"/"+clusterName+"_global");
- // Note how clusterEmf has the "local variable never read" warning, it's never used.
- EntityManagerFactory clusterEmf = Persistence.createEntityManagerFactory("ClusterPU", clusterEmfConfig);
- logger.info("Creating instance EMF...");
- Map<String, String> instanceEmfConfig = new HashMap<String, String>(commonConfig);
- // Expected: Exception because no driver is set.
- // Actual: works
- EntityManagerFactory instanceEmf = Persistence.createEntityManagerFactory("InstancePU", instanceEmfConfig);
- logger.info("Creating an instance EM...");
- int instanceId = 1;
- Map<String, String> instanceEmConfig = new HashMap<String, String>();
- instanceEmConfig.put(EntityManagerProperties.JDBC_DRIVER, "com.mysql.jdbc.Driver");
- instanceEmConfig.put(EntityManagerProperties.JDBC_USER, user);
- instanceEmConfig.put(EntityManagerProperties.JDBC_PASSWORD, password);
- instanceEmConfig.put(EntityManagerProperties.JDBC_URL, "jdbc:mysql://"+host+":"+port+"/"+clusterName+"_instance_"+instanceId);
- // Expected: a) Exception because no driver was set for EMF or b) use the driver for the EM
- // Actual: Connections using data from clusterEmf are created! (database ..._global)
- EntityManager instanceEm = instanceEmf.createEntityManager(instanceEmConfig);
- logger.info("Loading an entity from the instance EM...");
- Company c = instanceEm.find(Company.class, 66);
- // Exception is thrown here: Table 'jaka_icluster_global.companies' doesn't exist
- System.out.println(c.getName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement