Source Code Cross Referenced for Hibernate.java in  » EJB-Server-JBoss-4.2.1 » hibernate-int » org » jboss » hibernate » jmx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » hibernate int » org.jboss.hibernate.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.hibernate.jmx;
023:
024:        import java.io.File;
025:        import java.net.URL;
026:        import java.net.URLClassLoader;
027:        import java.util.Date;
028:        import java.util.HashSet;
029:        import java.util.Iterator;
030:        import java.util.Properties;
031:        import java.util.jar.JarFile;
032:
033:        import javax.management.Notification;
034:        import javax.management.ObjectName;
035:        import javax.naming.InitialContext;
036:        import javax.naming.NamingException;
037:
038:        import org.hibernate.HibernateException;
039:        import org.hibernate.Interceptor;
040:        import org.hibernate.SessionFactory;
041:        import org.hibernate.cfg.Configuration;
042:        import org.hibernate.cfg.Environment;
043:        import org.hibernate.jmx.StatisticsService;
044:        import org.hibernate.tool.hbm2ddl.SchemaExport;
045:        import org.hibernate.transaction.JBossTransactionManagerLookup;
046:        import org.hibernate.transaction.JTATransactionFactory;
047:        import org.jboss.deployment.DeploymentException;
048:        import org.jboss.deployment.DeploymentInfo;
049:        import org.jboss.hibernate.ListenerInjector;
050:        import org.jboss.hibernate.cache.DeployedTreeCacheProvider;
051:        import org.jboss.logging.Logger;
052:        import org.jboss.mx.loading.RepositoryClassLoader;
053:        import org.jboss.util.naming.Util;
054:        import org.jboss.system.ServiceMBeanSupport;
055:
056:        /**
057:         * The {@link HibernateMBean} implementation.
058:         *
059:         * @version <tt>$Revision: 60195 $</tt>
060:         * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
061:         * @author <a href="mailto:gavin@hibernate.org">Gavin King</a>
062:         * @author <a href="mailto:steve@hibernate.org">Steve Ebersole</a>
063:         * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
064:         */
065:        public class Hibernate extends ServiceMBeanSupport implements 
066:                HibernateMBean {
067:
068:            private static final Logger log = Logger.getLogger(Hibernate.class);
069:
070:            public static final String SESSION_FACTORY_CREATE = "hibernate.sessionfactory.create";
071:            public static final String SESSION_FACTORY_DESTROY = "hibernate.sessionfactory.destroy";
072:
073:            // Configuration attributes "passed through" to Hibernate
074:            private String datasourceName;
075:            private String dialect;
076:            private String defaultSchema;
077:            private String defaultCatalog;
078:            private Boolean sqlCommentsEnabled;
079:            private Integer maxFetchDepth;
080:            private Integer jdbcFetchSize;
081:            private Integer jdbcBatchSize;
082:            private Boolean batchVersionedDataEnabled;
083:            private Boolean jdbcScrollableResultSetEnabled;
084:            private Boolean getGeneratedKeysEnabled;
085:            private Boolean streamsForBinaryEnabled;
086:            private String hbm2ddlAuto;
087:            private String querySubstitutions;
088:            private Boolean showSqlEnabled;
089:            private String username;
090:            private String password;
091:            private Boolean secondLevelCacheEnabled = Boolean.TRUE;
092:            private Boolean queryCacheEnabled;
093:            private String cacheProviderClass;
094:            private ObjectName deployedTreeCacheObjectName;
095:            private Boolean minimalPutsEnabled;
096:            private String cacheRegionPrefix;
097:            private Boolean structuredCacheEntriesEnabled;
098:            private Boolean statGenerationEnabled;
099:            private Boolean reflectionOptimizationEnabled;
100:
101:            // Configuration attributes used by the MBean
102:            private String sessionFactoryName;
103:            private String sessionFactoryInterceptor;
104:            private String listenerInjector;
105:            private URL harUrl;
106:            private boolean scanForMappingsEnabled = false;
107:            private HashSet archiveClasspathUrls = new HashSet();
108:            private HashSet directoryClasspathUrls = new HashSet();
109:
110:            // Internal state
111:            private boolean dirty = false;
112:            private SessionFactory sessionFactory;
113:            private Date runningSince;
114:            private ObjectName hibernateStatisticsServiceName;
115:
116:            protected void createService() throws Exception {
117:                log.trace("forcing bytecode provider -> javassist");
118:                // todo : really need a much better solution for this...
119:                System.setProperty(Environment.BYTECODE_PROVIDER, "javassist");
120:            }
121:
122:            /**
123:             * Configure Hibernate and bind the <tt>SessionFactory</tt> to JNDI.
124:             */
125:            public void startService() throws Exception {
126:                log.debug("Hibernate MBean starting; " + this );
127:
128:                // be defensive...
129:                if (sessionFactory != null) {
130:                    destroySessionFactory();
131:                }
132:
133:                harUrl = determineHarUrl();
134:
135:                if (harUrl != null) {
136:                    log.trace("starting in har deployment mode");
137:                    // we are part of a har deployment...
138:                    if (scanForMappingsEnabled) {
139:                        log.trace("scan for mappings was enabled");
140:                        scanForMappings();
141:                    }
142:                } else {
143:                    // we are not contained within a har deployment...
144:                    log.trace("starting in non-har deployment mode");
145:                    scanForMappings();
146:                }
147:
148:                buildSessionFactory();
149:            }
150:
151:            /**
152:             * Close the <tt>SessionFactory</tt>.
153:             */
154:            public void stopService() throws Exception {
155:                destroySessionFactory();
156:                archiveClasspathUrls.clear();
157:                directoryClasspathUrls.clear();
158:            }
159:
160:            private URL determineHarUrl() throws Exception {
161:                log.trace("Attempting to determine HarUrl...");
162:                DeploymentInfo deploymentInfo = getDeploymentInfo();
163:                if (deploymentInfo == null) {
164:                    log.warn("Unable to locate deployment info ["
165:                            + getServiceName() + "]");
166:                    return null;
167:                }
168:
169:                String urlStr = deploymentInfo.url.getFile();
170:                log.trace("checking our deployment unit [" + urlStr + "]");
171:                if (urlStr.endsWith(".har") || urlStr.endsWith(".har/")) {
172:                    return deploymentInfo.url;
173:                } else {
174:                    return null;
175:                }
176:            }
177:
178:            private final Configuration buildConfiguration() throws Exception {
179:                log.debug("Building SessionFactory; " + this );
180:
181:                Configuration cfg = new Configuration();
182:                cfg.getProperties().clear(); // avoid reading hibernate.properties and Sys-props
183:
184:                // Handle custom listeners....
185:                ListenerInjector listenerInjector = generateListenerInjectorInstance();
186:                if (listenerInjector != null) {
187:                    listenerInjector.injectListeners(getServiceName(), cfg);
188:                }
189:
190:                // Handle config settings....
191:                transferSettings(cfg.getProperties());
192:
193:                // Handle mappings....
194:                handleMappings(cfg);
195:
196:                // Handle interceptor....
197:                Interceptor interceptorInstance = generateInterceptorInstance();
198:                if (interceptorInstance != null) {
199:                    cfg.setInterceptor(interceptorInstance);
200:                }
201:
202:                return cfg;
203:            }
204:
205:            /**
206:             * Centralize the logic needed for starting/binding the SessionFactory.
207:             *
208:             * @throws Exception
209:             */
210:            private void buildSessionFactory() throws Exception {
211:
212:                Configuration cfg = buildConfiguration();
213:
214:                // Generate sf....
215:                sessionFactory = cfg.buildSessionFactory();
216:
217:                try {
218:                    // Handle stat-mbean creation/registration....
219:                    if (sessionFactory.getStatistics() != null
220:                            && sessionFactory.getStatistics()
221:                                    .isStatisticsEnabled()) {
222:                        String serviceName = getServiceName().toString();
223:                        if (serviceName.indexOf("type=service") != -1) {
224:                            serviceName = serviceName.replaceAll(
225:                                    "type=service", "type=stats");
226:                        } else {
227:                            serviceName = serviceName + ",type=stats";
228:                        }
229:                        hibernateStatisticsServiceName = new ObjectName(
230:                                serviceName);
231:                        StatisticsService hibernateStatisticsService = new StatisticsService();
232:                        hibernateStatisticsService
233:                                .setSessionFactory(sessionFactory);
234:                        getServer().registerMBean(hibernateStatisticsService,
235:                                hibernateStatisticsServiceName);
236:                    }
237:
238:                    // Handle JNDI binding....
239:                    bind();
240:                } catch (Exception e) {
241:                    forceCleanup();
242:                    throw e;
243:                }
244:
245:                dirty = false;
246:
247:                sendNotification(new Notification(SESSION_FACTORY_CREATE,
248:                        getServiceName(), getNextNotificationSequenceNumber()));
249:
250:                runningSince = new Date();
251:
252:                log
253:                        .info("SessionFactory successfully built and bound into JNDI ["
254:                                + sessionFactoryName + "]");
255:            }
256:
257:            /**
258:             * Centralize the logic needed to unbind/close a SessionFactory.
259:             *
260:             * @throws Exception
261:             */
262:            private void destroySessionFactory() throws Exception {
263:                if (sessionFactory != null) {
264:                    // TODO : exact situations where we need to clear the 2nd-lvl cache?
265:                    // (to allow clean release of the classloaders)
266:                    // Most likely, if custom classes are directly cached (UserTypes); anything else?
267:                    unbind();
268:                    sessionFactory.close();
269:                    sessionFactory = null;
270:                    runningSince = null;
271:
272:                    if (hibernateStatisticsServiceName != null) {
273:                        try {
274:                            getServer().unregisterMBean(
275:                                    hibernateStatisticsServiceName);
276:                        } catch (Throwable t) {
277:                            // just log it
278:                            log.warn("unable to cleanup statistics mbean", t);
279:                        }
280:                    }
281:
282:                    sendNotification(new Notification(SESSION_FACTORY_DESTROY,
283:                            getServiceName(),
284:                            getNextNotificationSequenceNumber()));
285:                }
286:            }
287:
288:            private void handleMappings(Configuration cfg) {
289:                //if scanForMappingsEnabled=true we dont want to add the xyz.har file
290:                //as scanForMappingsEnabled=true has already added it to archiveClasspathUrls
291:                if (harUrl != null && !scanForMappingsEnabled) {
292:                    final File file = new File(harUrl.getFile());
293:                    if (file.isDirectory()) {
294:                        cfg.addDirectory(file);
295:                    } else {
296:                        cfg.addJar(file);
297:                    }
298:                }
299:
300:                Iterator itr = archiveClasspathUrls.iterator();
301:                while (itr.hasNext()) {
302:                    final File archive = (File) itr.next();
303:                    log.debug("Passing archive [" + archive
304:                            + "] to Hibernate Configration");
305:                    cfg.addJar(archive);
306:                }
307:
308:                itr = directoryClasspathUrls.iterator();
309:                while (itr.hasNext()) {
310:                    final File directory = (File) itr.next();
311:                    log.debug("Passing directory [" + directory
312:                            + "] to Hibernate Configration");
313:                    cfg.addDirectory(directory);
314:                }
315:            }
316:
317:            /**
318:             * Scan the current context's classloader to locate any potential sources of Hibernate mapping files.
319:             *
320:             * @throws DeploymentException
321:             */
322:            private void scanForMappings() throws DeploymentException {
323:                // Won't this cause problems if start() is called from say the console?
324:                // a way around is to locate our DeploymentInfo and grab its ucl attribute
325:                // for use here.
326:                URL[] urls = null;
327:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
328:                if (cl instanceof  RepositoryClassLoader) {
329:                    urls = ((RepositoryClassLoader) cl).getClasspath();
330:                } else if (cl instanceof  URLClassLoader) {
331:                    urls = ((URLClassLoader) cl).getURLs();
332:                } else {
333:                    throw new DeploymentException(
334:                            "Unable to determine urls from classloader [" + cl
335:                                    + "]");
336:                }
337:
338:                // Search the urls for each of the classpath entries for any containing
339:                // hibernate mapping files or archives
340:                for (int i = 0; i < urls.length; i++) {
341:                    final File entry = new File(urls[i].getFile());
342:                    log.trace("checking classpath entry [" + entry + "]");
343:                    if (!entry.exists()) {
344:                        continue;
345:                    }
346:
347:                    if (!entry.isDirectory()) {
348:                        // This entry is not a directory, meaning it is a file of
349:                        // some sort.  If it is an archive, we are interested in it...
350:                        if (isArchive(entry)) {
351:                            log.trace("classpath entry was an archive file...");
352:                            archiveClasspathUrls.add(entry);
353:                        } else {
354:                            log
355:                                    .trace("classpath entry was a non-archive file...");
356:                        }
357:                    } else {
358:                        log.trace("classpath entry was a directory...");
359:
360:                        // we have a directory, add it to the list of directory classpath urls
361:                        directoryClasspathUrls.add(entry);
362:                    }
363:                }
364:            }
365:
366:            /**
367:             * Simple helper method to determine whether a given File instance represents an archive which complies with the JAR
368:             * specification.
369:             *
370:             * @param file The file to test.
371:             *
372:             * @return True if the incoming file for certain represents an archive; false otherwise.
373:             */
374:            private boolean isArchive(File file) {
375:                try {
376:                    new JarFile(file);
377:                    return true;
378:                } catch (Throwable t) {
379:                    return false;
380:                }
381:            }
382:
383:            public void createSchema() throws Exception {
384:                new SchemaExport(buildConfiguration()).create(false, true);
385:            }
386:
387:            public void dropSchema() throws Exception {
388:                new SchemaExport(buildConfiguration()).drop(false, true);
389:            }
390:
391:            /**
392:             * Transfer the state represented by our current attribute values into the given Properties instance, translating our
393:             * attributes into the appropriate Hibernate settings.
394:             *
395:             * @param settings The Properties instance to which to add our state.
396:             */
397:            private void transferSettings(Properties settings) {
398:                if (cacheProviderClass == null) {
399:                    cacheProviderClass = "org.hibernate.cache.HashtableCacheProvider";
400:                }
401:
402:                log.debug("Using JDBC batch size : " + jdbcBatchSize);
403:
404:                setUnlessNull(settings, Environment.DATASOURCE, datasourceName);
405:                setUnlessNull(settings, Environment.DIALECT, dialect);
406:                setUnlessNull(settings, Environment.CACHE_PROVIDER,
407:                        cacheProviderClass);
408:                setUnlessNull(settings, Environment.CACHE_REGION_PREFIX,
409:                        cacheRegionPrefix);
410:                setUnlessNull(settings, Environment.USE_MINIMAL_PUTS,
411:                        minimalPutsEnabled);
412:                setUnlessNull(settings, Environment.HBM2DDL_AUTO, hbm2ddlAuto);
413:                setUnlessNull(settings, Environment.DEFAULT_SCHEMA,
414:                        defaultSchema);
415:                setUnlessNull(settings, Environment.STATEMENT_BATCH_SIZE,
416:                        jdbcBatchSize);
417:                setUnlessNull(settings, Environment.USE_SQL_COMMENTS,
418:                        sqlCommentsEnabled);
419:
420:                setUnlessNull(settings, Environment.STATEMENT_FETCH_SIZE,
421:                        jdbcFetchSize);
422:                setUnlessNull(settings, Environment.USE_SCROLLABLE_RESULTSET,
423:                        jdbcScrollableResultSetEnabled);
424:                setUnlessNull(settings, Environment.USE_QUERY_CACHE,
425:                        queryCacheEnabled);
426:                setUnlessNull(settings, Environment.USE_STRUCTURED_CACHE,
427:                        structuredCacheEntriesEnabled);
428:                setUnlessNull(settings, Environment.QUERY_SUBSTITUTIONS,
429:                        querySubstitutions);
430:                setUnlessNull(settings, Environment.MAX_FETCH_DEPTH,
431:                        maxFetchDepth);
432:                setUnlessNull(settings, Environment.SHOW_SQL, showSqlEnabled);
433:                setUnlessNull(settings, Environment.USE_GET_GENERATED_KEYS,
434:                        getGeneratedKeysEnabled);
435:                setUnlessNull(settings, Environment.USER, username);
436:                setUnlessNull(settings, Environment.PASS, password);
437:                setUnlessNull(settings, Environment.BATCH_VERSIONED_DATA,
438:                        batchVersionedDataEnabled);
439:                setUnlessNull(settings, Environment.USE_STREAMS_FOR_BINARY,
440:                        streamsForBinaryEnabled);
441:                setUnlessNull(settings, Environment.USE_REFLECTION_OPTIMIZER,
442:                        reflectionOptimizationEnabled);
443:                setUnlessNull(settings, Environment.GENERATE_STATISTICS,
444:                        statGenerationEnabled);
445:
446:                setUnlessNull(settings,
447:                        Environment.TRANSACTION_MANAGER_STRATEGY,
448:                        JBossTransactionManagerLookup.class.getName());
449:                setUnlessNull(settings, Environment.TRANSACTION_STRATEGY,
450:                        JTATransactionFactory.class.getName());
451:
452:                if (deployedTreeCacheObjectName != null) {
453:                    String objNameString = deployedTreeCacheObjectName
454:                            .toString();
455:                    if (objNameString != null && !"".equals(objNameString)) {
456:                        settings.setProperty(
457:                                DeployedTreeCacheProvider.OBJECT_NAME_PROP,
458:                                objNameString);
459:                    }
460:                }
461:
462:                settings.setProperty(Environment.FLUSH_BEFORE_COMPLETION,
463:                        "true");
464:                settings.setProperty(Environment.AUTO_CLOSE_SESSION, "true");
465:
466:                // This is really H3-version-specific:
467:                // in 3.0.3 and later, this should be the ConnectionReleaseMode enum;
468:                // in 3.0.2, this is a true/false setting;
469:                // in 3.0 -> 3.0.1, there is no such setting
470:                //
471:                // so we just set them both :)
472:                settings.setProperty("hibernate.connection.agressive_release",
473:                        "true");
474:                settings.setProperty("hibernate.connection.release_mode",
475:                        "after_statement");
476:            }
477:
478:            /**
479:             * Simple helper method for transferring individual settings to a properties
480:             * instance only if the setting's value is not null.
481:             *
482:             * @param props The properties instance into which to transfer the setting
483:             * @param key The key under which to transfer the setting
484:             * @param value The value of the setting.
485:             */
486:            private void setUnlessNull(Properties props, String key,
487:                    Object value) {
488:                if (value != null) {
489:                    props.setProperty(key, value.toString());
490:                }
491:            }
492:
493:            private ListenerInjector generateListenerInjectorInstance() {
494:                if (listenerInjector == null) {
495:                    return null;
496:                }
497:
498:                log.info("attempting to use listener injector ["
499:                        + listenerInjector + "]");
500:                try {
501:                    return (ListenerInjector) Thread.currentThread()
502:                            .getContextClassLoader()
503:                            .loadClass(listenerInjector).newInstance();
504:                } catch (Throwable t) {
505:                    log.warn("Unable to generate specified listener injector",
506:                            t);
507:                }
508:
509:                return null;
510:            }
511:
512:            private Interceptor generateInterceptorInstance() {
513:                if (sessionFactoryInterceptor == null) {
514:                    return null;
515:                }
516:
517:                log.info("Generating session factory interceptor instance ["
518:                        + sessionFactoryInterceptor + "]");
519:                try {
520:                    return (Interceptor) Thread.currentThread()
521:                            .getContextClassLoader().loadClass(
522:                                    sessionFactoryInterceptor).newInstance();
523:                } catch (Throwable t) {
524:                    log
525:                            .warn(
526:                                    "Unable to generate session factory interceptor instance",
527:                                    t);
528:                }
529:
530:                return null;
531:            }
532:
533:            /**
534:             * Perform the steps necessary to bind the managed SessionFactory into JNDI.
535:             *
536:             * @throws HibernateException
537:             */
538:            private void bind() throws HibernateException {
539:                InitialContext ctx = null;
540:                try {
541:                    ctx = new InitialContext();
542:                    Util.bind(ctx, sessionFactoryName, sessionFactory);
543:                } catch (NamingException e) {
544:                    throw new HibernateException(
545:                            "Unable to bind SessionFactory into JNDI", e);
546:                } finally {
547:                    if (ctx != null) {
548:                        try {
549:                            ctx.close();
550:                        } catch (Throwable ignore) {
551:                            // ignore
552:                        }
553:                    }
554:                }
555:            }
556:
557:            /**
558:             * Perform the steps necessary to unbind the managed SessionFactory from JNDI.
559:             *
560:             * @throws HibernateException
561:             */
562:            private void unbind() throws HibernateException {
563:                InitialContext ctx = null;
564:                try {
565:                    ctx = new InitialContext();
566:                    Util.unbind(ctx, sessionFactoryName);
567:                } catch (NamingException e) {
568:                    throw new HibernateException(
569:                            "Unable to unbind SessionFactory from JNDI", e);
570:                } finally {
571:                    if (ctx != null) {
572:                        try {
573:                            ctx.close();
574:                        } catch (Throwable ignore) {
575:                            // ignore
576:                        }
577:                    }
578:                }
579:            }
580:
581:            private void forceCleanup() {
582:                try {
583:                    sessionFactory.close();
584:                    sessionFactory = null;
585:                } catch (Throwable ignore) {
586:                    // ignore
587:                }
588:            }
589:
590:            public String toString() {
591:                return super .toString() + " [ServiceName=" + serviceName
592:                        + ", JNDI=" + sessionFactoryName + "]";
593:            }
594:
595:            // Managed operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
596:
597:            public void rebuildSessionFactory() throws Exception {
598:                destroySessionFactory();
599:                buildSessionFactory();
600:            }
601:
602:            // RO managed attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
603:
604:            public boolean isDirty() {
605:                return dirty;
606:            }
607:
608:            public boolean isSessionFactoryRunning() {
609:                return sessionFactory != null;
610:            }
611:
612:            public String getVersion() {
613:                return Environment.VERSION;
614:            }
615:
616:            public SessionFactory getInstance() {
617:                return sessionFactory;
618:            }
619:
620:            public URL getHarUrl() {
621:                return harUrl;
622:            }
623:
624:            public ObjectName getStatisticsServiceName() {
625:                return hibernateStatisticsServiceName;
626:            }
627:
628:            public Date getRunningSince() {
629:                return runningSince;
630:            }
631:
632:            // R/W managed attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
633:
634:            public String getSessionFactoryName() {
635:                return sessionFactoryName;
636:            }
637:
638:            public void setSessionFactoryName(String sessionFactoryName) {
639:                this .sessionFactoryName = sessionFactoryName;
640:                dirty = true;
641:            }
642:
643:            public String getDatasourceName() {
644:                return datasourceName;
645:            }
646:
647:            public void setDatasourceName(String datasourceName) {
648:                this .datasourceName = datasourceName;
649:                dirty = true;
650:            }
651:
652:            public String getUsername() {
653:                return username;
654:            }
655:
656:            public void setUsername(String username) {
657:                this .username = username;
658:                dirty = true;
659:            }
660:
661:            public void setPassword(String password) {
662:                this .password = password;
663:                dirty = true;
664:            }
665:
666:            public String getDefaultSchema() {
667:                return defaultSchema;
668:            }
669:
670:            public void setDefaultSchema(String defaultSchema) {
671:                this .defaultSchema = defaultSchema;
672:                dirty = true;
673:            }
674:
675:            public String getDefaultCatalog() {
676:                return defaultCatalog;
677:            }
678:
679:            public void setDefaultCatalog(String defaultCatalog) {
680:                this .defaultCatalog = defaultCatalog;
681:            }
682:
683:            public String getHbm2ddlAuto() {
684:                return hbm2ddlAuto;
685:            }
686:
687:            public void setHbm2ddlAuto(String hbm2ddlAuto) {
688:                this .hbm2ddlAuto = hbm2ddlAuto;
689:                dirty = true;
690:            }
691:
692:            public String getDialect() {
693:                return dialect;
694:            }
695:
696:            public void setDialect(String dialect) {
697:                this .dialect = dialect;
698:                dirty = true;
699:            }
700:
701:            public Integer getMaxFetchDepth() {
702:                return maxFetchDepth;
703:            }
704:
705:            public void setMaxFetchDepth(Integer maxFetchDepth) {
706:                this .maxFetchDepth = maxFetchDepth;
707:                dirty = true;
708:            }
709:
710:            public Integer getJdbcBatchSize() {
711:                return jdbcBatchSize;
712:            }
713:
714:            public void setJdbcBatchSize(Integer jdbcBatchSize) {
715:                this .jdbcBatchSize = jdbcBatchSize;
716:                dirty = true;
717:            }
718:
719:            public Integer getJdbcFetchSize() {
720:                return jdbcFetchSize;
721:            }
722:
723:            public void setJdbcFetchSize(Integer jdbcFetchSize) {
724:                this .jdbcFetchSize = jdbcFetchSize;
725:                dirty = true;
726:            }
727:
728:            public Boolean getJdbcScrollableResultSetEnabled() {
729:                return jdbcScrollableResultSetEnabled;
730:            }
731:
732:            public void setJdbcScrollableResultSetEnabled(
733:                    Boolean jdbcScrollableResultSetEnabled) {
734:                this .jdbcScrollableResultSetEnabled = jdbcScrollableResultSetEnabled;
735:                dirty = true;
736:            }
737:
738:            public Boolean getGetGeneratedKeysEnabled() {
739:                return getGeneratedKeysEnabled;
740:            }
741:
742:            public void setGetGeneratedKeysEnabled(
743:                    Boolean getGeneratedKeysEnabled) {
744:                this .getGeneratedKeysEnabled = getGeneratedKeysEnabled;
745:                dirty = true;
746:            }
747:
748:            public String getQuerySubstitutions() {
749:                return querySubstitutions;
750:            }
751:
752:            public void setQuerySubstitutions(String querySubstitutions) {
753:                this .querySubstitutions = querySubstitutions;
754:                dirty = true;
755:            }
756:
757:            public Boolean getSecondLevelCacheEnabled() {
758:                return secondLevelCacheEnabled;
759:            }
760:
761:            public void setSecondLevelCacheEnabled(
762:                    Boolean secondLevelCacheEnabled) {
763:                this .secondLevelCacheEnabled = secondLevelCacheEnabled;
764:                dirty = true;
765:            }
766:
767:            public Boolean getQueryCacheEnabled() {
768:                return queryCacheEnabled;
769:            }
770:
771:            public void setQueryCacheEnabled(Boolean queryCacheEnabled) {
772:                this .queryCacheEnabled = queryCacheEnabled;
773:                dirty = true;
774:            }
775:
776:            public String getCacheProviderClass() {
777:                return cacheProviderClass;
778:            }
779:
780:            public void setCacheProviderClass(String cacheProviderClass) {
781:                this .cacheProviderClass = cacheProviderClass;
782:                dirty = true;
783:            }
784:
785:            public String getCacheRegionPrefix() {
786:                return cacheRegionPrefix;
787:            }
788:
789:            public void setCacheRegionPrefix(String cacheRegionPrefix) {
790:                this .cacheRegionPrefix = cacheRegionPrefix;
791:                dirty = true;
792:            }
793:
794:            public Boolean getMinimalPutsEnabled() {
795:                return minimalPutsEnabled;
796:            }
797:
798:            public void setMinimalPutsEnabled(Boolean minimalPutsEnabled) {
799:                this .minimalPutsEnabled = minimalPutsEnabled;
800:                dirty = true;
801:            }
802:
803:            public Boolean getUseStructuredCacheEntriesEnabled() {
804:                return structuredCacheEntriesEnabled;
805:            }
806:
807:            public void setUseStructuredCacheEntriesEnabled(
808:                    Boolean structuredCacheEntriesEnabled) {
809:                this .structuredCacheEntriesEnabled = structuredCacheEntriesEnabled;
810:            }
811:
812:            public Boolean getShowSqlEnabled() {
813:                return showSqlEnabled;
814:            }
815:
816:            public void setShowSqlEnabled(Boolean showSqlEnabled) {
817:                this .showSqlEnabled = showSqlEnabled;
818:                dirty = true;
819:            }
820:
821:            public Boolean getSqlCommentsEnabled() {
822:                return sqlCommentsEnabled;
823:            }
824:
825:            public void setSqlCommentsEnabled(Boolean commentsEnabled) {
826:                this .sqlCommentsEnabled = commentsEnabled;
827:            }
828:
829:            public String getSessionFactoryInterceptor() {
830:                return sessionFactoryInterceptor;
831:            }
832:
833:            public void setSessionFactoryInterceptor(
834:                    String sessionFactoryInterceptor) {
835:                this .sessionFactoryInterceptor = sessionFactoryInterceptor;
836:                dirty = true;
837:            }
838:
839:            public String getListenerInjector() {
840:                return listenerInjector;
841:            }
842:
843:            public void setListenerInjector(String listenerInjector) {
844:                this .listenerInjector = listenerInjector;
845:            }
846:
847:            public ObjectName getDeployedTreeCacheObjectName() {
848:                return deployedTreeCacheObjectName;
849:            }
850:
851:            public void setDeployedTreeCacheObjectName(
852:                    ObjectName deployedTreeCacheObjectName) {
853:                this .deployedTreeCacheObjectName = deployedTreeCacheObjectName;
854:            }
855:
856:            public Boolean getBatchVersionedDataEnabled() {
857:                return batchVersionedDataEnabled;
858:            }
859:
860:            public void setBatchVersionedDataEnabled(
861:                    Boolean batchVersionedDataEnabled) {
862:                this .batchVersionedDataEnabled = batchVersionedDataEnabled;
863:                this .dirty = true;
864:            }
865:
866:            public Boolean getStreamsForBinaryEnabled() {
867:                return streamsForBinaryEnabled;
868:            }
869:
870:            public void setStreamsForBinaryEnabled(
871:                    Boolean streamsForBinaryEnabled) {
872:                this .streamsForBinaryEnabled = streamsForBinaryEnabled;
873:                this .dirty = true;
874:            }
875:
876:            public Boolean getReflectionOptimizationEnabled() {
877:                return reflectionOptimizationEnabled;
878:            }
879:
880:            public void setReflectionOptimizationEnabled(
881:                    Boolean reflectionOptimizationEnabled) {
882:                this .reflectionOptimizationEnabled = reflectionOptimizationEnabled;
883:                this .dirty = true;
884:            }
885:
886:            public Boolean getStatGenerationEnabled() {
887:                return statGenerationEnabled;
888:            }
889:
890:            public void setStatGenerationEnabled(Boolean statGenerationEnabled) {
891:                this .statGenerationEnabled = statGenerationEnabled;
892:            }
893:
894:            public boolean isScanForMappingsEnabled() {
895:                return scanForMappingsEnabled;
896:            }
897:
898:            public void setScanForMappingsEnabled(boolean scanForMappingsEnabled) {
899:                this.scanForMappingsEnabled = scanForMappingsEnabled;
900:            }
901:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.