Added CDI to the application

This commit is contained in:
2014-05-23 10:24:33 +02:00
parent 2af2f56ade
commit 615d277359
19 changed files with 239 additions and 177 deletions

View File

@@ -53,9 +53,10 @@ dependencies {
compile files('lib/JFXtras/jfxtras-labs-8.0-r1-SNAPSHOT.jar', 'lib/ScenicView/ScenicView.jar') compile files('lib/JFXtras/jfxtras-labs-8.0-r1-SNAPSHOT.jar', 'lib/ScenicView/ScenicView.jar')
compile group: 'org.jdom', name: 'jdom2', version: '2.0.5' compile group: 'org.jdom', name: 'jdom2', version: '2.0.5'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.5' compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.5'
compile group: 'com.h2database', name: 'h2', version: '1.3.173' compile group: 'com.h2database', name: 'h2', version: '1.4.178'
compile group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.5.0' compile group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.5.0'
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.2.1' compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.2.1'
compile group: 'org.jboss.weld.se', name: 'weld-se', version: '2.2.0.Final'
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- no content needed -->
</beans>

View File

@@ -1,85 +0,0 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.geofroggerfx.application;
import de.geofroggerfx.gpx.GPXReader;
import de.geofroggerfx.gpx.GroundspeakGPXReader;
import de.geofroggerfx.plugins.PluginService;
import de.geofroggerfx.plugins.PluginServiceImpl;
import de.geofroggerfx.service.CacheService;
import de.geofroggerfx.service.CacheServiceImpl;
import de.geofroggerfx.sql.DatabaseService;
import de.geofroggerfx.sql.DatabaseServiceImpl;
/**
* @author Andreas
*/
public class ServiceManager {
private static final ServiceManager INSTANCE = new ServiceManager();
private GPXReader gpxReader;
private DatabaseService databaseService;
private CacheService cacheService;
private PluginService pluginService;
private ServiceManager() {
// private for singleton pattern
}
public static ServiceManager getInstance() {
return INSTANCE;
}
public synchronized GPXReader getGPXReader() {
if (gpxReader == null) {
gpxReader = new GroundspeakGPXReader();
}
return gpxReader;
}
public synchronized DatabaseService getDatabaseService() {
if (databaseService == null) {
databaseService = new DatabaseServiceImpl();
}
return databaseService;
}
public synchronized CacheService getCacheService() {
if (cacheService == null) {
cacheService = new CacheServiceImpl();
}
return cacheService;
}
public synchronized PluginService getPluginService() {
if (pluginService == null) {
pluginService = new PluginServiceImpl();
}
return pluginService;
}
}

View File

@@ -25,6 +25,7 @@
*/ */
package de.geofroggerfx.application; package de.geofroggerfx.application;
import javax.inject.Singleton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -34,19 +35,12 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author Andreas * @author Andreas
*/ */
@Singleton
public class SessionContext { public class SessionContext {
private static final SessionContext INSTANCE = new SessionContext();
private final Map<String, Object> map = new ConcurrentHashMap<>(); private final Map<String, Object> map = new ConcurrentHashMap<>();
private final Map<String, List<SessionContextListener>> sessionListeners = new HashMap<>(); private final Map<String, List<SessionContextListener>> sessionListeners = new HashMap<>();
private SessionContext() {
}
public static SessionContext getInstance() {
return INSTANCE;
}
public void setData(String key, Object value) { public void setData(String key, Object value) {
if (value == null && map.containsKey(key)) { if (value == null && map.containsKey(key)) {
map.remove(key); map.remove(key);

View File

@@ -0,0 +1,49 @@
package de.geofroggerfx.fx;
import de.geofroggerfx.fx.utils.StartupScene;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import org.scenicview.ScenicView;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ResourceBundle;
/**
* This class is based on the tutorial
* http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
*
* Thanks to Matthieu BROUILLARD
*/
public class FxMain {
@Inject
private FXMLLoader fxmlLoader;
public void start( @Observes @StartupScene Stage stage) throws IOException
{
try (InputStream fxml = getClass().getResourceAsStream( "geofrogger/geofrogger.fxml" )) {
fxmlLoader.setResources(ResourceBundle.getBundle("de.geofroggerfx.fx.geofrogger"));
final Parent root = fxmlLoader.load(fxml);
final Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
scene.setOnKeyPressed(keyEvent -> {
if (isScenicViewShortcutPressed(keyEvent)) {
ScenicView.show(scene);
}
});
}
}
private boolean isScenicViewShortcutPressed(final KeyEvent keyEvent) {
return keyEvent.isAltDown() && keyEvent.isControlDown() && keyEvent.getCode().equals(KeyCode.V);
}
}

View File

@@ -25,38 +25,47 @@
*/ */
package de.geofroggerfx.fx; package de.geofroggerfx.fx;
import de.geofroggerfx.application.ServiceManager; import de.geofroggerfx.fx.utils.ApplicationParametersProvider;
import de.geofroggerfx.fx.utils.StartupScene;
import de.geofroggerfx.sql.DatabaseService;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.scenicview.ScenicView; import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import java.util.ResourceBundle; import javax.enterprise.util.AnnotationLiteral;
/** /**
* @author Andreas * @author Andreas
*/ */
public class GeoFroggerFXMain extends Application { public class GeoFroggerFXMain extends Application {
private Weld weld;
private WeldContainer weldContainer;
@Override
public void init() throws Exception {
super.init();
// Init Weld CDI
weld = new Weld();
}
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
loadCustomFonts(); loadCustomFonts();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("geofrogger/geofrogger.fxml"), ResourceBundle.getBundle("de.geofroggerfx.fx.geofrogger"));
Parent root = (Parent)fxmlLoader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
scene.setOnKeyPressed(keyEvent -> { weldContainer = weld.initialize();
if (isScenicViewShortcutPressed(keyEvent)) {
ScenicView.show(scene); // Make the application parameters injectable with a standard CDI
} // annotation
}); weldContainer.instance().select(ApplicationParametersProvider.class).get().setParameters(getParameters());
// Now that JavaFX thread is ready
// let's inform whoever cares using standard CDI notification mechanism:
// CDI events
weldContainer.event().select(Stage.class, new AnnotationLiteral<StartupScene>() {}).fire(stage);
} }
private void loadCustomFonts() { private void loadCustomFonts() {
@@ -72,13 +81,10 @@ public class GeoFroggerFXMain extends Application {
Font.loadFont(GeoFroggerFXMain.class.getResource("/fonts/FiraSansOT-RegularItalic.otf").toExternalForm(), 12); Font.loadFont(GeoFroggerFXMain.class.getResource("/fonts/FiraSansOT-RegularItalic.otf").toExternalForm(), 12);
} }
private boolean isScenicViewShortcutPressed(final KeyEvent keyEvent) {
return keyEvent.isAltDown() && keyEvent.isControlDown() && keyEvent.getCode().equals(KeyCode.V);
}
@Override @Override
public void stop() throws Exception { public void stop() throws Exception {
ServiceManager.getInstance().getDatabaseService().getEntityManager().close(); weldContainer.instance().select(DatabaseService.class).get().getEntityManager().close();
weld.shutdown();
super.stop(); super.stop();
} }

View File

@@ -45,6 +45,7 @@ import javafx.util.Duration;
import jfxtras.labs.map.render.ImageMapMarker; import jfxtras.labs.map.render.ImageMapMarker;
import jfxtras.labs.map.render.MapMarkable; import jfxtras.labs.map.render.MapMarkable;
import javax.inject.Inject;
import java.net.URL; import java.net.URL;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Arrays; import java.util.Arrays;
@@ -97,7 +98,8 @@ public class CacheDetailsController implements Initializable, SessionContextList
private WebView shortDescriptionWebView; private WebView shortDescriptionWebView;
private WebView longDescriptionWebView; private WebView longDescriptionWebView;
private final SessionContext sessionContext = SessionContext.getInstance(); @Inject
private SessionContext sessionContext;
/** /**
* Initializes the controller class. * Initializes the controller class.

View File

@@ -142,6 +142,6 @@
</TabPane> </TabPane>
</children> </children>
<stylesheets> <stylesheets>
<URL value="@../geofrogger.css"/> <URL value="@/de/geofroggerfx/fx/geofrogger.css"/>
</stylesheets> </stylesheets>
</AnchorPane> </AnchorPane>

View File

@@ -25,7 +25,6 @@
*/ */
package de.geofroggerfx.fx.cachelist; package de.geofroggerfx.fx.cachelist;
import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.application.SessionContextListener; import de.geofroggerfx.application.SessionContextListener;
import de.geofroggerfx.fx.components.CacheListCell; import de.geofroggerfx.fx.components.CacheListCell;
@@ -39,10 +38,14 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuButton;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.util.Callback; import javafx.util.Callback;
import javax.inject.Inject;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@@ -59,8 +62,12 @@ public class CacheListController implements Initializable, SessionContextListene
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons"; private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
private final SessionContext sessionContext = SessionContext.getInstance(); @Inject
private final CacheService cacheService = ServiceManager.getInstance().getCacheService(); private SessionContext sessionContext;
@Inject
private CacheService cacheService;
private SortingMenuItem currentSortingButton = null; private SortingMenuItem currentSortingButton = null;
@FXML @FXML

View File

@@ -26,6 +26,6 @@
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/> AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
</children> </children>
<stylesheets> <stylesheets>
<URL value="@../geofrogger.css"/> <URL value="@/de/geofroggerfx/fx/geofrogger.css"/>
</stylesheets> </stylesheets>
</AnchorPane> </AnchorPane>

View File

@@ -26,7 +26,6 @@
package de.geofroggerfx.fx.geofrogger; package de.geofroggerfx.fx.geofrogger;
import de.geofroggerfx.application.ProgressEvent; import de.geofroggerfx.application.ProgressEvent;
import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.gpx.GPXReader; import de.geofroggerfx.gpx.GPXReader;
import de.geofroggerfx.model.Cache; import de.geofroggerfx.model.Cache;
@@ -45,6 +44,7 @@ import javafx.scene.control.*;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.controlsfx.dialog.Dialog; import org.controlsfx.dialog.Dialog;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@@ -53,8 +53,8 @@ import java.util.ResourceBundle;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static de.geofroggerfx.service.CacheSortField.*; import static de.geofroggerfx.service.CacheSortField.NAME;
import static de.geofroggerfx.service.SortDirection.*; import static de.geofroggerfx.service.SortDirection.ASC;
/** /**
* FXML Controller class * FXML Controller class
@@ -97,13 +97,19 @@ public class GeofroggerController implements Initializable {
+ "\t- H2 1.3.173\n" + "\t- H2 1.3.173\n"
+ "\t- Icons by http://iconmonstr.com/\n"; + "\t- Icons by http://iconmonstr.com/\n";
private final SessionContext sessionContext = SessionContext.getInstance(); @Inject
private SessionContext sessionContext;
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService(); private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService(); private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
private final GPXReader gpxReader = ServiceManager.getInstance().getGPXReader(); @Inject
private final CacheService cacheService = ServiceManager.getInstance().getCacheService(); private GPXReader gpxReader;
private final PluginService pluginService = ServiceManager.getInstance().getPluginService();
@Inject
private CacheService cacheService;
@Inject
private PluginService pluginService;
@FXML @FXML
private Label leftStatus; private Label leftStatus;

View File

@@ -29,10 +29,10 @@
<SplitPane dividerPositions="0.3779342723004695" focusTraversable="true" prefHeight="-1.0" prefWidth="-1.0" <SplitPane dividerPositions="0.3779342723004695" focusTraversable="true" prefHeight="-1.0" prefWidth="-1.0"
VBox.vgrow="ALWAYS"> VBox.vgrow="ALWAYS">
<items> <items>
<fx:include source="../cachelist/cache_list.fxml" fx:id="cacheListContent"/> <fx:include source="/de/geofroggerfx/fx/cachelist/cache_list.fxml" fx:id="cacheListContent"/>
<ScrollPane fitToHeight="true" fitToWidth="true" pannable="false" prefHeight="-1.0" prefWidth="-1.0"> <ScrollPane fitToHeight="true" fitToWidth="true" pannable="false" prefHeight="-1.0" prefWidth="-1.0">
<content> <content>
<fx:include source="../cachedetails/cache_details.fxml" fx:id="cacheDetailsContent"/> <fx:include source="/de/geofroggerfx/fx/cachedetails/cache_details.fxml" fx:id="cacheDetailsContent"/>
</content> </content>
</ScrollPane> </ScrollPane>
</items> </items>
@@ -56,6 +56,6 @@
</HBox> </HBox>
</children> </children>
<stylesheets> <stylesheets>
<URL value="@../geofrogger.css"/> <URL value="@/de/geofroggerfx/fx/geofrogger.css"/>
</stylesheets> </stylesheets>
</VBox> </VBox>

View File

@@ -0,0 +1,25 @@
package de.geofroggerfx.fx.utils;
import javafx.application.Application;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
/**
* This class is based on the tutorial
* http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
*
* Thanks to Matthieu BROUILLARD
*/
@Singleton
public class ApplicationParametersProvider {
private Application.Parameters parameters;
public void setParameters(Application.Parameters p) {
this.parameters = p;
}
public @Produces Application.Parameters getParameters() {
return parameters;
}
}

View File

@@ -0,0 +1,27 @@
package de.geofroggerfx.fx.utils;
import javafx.fxml.FXMLLoader;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
/**
* This class is based on the tutorial
* http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
*
* Thanks to Matthieu BROUILLARD
*/
public class FXMLLoaderProducer {
@Inject
private Instance<Object> instance;
@Produces
public FXMLLoader createLoader()
{
final FXMLLoader loader = new FXMLLoader();
loader.setControllerFactory(param -> instance.select(param).get());
return loader;
}
}

View File

@@ -0,0 +1,19 @@
package de.geofroggerfx.fx.utils;
import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This class is based on the tutorial
* http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
*
* Thanks to Matthieu BROUILLARD
*/
@Qualifier
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface StartupScene {
}

View File

@@ -1,9 +1,10 @@
package de.geofroggerfx.plugins; package de.geofroggerfx.plugins;
import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.service.CacheService;
import groovy.lang.GroovyClassLoader; import groovy.lang.GroovyClassLoader;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -19,7 +20,12 @@ import java.util.Map;
public class PluginServiceImpl implements PluginService { public class PluginServiceImpl implements PluginService {
private final GroovyClassLoader gcl = new GroovyClassLoader(); private final GroovyClassLoader gcl = new GroovyClassLoader();
private final ServiceManager serviceManager = ServiceManager.getInstance();
@Inject
private CacheService cacheService;
@Inject
private SessionContext sessionContext;
@Override @Override
@@ -54,8 +60,8 @@ public class PluginServiceImpl implements PluginService {
@Override @Override
public void executePlugin(final Plugin plugin) { public void executePlugin(final Plugin plugin) {
Map<String, Object> context = new HashMap<>(); Map<String, Object> context = new HashMap<>();
context.put("sessionContext", SessionContext.getInstance()); context.put("sessionContext", sessionContext);
context.put("cacheService", serviceManager.getCacheService()); context.put("cacheService", cacheService);
plugin.run(context); plugin.run(context);
} }
} }

View File

@@ -28,6 +28,7 @@ package de.geofroggerfx.service;
import de.geofroggerfx.application.ProgressListener; import de.geofroggerfx.application.ProgressListener;
import de.geofroggerfx.model.Cache; import de.geofroggerfx.model.Cache;
import javax.inject.Singleton;
import java.util.List; import java.util.List;
/** /**

View File

@@ -7,13 +7,13 @@ package de.geofroggerfx.service;
import de.geofroggerfx.application.ProgressEvent; import de.geofroggerfx.application.ProgressEvent;
import de.geofroggerfx.application.ProgressListener; import de.geofroggerfx.application.ProgressListener;
import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.model.Attribute; import de.geofroggerfx.model.Attribute;
import de.geofroggerfx.model.Cache; import de.geofroggerfx.model.Cache;
import de.geofroggerfx.model.Log; import de.geofroggerfx.model.Log;
import de.geofroggerfx.model.TravelBug; import de.geofroggerfx.model.TravelBug;
import de.geofroggerfx.sql.DatabaseService; import de.geofroggerfx.sql.DatabaseService;
import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -24,7 +24,9 @@ import java.util.List;
public class CacheServiceImpl implements CacheService { public class CacheServiceImpl implements CacheService {
private static final int TRANSACTION_SIZE = 100; private static final int TRANSACTION_SIZE = 100;
private final DatabaseService dbService = ServiceManager.getInstance().getDatabaseService();
@Inject
private DatabaseService dbService;
private final List<ProgressListener> listeners = new ArrayList<>(); private final List<ProgressListener> listeners = new ArrayList<>();
@Override @Override
@@ -50,7 +52,7 @@ public class CacheServiceImpl implements CacheService {
(double) currentCacheNumber / (double) numberOfCaches)); (double) currentCacheNumber / (double) numberOfCaches));
// begin transaction if the transaction counter is set to zero // begin transaction if the transaction counter is set to zero
if (transactionNumber == 0) { em.getTransaction().begin(); }; if (transactionNumber == 0) { em.getTransaction().begin(); }
transactionNumber++; transactionNumber++;
em.merge(cache.getOwner()); em.merge(cache.getOwner());

View File

@@ -39,8 +39,6 @@ public class DatabaseServiceImpl implements DatabaseService {
private EntityManager em; private EntityManager em;
public DatabaseServiceImpl() { public DatabaseServiceImpl() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = factory.createEntityManager(); em = factory.createEntityManager();
} }