List of usage examples for javax.persistence Persistence createEntityManagerFactory
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties)
From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java
/** * This will initialize the JPA Entity Manager Factory. This will determine if * the database connection settings are correct. * //from w ww . j av a 2s . c o m * @throws ServletException */ private static void initializeEntityFactory() throws ServletException { logger.info("intializing Persistence Entity Factory"); // // Pull custom persistence settings // Properties properties; try { properties = XACMLProperties.getProperties(); } catch (IOException e) { throw new ServletException(e.getMessage(), e.getCause()); } // // Create the factory // emf = Persistence.createEntityManagerFactory(XacmlAdminUI.PERSISTENCE_UNIT, properties); // // Did it get created? // if (emf == null) { throw new ServletException("Unable to create Entity Manager Factory"); } // // Create our JDBC connection pool // try { logger.info("intializing JDBC Connection Pool"); XacmlAdminUI.pool = new XacmlJDBCConnectionPool( properties.getProperty(PersistenceUnitProperties.JDBC_DRIVER), properties.getProperty(PersistenceUnitProperties.JDBC_URL), properties.getProperty(PersistenceUnitProperties.JDBC_USER), properties.getProperty(PersistenceUnitProperties.JDBC_PASSWORD)); } catch (SQLException e) { throw new ServletException(e.getMessage(), e.getCause()); } }
From source file:org.oxymores.chronix.core.ChronixContext.java
public EntityManagerFactory getTransacEMF() { Properties p = new Properties(); if (this.transacDbPath != null) { p.put("openjpa.ConnectionURL", "jdbc:hsqldb:file:" + this.transacDbPath); }//from w w w . j a v a 2s . c o m return Persistence.createEntityManagerFactory(this.transacUnitName, p); }
From source file:op.OPDE.java
/** * Hier ist die main Methode von OPDE. In dieser Methode wird auch festgestellt, wie OPDE gestartet wurde. * <ul>// w ww . j a v a 2 s. co m * <li>Im Standard Modus, das heisst mit graphischer Oberflche. Das drfte der hufigste Fall sein.</li> * <li>Im DFNImport Modus. Der wird meist auf dem Datenbankserver gebraucht um Nachts die Durchfhrungsnachweise anhand der * DFNImport Tabelle zu generieren. Das alles gehrt zu der Pflegeplanung.</li> * <li>Im BHPImport Modus. Auch dieser Modus wird auf dem DB-Server gebraucht um die Behandlungspflege Massnahmen * anhand der rztlichen Verordnungen zu generieren.</li> * </ul> * * @param args Hier stehen die Kommandozeilen Parameter. Diese werden mit */ public static void main(String[] args) throws Exception { /*** * * ____ * ,' , `. * ,-+-,.' _ | ,--, * ,-+-. ; , || ,--.'| ,---, * ,--.'|' | ;| | |, ,-+-. / | * | | ,', | ': ,--.--. `--'_ ,--.'|' | * | | / | | || / \ ,' ,'| | | ,"' | * ' | : | : |,.--. .-. | ' | | | | / | | * ; . | ; |--' \__\/: . . | | : | | | | | * | : | | , ," .--.; | ' : |__ | | | |/ * | : ' |/ / / ,. | | | '.'|| | |--' * ; | |`-' ; : .' \; : ;| |/ * | ;/ | , .-./| , / '---' * '---' `--`---' ---`-' * */ uptime = SYSCalendar.now(); // arial14 = new Font("Arial", Font.PLAIN, 14); // arial28 = new Font("Arial", Font.PLAIN, 28); /*** * _ ____ _ _ * | | __ _ _ __ __ _ _ _ __ _ __ _ ___ | __ ) _ _ _ __ __| | | ___ * | | / _` | '_ \ / _` | | | |/ _` |/ _` |/ _ \ | _ \| | | | '_ \ / _` | |/ _ \ * | |__| (_| | | | | (_| | |_| | (_| | (_| | __/ | |_) | |_| | | | | (_| | | __/ * |_____\__,_|_| |_|\__, |\__,_|\__,_|\__, |\___| |____/ \__,_|_| |_|\__,_|_|\___| * |___/ |___/ */ lang = ResourceBundle.getBundle("languageBundle", Locale.getDefault()); validatorFactory = Validation.buildDefaultValidatorFactory(); /*** * ____ _ _ _ _ _ _ * / ___|__ _| |_ ___| |__ __ _| | | _ __ ___ __ _ _ _ ___ _____ _____ ___ _ __ | |_(_) ___ _ __ ___ * | | / _` | __/ __| '_ \ / _` | | | | '__/ _ \ / _` | | | |/ _ \ / _ \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __| * | |__| (_| | || (__| | | | | (_| | | | | | | (_) | (_| | |_| | __/ | __/> < (_| __/ |_) | |_| | (_) | | | \__ \ * \____\__,_|\__\___|_| |_| \__,_|_|_| |_| \___/ \__, |\__,_|\___| \___/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/ * |___/ |_| */ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { OPDE.fatal(e); } }); localProps = new SortedProperties(); props = new Properties(); /*** * _ _ ___ __ * _ __ ___ __ _ __| | / \ _ __ _ __|_ _|_ __ / _| ___ * | '__/ _ \/ _` |/ _` | / _ \ | '_ \| '_ \| || '_ \| |_ / _ \ * | | | __/ (_| | (_| | / ___ \| |_) | |_) | || | | | _| (_) | * |_| \___|\__,_|\__,_| /_/ \_\ .__/| .__/___|_| |_|_| \___/ * |_| |_| */ appInfo = new AppInfo(); /*** * ____ _ _ _ ___ _ _ * / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| | | | (_)_ __ ___ / _ \ _ __ | |_(_) ___ _ __ ___ * | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` | | | | | '_ \ / _ \ | | | | '_ \| __| |/ _ \| '_ \/ __| * | |__| (_) | | | | | | | | | | | (_| | | | | (_| | | |___| | | | | __/ | |_| | |_) | |_| | (_) | | | \__ \ * \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_| |_____|_|_| |_|\___| \___/| .__/ \__|_|\___/|_| |_|___/ * |_| */ Options opts = new Options(); opts.addOption("h", "hilfe", false, "Gibt die Hilfeseite fr OPDE aus."); opts.addOption("v", "version", false, "Zeigt die Versionsinformationen an."); opts.addOption("x", "experimental", false, "Schaltet experimentelle Programm-Module fr User frei, die Admin Rechte haben. VORSICHT !!!!"); opts.addOption("a", "anonym", false, "Blendet die Bewohnernamen in allen Ansichten aus. Spezieller Modus fr Schulungsmaterial zu erstellen."); opts.addOption("w", "workingdir", true, "Damit kannst Du ein anderes Arbeitsverzeichnis setzen. Wenn Du diese Option weglsst, dann ist das Dein Benutzerverzeichnis: " + System.getProperty("user.home")); opts.addOption("l", "debug", false, "Schaltet alle Ausgaben ein auf der Konsole ein, auch die, die eigentlich nur whrend der Softwareentwicklung angezeigt werden."); opts.addOption("t", "training", false, "Wird fr Einarbeitungsversionen bentigt. Frbt die Oberflche anders ein und zeigt eine Warnmeldung nach jeder Anmeldung."); Option optFTPserver = OptionBuilder.withLongOpt("ftpserver").withArgName("ip or hostname").hasArgs(1) .withDescription(lang.getString("cmdline.ftpserver")).create("f"); opts.addOption(optFTPserver); // opts.addOption("p", "pidfile", false, "Path to the pidfile which needs to be deleted when this application ends properly."); Option notification = OptionBuilder.withLongOpt("notification").hasOptionalArg() .withDescription("Schickt allen festgelegten Empfngern die jeweilige Benachrichtungs-Mail.") .create("n"); notification.setArgName( "Liste der Empfnger (durch Komma getrennt, ohne Leerzeichen. UID verwenden). Damit kannst Du die Benachrichtigungen einschrnken. Fehlt diese Liste, erhalten ALLE Empfnger eine Mail."); opts.addOption(notification); opts.addOption(OptionBuilder.withLongOpt("jdbc").hasArg().withDescription(lang.getString("cmdline.jdbc")) .create("j")); Option dfnimport = OptionBuilder //.withArgName("datum") .withLongOpt("dfnimport").hasOptionalArg() .withDescription("Startet OPDE im DFNImport Modus fr den aktuellen Tag.").create("d"); dfnimport.setArgName( "Anzahl der Tage (+ oder -) abweichend vom aktuellen Tag fr den der Import durchgefhrt werden soll. Nur in Ausnahmefllen anzuwenden."); opts.addOption(dfnimport); Option bhpimport = OptionBuilder.withLongOpt("bhpimport").hasOptionalArg() .withDescription("Startet OPDE im BHPImport Modus fr den aktuellen Tag.").create("b"); // bhpimport.setOptionalArg(true); bhpimport.setArgName( "Anzahl der Tage (+ oder -) abweichend vom aktuellen Tag fr den der Import durchgefhrt werden soll. Nur in Ausnahmefllen anzuwenden."); opts.addOption(bhpimport); BasicParser parser = new BasicParser(); CommandLine cl = null; String footer = "http://www.Offene-Pflege.de"; /*** * _ _ * | |__ ___| |_ __ ___ ___ _ __ ___ ___ _ __ * | '_ \ / _ \ | '_ \ / __|/ __| '__/ _ \/ _ \ '_ \ * | | | | __/ | |_) | \__ \ (__| | | __/ __/ | | | * |_| |_|\___|_| .__/ |___/\___|_| \___|\___|_| |_| * |_| */ try { cl = parser.parse(opts, args); } catch (ParseException ex) { HelpFormatter f = new HelpFormatter(); f.printHelp("OffenePflege.jar [OPTION]", "Offene-Pflege.de, Version " + appInfo.getVersion() + " Build:" + appInfo.getBuildnum(), opts, footer); System.exit(0); } // Alternative FTP-Server if (cl.hasOption("f")) { UPDATE_FTPSERVER = cl.getOptionValue("f"); } if (cl.hasOption("h")) { HelpFormatter f = new HelpFormatter(); f.printHelp("OffenePflege.jar [OPTION]", "Offene-Pflege.de, Version " + appInfo.getVersion() + " Build:" + appInfo.getBuildnum(), opts, footer); System.exit(0); } String homedir = System.getProperty("user.home"); // alternatice working dir if (cl.hasOption("w")) { File dir = new File(cl.getOptionValue("w")); if (dir.exists() && dir.isDirectory()) { homedir = dir.getAbsolutePath(); } } opwd = homedir + sep + AppInfo.dirBase; /*** * ___ * __ _ _ __ ___ _ __ _ _ _ __ ___ ___ _ _ ___ |__ \ * / _` | '_ \ / _ \| '_ \| | | | '_ ` _ \ / _ \| | | / __| / / * | (_| | | | | (_) | | | | |_| | | | | | | (_) | |_| \__ \ |_| * \__,_|_| |_|\___/|_| |_|\__, |_| |_| |_|\___/ \__,_|___/ (_) * |___/ */ if (cl.hasOption("a")) { // anonym Modus //localProps.put("anonym", "true"); anonym = true; anonymize = new HashMap[] { SYSConst.getNachnamenAnonym(), SYSConst.getVornamenFrauAnonym(), SYSConst.getVornamenMannAnonym() }; } else { anonym = false; } /*** * _ _ _ _ _ * (_)_ __ (_) |_ _ __ _ __(_)_ __ | |_ ___ _ __ ___ * | | '_ \| | __| | '_ \| '__| | '_ \| __/ _ \ '__/ __| * | | | | | | |_ | |_) | | | | | | | || __/ | \__ \ * |_|_| |_|_|\__| | .__/|_| |_|_| |_|\__\___|_| |___/ * |_| */ printers = new LogicalPrinters(); /*** * _ _ _ _ _ _ * | | ___ __ _ __| | | | ___ ___ __ _| | _ __ _ __ ___ _ __ ___ _ __| |_(_) ___ ___ * | |/ _ \ / _` |/ _` | | |/ _ \ / __/ _` | | | '_ \| '__/ _ \| '_ \ / _ \ '__| __| |/ _ \/ __| * | | (_) | (_| | (_| | | | (_) | (_| (_| | | | |_) | | | (_) | |_) | __/ | | |_| | __/\__ \ * |_|\___/ \__,_|\__,_| |_|\___/ \___\__,_|_| | .__/|_| \___/| .__/ \___|_| \__|_|\___||___/ * |_| |_| */ if (loadLocalProperties()) { // try { // FileAppender fileAppender = new FileAppender(layout, , true); // logger.addAppender(fileAppender); // } catch (IOException ex) { // fatal(ex); // } animation = localProps.containsKey("animation") && localProps.getProperty("animation").equals("true"); logger.info("######### START ########### " + OPDE.getAppInfo().getProgname() + ", v" + OPDE.getAppInfo().getVersion() + "/" + OPDE.getAppInfo().getBuildnum()); logger.info(System.getProperty("os.name").toLowerCase()); /*** * _ ____ _ ___ ___ * (_)___| _ \ ___| |__ _ _ __ _ |__ \__ \ * | / __| | | |/ _ \ '_ \| | | |/ _` | / / / / * | \__ \ |_| | __/ |_) | |_| | (_| | |_| |_| * |_|___/____/ \___|_.__/ \__,_|\__, | (_) (_) * |___/ */ if (cl.hasOption("l") || SYSTools.catchNull(localProps.getProperty("debug")).equalsIgnoreCase("true")) { debug = true; logger.setLevel(Level.DEBUG); } else { debug = false; logger.setLevel(Level.INFO); } Logger.getLogger("org.hibernate").setLevel(Level.OFF); if (cl.hasOption("x") || SYSTools.catchNull(localProps.getProperty("experimental")).equalsIgnoreCase("true")) { experimental = true; } else { experimental = false; } if (cl.hasOption("t") || SYSTools.catchNull(localProps.getProperty("training")).equalsIgnoreCase("true")) { training = true; } else { training = false; } /*** * _ _ _ _ _ _ _ ___ * __| | |____ _____ _ __ ___(_) ___ _ __ ___ ___ _ __ ___ _ __ __ _| |_(_) |__ | | ___ |__ \ * / _` | '_ \ \ / / _ \ '__/ __| |/ _ \| '_ \ / __/ _ \| '_ ` _ \| '_ \ / _` | __| | '_ \| |/ _ \ / / * | (_| | |_) \ V / __/ | \__ \ | (_) | | | | | (_| (_) | | | | | | |_) | (_| | |_| | |_) | | __/ |_| * \__,_|_.__/ \_/ \___|_| |___/_|\___/|_| |_| \___\___/|_| |_| |_| .__/ \__,_|\__|_|_.__/|_|\___| (_) * |_| */ url = cl.hasOption("j") ? cl.getOptionValue("j") : localProps.getProperty("javax.persistence.jdbc.url"); String hostkey = OPDE.getLocalProps().getProperty("hostkey"); String cryptpassword = localProps.getProperty("javax.persistence.jdbc.password"); DesEncrypter desEncrypter = new DesEncrypter(hostkey); Connection jdbcConnection = DriverManager.getConnection(url, localProps.getProperty("javax.persistence.jdbc.user"), desEncrypter.decrypt(cryptpassword)); if (appInfo.getDbversion() != getDBVersion(jdbcConnection)) { SYSFilesTools.print(lang.getString("cant.start.with.version.mismatch"), false); System.exit(1); } jdbcConnection.close(); /*** * _ ____ _ ____ _ _ * | | _ \ / \ | _ \ __ _| |_ __ _| |__ __ _ ___ ___ * _ | | |_) / _ \ | | | |/ _` | __/ _` | '_ \ / _` / __|/ _ \ * | |_| | __/ ___ \ | |_| | (_| | || (_| | |_) | (_| \__ \ __/ * \___/|_| /_/ \_\ |____/ \__,_|\__\__,_|_.__/ \__,_|___/\___| * */ Properties jpaProps = new Properties(); jpaProps.put("javax.persistence.jdbc.user", localProps.getProperty("javax.persistence.jdbc.user")); try { jpaProps.put("javax.persistence.jdbc.password", desEncrypter.decrypt(cryptpassword)); } catch (Exception e) { if (Desktop.isDesktopSupported()) { JOptionPane.showMessageDialog(null, SYSTools.xx("misc.msg.decryption.failure"), appInfo.getProgname(), JOptionPane.ERROR_MESSAGE); } else { OPDE.fatal(e); } System.exit(1); } jpaProps.put("javax.persistence.jdbc.driver", localProps.getProperty("javax.persistence.jdbc.driver")); jpaProps.put("javax.persistence.jdbc.url", url); // if (cl.hasOption("d") || cl.hasOption("d")) { // not for BHP or DFN // jpaProps.put("eclipselink.cache.shared.default", "false"); // } else { // jpaProps.put("eclipselink.cache.shared.default", "true"); // } jpaProps.put("eclipselink.cache.shared.default", "false"); jpaProps.put("eclipselink.session.customizer", "entity.JPAEclipseLinkSessionCustomizer"); emf = Persistence.createEntityManagerFactory("OPDEPU", jpaProps); /*** * __ __ _ * \ \ / /__ _ __ ___(_) ___ _ __ * \ \ / / _ \ '__/ __| |/ _ \| '_ \ * \ V / __/ | \__ \ | (_) | | | | * \_/ \___|_| |___/_|\___/|_| |_| * */ String header = SYSTools.getWindowTitle(""); if (cl.hasOption("v")) { System.out.println(header); System.out.println(footer); System.exit(0); } /*** * ____ _ ____ _____ _ _ * / ___| ___ _ __ ___ _ __ __ _| |_ ___ | _ \| ___| \ | |___ * | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \ | | | | |_ | \| / __| * | |_| | __/ | | | __/ | | (_| | || __/ | |_| | _| | |\ \__ \ * \____|\___|_| |_|\___|_| \__,_|\__\___| |____/|_| |_| \_|___/ * */ if (cl.hasOption("d")) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users rootUser = em.find(Users.class, "admin"); SYSLogin rootLogin = em.merge(new SYSLogin(rootUser)); OPDE.setLogin(rootLogin); initProps(); // create the new DFNs DFNTools.generate(em); // move over the floating ones that have not yet been clicked to the current day DFNTools.moveFloating(em); em.getTransaction().commit(); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } fatal(ex); } finally { em.close(); } System.exit(0); } /*** * ____ _ ____ _ _ ____ * / ___| ___ _ __ ___ _ __ __ _| |_ ___ | __ )| | | | _ \ ___ * | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \ | _ \| |_| | |_) / __| * | |_| | __/ | | | __/ | | (_| | || __/ | |_) | _ | __/\__ \ * \____|\___|_| |_|\___|_| \__,_|\__\___| |____/|_| |_|_| |___/ * */ if (cl.hasOption("b")) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users rootUser = em.find(Users.class, "admin"); SYSLogin rootLogin = em.merge(new SYSLogin(rootUser)); OPDE.setLogin(rootLogin); initProps(); BHPTools.generate(em); em.getTransaction().commit(); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } fatal(ex); } finally { em.close(); } System.exit(0); } /*** * _ _ _ _ __ _ _ _ * | \ | | ___ | |_(_)/ _(_) ___ __ _| |_(_) ___ _ __ * | \| |/ _ \| __| | |_| |/ __/ _` | __| |/ _ \| '_ \ * | |\ | (_) | |_| | _| | (_| (_| | |_| | (_) | | | | * |_| \_|\___/ \__|_|_| |_|\___\__,_|\__|_|\___/|_| |_| * */ if (cl.hasOption("n")) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users rootUser = em.find(Users.class, "admin"); SYSLogin rootLogin = em.merge(new SYSLogin(rootUser)); OPDE.setLogin(rootLogin); initProps(); EMailSystem.notify(cl.getOptionValue("n")); em.getTransaction().commit(); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } fatal(ex); } finally { em.close(); } System.exit(0); } // to speed things later. The first connection loads the while JPA system. EntityManager em1 = createEM(); em1.close(); UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); setStandardFont(); try { css = SYSTools.readFileAsString(opwd + sep + AppInfo.dirTemplates + sep + AppInfo.fileStandardCSS); } catch (IOException ie) { css = ""; } // JideSoft Lm.verifyLicense("Torsten Loehr", "Open-Pflege.de", "G9F4JW:Bm44t62pqLzp5woAD4OCSUAr2"); WizardStyle.setStyle(WizardStyle.JAVA_STYLE); // JideSoft /*** * _____ __ __ _ ____ * | ___| __ _ __ ___ | \/ | __ _(_)_ __ / /\ \ * | |_ | '__| '_ ` _ \| |\/| |/ _` | | '_ \| | | | * | _|| | | | | | | | | | | (_| | | | | | | | | * |_| |_| |_| |_| |_|_| |_|\__,_|_|_| |_| | | | * \_\/_/ */ // JFrame frm = new JFrame(); // frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // frm.setLayout(new FlowLayout()); // // frm.getContentPane().add(new PnlBodyScheme(new Properties())); // // frm.setVisible(true); SYSTools.checkForSoftwareupdates(); mainframe = new FrmMain(); mainframe.setVisible(true); } }
From source file:com.gnadenheimer.mg3.utils.Utils.java
public void setEntityManagerFactory() { this.entityManagerFactory = Persistence.createEntityManagerFactory("mg_PU", getPersistenceMap()); }
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {// ww w . j a v a 2 s . com CurrentUser currentUser = CurrentUser.getInstance(); Map<String, String> persistenceMap = Utils.getInstance().getPersistenceMap(); EntityManager entityManager = Persistence.createEntityManagerFactory("mg_PU", persistenceMap) .createEntityManager(); entityManager.getTransaction().begin(); Query queryEventoDetalle = entityManager.createQuery("SELECT t FROM TblEventoDetalle t ORDER BY t.id"); List<TblEventoDetalle> listEventoDetalle = org.jdesktop.observablecollections.ObservableCollections .observableList(queryEventoDetalle.getResultList()); TblCuentasContablesPorDefecto cuentasContablesPorDefecto = entityManager .find(TblCuentasContablesPorDefecto.class, 1); for (TblEventoDetalle evd : listEventoDetalle) { if (evd.getTblAsientosList().size() == 2) { Integer indexAsientoAporte = -1; Integer indexAsientoDonacion = -1; if (((List<TblAsientos>) evd.getTblAsientosList()).get(0).getIdCuentaContableHaber() .equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { indexAsientoAporte = 0; indexAsientoDonacion = 1; } else if (((List<TblAsientos>) evd.getTblAsientosList()).get(1).getIdCuentaContableHaber() .equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { indexAsientoAporte = 1; indexAsientoDonacion = 0; } ((List<TblAsientos>) evd .getTblAsientosList()) .get(indexAsientoAporte) .setMonto(((Long) (evd.getMonto().longValue() * evd.getIdEvento().getPorcentajeAporte().longValue() / 100)) .intValue()); ((List<TblAsientos>) evd.getTblAsientosList()).get(indexAsientoDonacion).setMonto(evd.getMonto() - ((List<TblAsientos>) evd.getTblAsientosList()).get(indexAsientoAporte).getMonto()); entityManager.merge(evd); } else if (evd.getTblAsientosList().isEmpty()) { List<TblAsientos> ts = evd.getTblAsientosList(); if (ts == null) { ts = new LinkedList<>(); evd.setTblAsientosList((List) ts); } TblAsientos asientoAporte = new TblAsientos(); asientoAporte.setFechahora(evd.getIdEvento().getFecha().atStartOfDay()); asientoAporte.setIdCentroDeCostoDebe(evd.getIdEvento().getIdCentroDeCosto()); asientoAporte.setIdCentroDeCostoHaber(evd.getIdEvento().getIdCentroDeCosto()); asientoAporte.setIdCuentaContableDebe(cuentasContablesPorDefecto.getIdCuentaACobrar()); asientoAporte.setIdCuentaContableHaber(cuentasContablesPorDefecto.getIdCuentaAportes()); asientoAporte.setMonto(((Long) (evd.getMonto().longValue() * evd.getIdEvento().getPorcentajeAporte().longValue() / 100)).intValue()); asientoAporte.setIdUser(currentUser.getUser()); ts.add(asientoAporte); TblAsientos asientoDonacion = new TblAsientos(); asientoDonacion.setFechahora(evd.getIdEvento().getFecha().atStartOfDay()); asientoDonacion.setIdCentroDeCostoDebe(evd.getIdEvento().getIdCentroDeCosto()); asientoDonacion.setIdCentroDeCostoHaber(evd.getIdEvento().getIdCentroDeCosto()); asientoDonacion.setIdCuentaContableDebe(cuentasContablesPorDefecto.getIdCuentaACobrar()); asientoDonacion.setIdCuentaContableHaber(cuentasContablesPorDefecto.getIdCuentaDonaciones()); asientoDonacion.setMonto(evd.getMonto() - asientoAporte.getMonto()); asientoDonacion.setIdUser(currentUser.getUser()); ts.add(asientoDonacion); entityManager.merge(evd); } } /* List<TblTransferencias> listT = (List<TblTransferencias>) entityManager.createQuery("select t from TblTransferencias t").getResultList(); for (TblTransferencias t : listT) { Query queryEvd = entityManager.createQuery("select e from TblEventoDetalle e where e.idEvento.idEventoTipo = :eventoTipo and EXTRACT(MONTH FROM e.idEvento.fecha) = :mes and EXTRACT(YEAR FROM e.idEvento.fecha) = :ano and e.idEntidad = :entidad"); Calendar c = Calendar.getInstance(); c.setTime(t.getFechahora()); queryEvd.setParameter("mes", c.get(Calendar.MONTH) + 1); queryEvd.setParameter("ano", c.get(Calendar.YEAR)); queryEvd.setParameter("entidad", t.getIdEntidad()); queryEvd.setParameter("eventoTipo", t.getIdEventoTipo()); List<TblEventoDetalle> listEvd = queryEvd.getResultList(); List<TblAsientos> listAsientos = new ArrayList<>(); for (TblEventoDetalle evd : listEvd) { listAsientos.addAll(evd.getTblAsientosList()); } List<TblAsientosTemporales> listAsientosTemporales = t.getTblAsientosTemporalesList(); if (listAsientosTemporales == null) { listAsientosTemporales = new LinkedList<>(); t.setTblAsientosTemporalesList(listAsientosTemporales); } if (t.getTblAsientosTemporalesList().isEmpty()) { for (TblAsientos asiento : listAsientos) { TblAsientosTemporales aT = new TblAsientosTemporales(); entityManager.persist(aT); aT.setFacturado(false); aT.setFechahora(t.getFechahora()); aT.setIdCentroDeCosto(asiento.getIdCentroDeCosto()); aT.setIdCuentaContableDebe(asiento.getIdCentroDeCosto().getIdCuentaContableCtaCtePorDefecto()); aT.setIdCuentaContableHaber(asiento.getIdCuentaContableDebe()); if (asiento.getIdCuentaContableHaber().equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { aT.setEsAporte(true); } else { aT.setEsAporte(false); } aT.setMonto(asiento.getMonto()); listAsientosTemporales.add(aT); } entityManager.merge(t); } }*/ entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); JOptionPane.showMessageDialog(null, "Actualizacion satisfactoria!"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:richtercloud.document.scanner.gui.DocumentScanner.java
/** * run all initialization routines which open resources which need to be * referenced by {@code this} in order to be closable (if everything is * initialized in the constructor and the initialization fails there's no * way to close opened resources).//from w w w. j a v a 2 s. com */ @Override public void init() throws DerbyPersistenceStorageConfInitializationException, IOException { Map<Object, Object> entityManagerFactoryMap = new HashMap<>(); entityManagerFactoryMap.put("javax.persistence.jdbc.url", String.format("%s;create=%s", DERBY_CONNECTION_URL, !DATABASE_DIR.exists())); this.entityManagerFactory = Persistence.createEntityManagerFactory( "richtercloud_document-scanner_jar_1.0-SNAPSHOTPU", entityManagerFactoryMap); this.entityManager = entityManagerFactory.createEntityManager(); DerbyPersistenceStorageConfPanel derbyStorageConfPanel; derbyStorageConfPanel = new DerbyPersistenceStorageConfPanel(entityManager, messageHandler, ENTITY_CLASSES, derbyPersistenceStorageSchemeChecksumFile //schemeChecksumFile ); //@TODO: replace with classpath annotation discovery this.storageConfPanelMap.put(DerbyPersistenceStorageConf.class, derbyStorageConfPanel); this.mainPanel = new MainPanel(ENTITY_CLASSES, PRIMARY_CLASS_SELECTION, entityManager, amountMoneyUsageStatisticsStorage, amountMoneyCurrencyStorage, amountMoneyExchangeRateRetriever, messageHandler, this, oCREngineFactory, documentScannerConf.getoCREngineConf(), typeHandlerMapping, documentScannerConf, this //oCRProgressMonitorParent ); mainPanelPanel.add(this.mainPanel); }
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try {/*from www . jav a 2 s. c o m*/ CurrentUser currentUser = CurrentUser.getInstance(); Map<String, String> persistenceMap = Utils.getInstance().getPersistenceMap(); EntityManager entityManager = Persistence.createEntityManagerFactory("mg_PU", persistenceMap) .createEntityManager(); entityManager.getTransaction().begin(); List<TblEntidades> list = (List<TblEntidades>) entityManager.createQuery("select e from TblEntidades e") .getResultList(); for (TblEntidades e : list) { String nombreviejo = e.getNombres(); if (nombreviejo.contains(",")) { String[] parts = nombreviejo.split(","); e.setNombres(parts[0].trim()); e.setApellidos(parts[1].trim()); entityManager.merge(e); } } entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); JOptionPane.showMessageDialog(null, "Nombres actualizados!"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed Map<String, String> persistenceMap = Utils.getInstance().getPersistenceMap(); EntityManager entityManager = Persistence.createEntityManagerFactory("mg_PU", persistenceMap) .createEntityManager();/*from w w w . j av a 2 s . c om*/ entityManager.getTransaction().begin(); int suma = 0; List<TblTransferencias> listT = (List<TblTransferencias>) entityManager .createQuery("select t from TblTransferencias t").getResultList(); for (TblTransferencias t : listT) { Integer sumAtAporte = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(true)).mapToInt(l -> l.getMonto()).sum(); Integer sumAtDonacion = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(false)).mapToInt(l -> l.getMonto()).sum(); if (t.getMontoAporte() < sumAtAporte) { for (int i = 0; i < t.getTblAsientosTemporalesList().size(); i++) { if (t.getTblAsientosTemporalesList().get(i).getEsAporte()) { if (sumAtAporte - t.getTblAsientosTemporalesList().get(i).getMonto() - t.getMontoAporte() == 0) { System.out.println(t.getTblAsientosTemporalesList().get(i).getId()); suma += t.getTblAsientosTemporalesList().get(i).getMonto(); t.getTblAsientosTemporalesList().get(i).setMonto(0); sumAtAporte = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(true)).mapToInt(l -> l.getMonto()).sum(); System.out.println(suma); entityManager.merge(t); } } } } if (t.getMontoDonacion() < sumAtDonacion) { for (int i = 0; i < t.getTblAsientosTemporalesList().size(); i++) { if (!t.getTblAsientosTemporalesList().get(i).getEsAporte()) { if (sumAtDonacion - t.getTblAsientosTemporalesList().get(i).getMonto() - t.getMontoDonacion() == 0) { System.out.println(t.getTblAsientosTemporalesList().get(i).getId()); suma += t.getTblAsientosTemporalesList().get(i).getMonto(); t.getTblAsientosTemporalesList().get(i).setMonto(0); sumAtDonacion = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(false)).mapToInt(l -> l.getMonto()).sum(); System.out.println(suma); entityManager.merge(t); } } } } } for (TblTransferencias t : listT) { Integer sumAtAporte = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(true)).mapToInt(l -> l.getMonto()).sum(); Integer sumAtDonacion = t.getTblAsientosTemporalesList().stream() .filter(x -> x.getEsAporte().equals(false)).mapToInt(l -> l.getMonto()).sum(); if (t.getMontoAporte() < sumAtAporte) { int asientoValido = -1; for (int i = 0; i < t.getTblAsientosTemporalesList().size(); i++) { if (t.getTblAsientosTemporalesList().get(i).getEsAporte()) { if (t.getTblAsientosTemporalesList().get(i).getMonto().equals(t.getMontoAporte())) { asientoValido = t.getTblAsientosTemporalesList().get(i).getId(); for (int ii = 0; ii < t.getTblAsientosTemporalesList().size(); ii++) { if (t.getTblAsientosTemporalesList().get(ii).getEsAporte() && t.getTblAsientosTemporalesList().get(ii).getId() != asientoValido) { suma += t.getTblAsientosTemporalesList().get(ii).getMonto(); t.getTblAsientosTemporalesList().get(ii).setMonto(0); } } entityManager.merge(t); } } } } if (t.getMontoDonacion() < sumAtDonacion) { int asientoValido = -1; for (int i = 0; i < t.getTblAsientosTemporalesList().size(); i++) { if (!t.getTblAsientosTemporalesList().get(i).getEsAporte()) { if (t.getTblAsientosTemporalesList().get(i).getMonto().equals(t.getMontoDonacion())) { asientoValido = t.getTblAsientosTemporalesList().get(i).getId(); for (int ii = 0; ii < t.getTblAsientosTemporalesList().size(); ii++) { if (!t.getTblAsientosTemporalesList().get(ii).getEsAporte() && t.getTblAsientosTemporalesList().get(ii).getId() != asientoValido) { suma += t.getTblAsientosTemporalesList().get(ii).getMonto(); t.getTblAsientosTemporalesList().get(ii).setMonto(0); } } entityManager.merge(t); } } } } } entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); JOptionPane.showMessageDialog(null, suma); }