Project

General

Profile

« Previous | Next » 

Revision 3fd7eb7e

Added by Cherian Mathew over 9 years ago

moving code to remoting project

View differences:

.gitattributes
326 326
eu.etaxonomy.taxeditor.cdmlib/lib/xstream-1.4.4.jar -text
327 327
eu.etaxonomy.taxeditor.cdmlib/lib/yjp-controller-api-redist-9.0.8.jar -text
328 328
eu.etaxonomy.taxeditor.cdmlib/pom.xml -text
329
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java -text
330
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java -text
331
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java -text
332
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java -text
333
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmPersistentRemoteSource.java -text
334
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSource.java -text
335
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceBase.java -text
336
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceException.java -text
337
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/ICdmRemoteSource.java -text
338
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java -text
339
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java -text
340 329
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/config.properties -text
341 330
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml -text
342 331
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicationContext.xml -text
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
8 8
 com.google.api.detect,
9 9
 com.google.api.translate,
10 10
 eu.etaxonomy.cdm.api.application,
11
 eu.etaxonomy.cdm.api.cache,
11 12
 eu.etaxonomy.cdm.api.conversation,
12 13
 eu.etaxonomy.cdm.api.facade,
13
 eu.etaxonomy.cdm.api.lazyloading,
14 14
 eu.etaxonomy.cdm.api.service,
15 15
 eu.etaxonomy.cdm.api.service.config,
16 16
 eu.etaxonomy.cdm.api.service.description,
......
129 129
 eu.etaxonomy.cdm.print.out.pdf,
130 130
 eu.etaxonomy.cdm.print.out.taxpub,
131 131
 eu.etaxonomy.cdm.print.out.xml,
132
 eu.etaxonomy.cdm.remote,
133 132
 eu.etaxonomy.cdm.remote.config,
134 133
 eu.etaxonomy.cdm.remote.controller,
135 134
 eu.etaxonomy.cdm.remote.controller.dto,
......
181 180
 eu.etaxonomy.cdm.validation.annotation,
182 181
 eu.etaxonomy.cdm.validation.constraint,
183 182
 eu.etaxonomy.remote.dto.rdf,
183
 javassist.util.proxy,
184 184
 javax.persistence,
185 185
 junit.framework;uses:="org.junit.runner.manipulation,org.junit.runner,org.junit.runner.notification",
186
 net.sf.ehcache,
187
 net.sf.ehcache.config,
188
 net.sf.ehcache.store,
186 189
 net.sf.json;uses:="net.sf.json.processors,net.sf.json.util,org.apache.commons.lang.exception",
187 190
 org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
188 191
 org.apache.commons.io;uses:="org.apache.commons.io.filefilter",
......
255 258
 org.hibernate,
256 259
 org.hibernate.annotations.common.reflection,
257 260
 org.hibernate.cache.internal,
261
 org.hibernate.cfg,
258 262
 org.hibernate.classic,
259 263
 org.hibernate.collection.internal,
264
 org.hibernate.collection.spi,
260 265
 org.hibernate.criterion,
266
 org.hibernate.engine.internal,
267
 org.hibernate.engine.spi,
268
 org.hibernate.engine.transaction.spi,
261 269
 org.hibernate.envers.query.criteria,
270
 org.hibernate.internal,
271
 org.hibernate.internal.util,
272
 org.hibernate.internal.util.collections,
273
 org.hibernate.mapping,
274
 org.hibernate.persister.collection,
275
 org.hibernate.persister.entity,
276
 org.hibernate.pretty,
277
 org.hibernate.property,
262 278
 org.hibernate.proxy,
279
 org.hibernate.proxy.pojo.javassist,
263 280
 org.hibernate.search,
264 281
 org.hibernate.search.spatial.impl,
282
 org.hibernate.type,
265 283
 org.jadira.usertype.dateandtime.joda,
266 284
 org.jadira.usertype.dateandtime.shared.spi,
267 285
 org.jboss.logging,
......
300 318
 org.odftoolkit.odfdom.dom.element,
301 319
 org.odftoolkit.odfdom.dom.element.style,
302 320
 org.odftoolkit.odfdom.dom.style,
321
 org.springframework.beans,
303 322
 org.springframework.beans.factory,
304 323
 org.springframework.beans.factory.annotation;
305 324
  uses:="org.apache.commons.logging,
......
310 329
   org.springframework.beans.factory.wiring,
311 330
   org.springframework.core.type,
312 331
   org.springframework.beans.factory",
332
 org.springframework.beans.factory.config,
333
 org.springframework.beans.factory.support,
334
 org.springframework.beans.factory.xml,
313 335
 org.springframework.cache.ehcache,
314 336
 org.springframework.context;
315 337
  uses:="org.springframework.core.io,
......
322 344
   org.aopalliance.intercept,
323 345
   org.springframework.context,
324 346
   org.springframework.beans.factory",
347
 org.springframework.context.support,
325 348
 org.springframework.core;uses:="org.springframework.util",
349
 org.springframework.core.env,
326 350
 org.springframework.core.io;uses:="org.jboss.virtual",
351
 org.springframework.core.io.support,
327 352
 org.springframework.core.type.classreading,
328 353
 org.springframework.orm.hibernate3;
329 354
  uses:="org.apache.commons.logging,
......
351 376
   org.springframework.dao,
352 377
   org.springframework.transaction.support",
353 378
 org.springframework.orm.hibernate4,
379
 org.springframework.remoting,
380
 org.springframework.remoting.httpinvoker,
381
 org.springframework.remoting.support,
354 382
 org.springframework.security.access,
355 383
 org.springframework.security.authentication,
356 384
 org.springframework.security.authentication.event,
......
390 418
   org.springframework.transaction,
391 419
   org.apache.commons.logging,
392 420
   org.springframework.beans.factory",
421
 org.springframework.util,
393 422
 org.springframework.web.servlet;
394 423
  uses:="org.springframework.web.multipart,
395 424
   org.apache.commons.logging,
......
402 431
   org.springframework.context.event,
403 432
   javax.servlet,
404 433
   org.springframework.ui,
405
   javax.servlet.http"
434
   javax.servlet.http",
435
 org.unitils,
436
 org.unitils.database,
437
 org.unitils.database.annotations,
438
 org.unitils.database.util,
439
 org.unitils.dbunit.annotation,
440
 org.unitils.spring.annotation
406 441
Bundle-Vendor: EDIT
407 442
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
408 443
Require-Bundle: org.eclipse.osgi,
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.api.application;
11

  
12
import javax.sql.DataSource;
13

  
14
import org.hibernate.SessionFactory;
15

  
16
import org.apache.log4j.Logger;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.stereotype.Component;
19
import org.springframework.transaction.PlatformTransactionManager;
20
import org.springframework.transaction.TransactionStatus;
21

  
22
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
24
import eu.etaxonomy.cdm.api.service.IDatabaseService;
25
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
26

  
27

  
28
/**
29
 * CDM Application Configuration class which manages the configuration for remoting
30
 * clients
31
 *
32
 */
33
@Component
34
public class CdmApplicationRemoteConfiguration extends CdmApplicationDefaultConfiguration {
35
	
36
	@SuppressWarnings("unused")
37
	private static final Logger logger = Logger.getLogger(CdmApplicationRemoteConfiguration.class);
38

  
39
	@Autowired
40
	IEditGeoService editGeoService;
41
	
42
	public CdmApplicationRemoteConfiguration() {
43
	}
44
	
45
    /* (non-Javadoc)
46
     * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#getTransactionManager()
47
     */
48
    @Override
49
    public PlatformTransactionManager getTransactionManager() throws UnsupportedOperationException {
50
		throw new UnsupportedOperationException("getTransactionManager is not implemented for CdmApplicationRemoteConfiguration");
51
	}
52

  
53

  
54
    /* (non-Javadoc)
55
     * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#startTransaction()
56
     */
57
    @Override
58
    public TransactionStatus startTransaction() throws UnsupportedOperationException {
59
		throw new UnsupportedOperationException("startTransaction is not implemented for CdmApplicationRemoteConfiguration");
60
	}
61

  
62

  
63
    /* (non-Javadoc)
64
     * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#startTransaction()
65
     */
66
    @Override
67
    public TransactionStatus startTransaction(Boolean readOnly) throws UnsupportedOperationException {
68
		throw new UnsupportedOperationException("startTransaction is not implemented for CdmApplicationRemoteConfiguration");
69
	}
70

  
71

  
72
    /* (non-Javadoc)
73
     * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#commitTransaction(org.springframework.transaction.TransactionStatus)
74
     */
75
    @Override
76
    public void commitTransaction(TransactionStatus txStatus) throws UnsupportedOperationException {
77
		throw new UnsupportedOperationException("commitTransaction is not implemented for CdmApplicationRemoteConfiguration");
78
	}
79
			
80
	/* (non-Javadoc)
81
	 * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#NewConversation()
82
	 */
83
	@Override
84
	public ConversationHolder NewConversation() {		
85
		return new ConversationHolderMock();
86
	}
87
	
88
	/**
89
	 * @return
90
	 */
91
	public IEditGeoService getEditGeoService() {
92
		return this.editGeoService;
93
	}
94
	
95
	/* (non-Javadoc)
96
	 * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#setDataSource(javax.sql.DataSource)
97
	 */
98
	@Override
99
	public void setDataSource(DataSource dataSource) {        		
100
    }
101
	
102
	/* (non-Javadoc)
103
	 * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#setTransactionManager(org.springframework.transaction.PlatformTransactionManager)
104
	 */
105
	@Override
106
	public void setTransactionManager(PlatformTransactionManager transactionManager) {        
107
    }
108
	
109
	/* (non-Javadoc)
110
	 * @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#setSessionFactory(org.hibernate.SessionFactory)
111
	 */
112
	@Override
113
    public void setSessionFactory(SessionFactory sessionFactory) {    	
114
    }
115
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10

  
11
package eu.etaxonomy.cdm.api.application;
12

  
13
import java.util.List;
14
import java.util.Properties;
15

  
16
import org.apache.log4j.Logger;
17
import org.hibernate.collection.internal.AbstractPersistentCollection;
18
import org.hibernate.proxy.AbstractLazyInitializer;
19
import org.springframework.beans.MutablePropertyValues;
20
import org.springframework.beans.factory.config.BeanDefinition;
21
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
22
import org.springframework.context.ApplicationListener;
23
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
24
import org.springframework.core.io.ClassPathResource;
25
import org.springframework.core.io.Resource;
26

  
27
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
28
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
29
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
30
import eu.etaxonomy.cdm.remote.ICdmRemoteSource;
31

  
32
/**
33
 * CDM Application Controller class for remoting clients
34
 * 
35
 * FIXME:Remoting extending {@link CdmApplicationController} is a temporary workaround.
36
 * The {@link CdmApplicationController} should be split into a CdmApplicationControllerBase
37
 * class with {@link CdmApplicationController} and this class as subclasses
38
 *
39
 */
40
public class CdmApplicationRemoteController  extends CdmApplicationController {
41
	
42
    private static final Logger logger = Logger.getLogger(CdmApplicationRemoteController.class);
43

  
44
    public static final Resource DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE = 
45
    		new ClassPathResource("/eu/etaxonomy/cdm/remotingApplicationContext.xml");
46
    private final Resource applicationContextResource;
47
    private final IProgressMonitor progressMonitor;
48
    
49
    /**
50
     * Creates new instance of CdmApplicationRemoteController
51
     * 
52
     * @param applicationContextResource
53
     * @param remoteSource
54
     * @param omitTermLoading
55
     * @param progressMonitor
56
     * @param listeners
57
     * @return
58
     */
59
    public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource, 
60
			ICdmRemoteSource remoteSource, 				
61
			boolean omitTermLoading, 
62
			IProgressMonitor progressMonitor, 
63
			List<ApplicationListener> listeners) {
64
    	return new CdmApplicationRemoteController(applicationContextResource, 
65
    			remoteSource, 
66
    			omitTermLoading, 
67
    			progressMonitor, 
68
				listeners);
69
    	
70
    }
71
    /**
72
     * Creates new instance of CdmApplicationRemoteController
73
     * 
74
     * @param applicationContextResource
75
     * @param remoteSource
76
     * @param omitTermLoading
77
     * @param progressMonitor
78
     * @param listeners
79
     * @return
80
     */
81
    public static CdmApplicationRemoteController NewInstance(ICdmRemoteSource remoteSource, 				
82
			boolean omitTermLoading, 
83
			IProgressMonitor progressMonitor, 
84
			List<ApplicationListener> listeners) {
85
    	
86
    	return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE, 
87
    			remoteSource, 
88
    			omitTermLoading, 
89
    			progressMonitor, 
90
				listeners);
91
    	
92
    }
93
    
94
	/**
95
	 * Constructs CdmApplicationRemoteController
96
	 * 
97
	 * @param applicationContextResource
98
	 * @param remoteSource
99
	 * @param omitTermLoading
100
	 * @param progressMonitor
101
	 * @param listeners
102
	 */
103
	private CdmApplicationRemoteController(Resource applicationContextResource, 
104
				ICdmRemoteSource remoteSource, 				
105
				boolean omitTermLoading, 
106
				IProgressMonitor progressMonitor, 
107
				List<ApplicationListener> listeners){
108
		logger.info("Start CdmApplicationRemoteController with remote source: " + remoteSource.getName());
109
        this.applicationContextResource = 
110
        		applicationContextResource != null ? applicationContextResource : DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE;
111
        this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor();
112

  
113
        setNewRemoteSource(remoteSource, omitTermLoading, listeners);
114
		
115
	}
116
	
117

  
118
    
119
    
120
    /**
121
     * Creates and starts a new spring application context
122
     * 
123
     * @param remoteSource object for connecting to an http-invoker server
124
     * @param omitTermLoading
125
     * @param listeners
126
     * @return
127
     */
128
    protected boolean setNewRemoteSource(ICdmRemoteSource remoteSource, 
129
    		boolean omitTermLoading, 
130
    		List<ApplicationListener> listeners){
131

  
132
        logger.info("Connecting to '" + remoteSource.getName() + "'");
133

  
134
        MonitoredGenericApplicationContext applicationContext =  new MonitoredGenericApplicationContext();
135
        int refreshTasks = 45;
136
        int nTasks = 5 + refreshTasks;
137

  
138
        progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks);
139

  
140
        progressMonitor.subTask("Registering remote source.");
141
        PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
142
        Properties properties = new Properties();
143
        properties.setProperty("remoteServer", remoteSource.getServer());
144
        properties.setProperty("remotePort", String.valueOf(remoteSource.getPort()));
145
        properties.setProperty("remoteContext", remoteSource.getContextPath());
146
        pspc.setProperties(properties);
147
        applicationContext.addBeanFactoryPostProcessor(pspc);
148
        progressMonitor.worked(1);
149

  
150
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext);
151
        //xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
152
        progressMonitor.subTask("Registering resources.");
153
        xmlReader.loadBeanDefinitions(applicationContextResource);
154
        progressMonitor.worked(1);
155

  
156
        //omitTerms
157
        if (omitTermLoading == true){
158
            String initializerName = "persistentTermInitializer";
159
            BeanDefinition beanDef = applicationContext.getBeanDefinition(initializerName);
160
            MutablePropertyValues values = beanDef.getPropertyValues();
161
            values.addPropertyValue("omit", omitTermLoading);
162
        }
163

  
164
        if (listeners != null){
165
            for(ApplicationListener listener : listeners){
166
                applicationContext.addApplicationListener(listener);
167
            }
168
        }
169

  
170

  
171
        applicationContext.refresh(new SubProgressMonitor(progressMonitor, refreshTasks));
172
        applicationContext.start();
173

  
174
        progressMonitor.subTask("Cleaning up.");
175
        setApplicationContext(applicationContext);
176
        progressMonitor.worked(1);
177

  
178
        progressMonitor.done();
179
        return true;
180
    }
181
    
182
    /* (non-Javadoc)
183
     * @see eu.etaxonomy.cdm.api.application.CdmApplicationController#init()
184
     */
185
    @Override
186
    protected void init(){    
187
        configuration = (ICdmApplicationConfiguration)applicationContext.getBean("cdmApplicationRemoteConfiguration");
188
		AbstractLazyInitializer.setConfiguration(this);
189
		AbstractPersistentCollection.setConfiguration(this);
190

  
191
    }
192

  
193
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java
1
package eu.etaxonomy.cdm.api.cache;
2

  
3
import java.util.UUID;
4

  
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.stereotype.Component;
7

  
8
import eu.etaxonomy.cdm.api.service.ITermService;
9
import eu.etaxonomy.cdm.model.common.CdmBase;
10

  
11
/**
12
 * Class which uses CDM services to cache cdm entities
13
 *
14
 * FIXME: Currently only handles terms entities. It would be
15
 *        interesting to have a generic method which finds the
16
 *        correct service to load / cache the entity.
17
 *
18
 * @author cmathew
19
 *
20
 * @param <T>
21
 */
22
@Component
23
public class CdmServiceCacher<T extends CdmBase> extends CdmCacher<T> {
24

  
25
	@Autowired
26
	ITermService termService;
27

  
28
	@Override
29
	protected T findByUuid(UUID uuid) {
30
		return (T)termService.findWithoutFlush(uuid);
31
	}
32

  
33
    /* (non-Javadoc)
34
     * @see eu.etaxonomy.cdm.api.cache.CdmCacher#setup()
35
     */
36
    @Override
37
    protected void setup() {
38
        // TODO Auto-generated method stub
39

  
40
    }
41

  
42
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java
1
package eu.etaxonomy.cdm.api.lazyloading;
2

  
3
import java.lang.reflect.Field;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10
import java.util.TreeMap;
11
import java.util.TreeSet;
12

  
13
import org.aspectj.lang.ProceedingJoinPoint;
14
import org.aspectj.lang.annotation.Around;
15
import org.aspectj.lang.annotation.Aspect;
16
import org.aspectj.lang.annotation.Pointcut;
17
import org.hibernate.collection.internal.PersistentList;
18
import org.hibernate.collection.internal.PersistentMap;
19
import org.hibernate.collection.internal.PersistentSet;
20
import org.hibernate.collection.internal.PersistentSortedMap;
21
import org.hibernate.collection.internal.PersistentSortedSet;
22
import org.hibernate.collection.spi.PersistentCollection;
23
import org.hibernate.proxy.LazyInitializer;
24
import org.springframework.beans.factory.annotation.Autowire;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.beans.factory.annotation.Configurable;
27
import org.springframework.stereotype.Component;
28

  
29
import eu.etaxonomy.cdm.api.service.ICommonService;
30
import eu.etaxonomy.cdm.model.common.CdmBase;
31
import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
32

  
33

  
34
@Aspect
35
@Component
36
@Configurable(autowire = Autowire.BY_TYPE)
37
public class CdmLazyLoader {
38

  
39

  
40
	private Set classes = new HashSet();
41
	
42
	public static boolean enableWeaving = true;
43
	private static Set<String> classesToIgnore = new HashSet<String>();
44
	
45
	
46
	@Autowired
47
	private ICommonService commonService;
48

  
49
	public CdmLazyLoader() {
50
		//classesToIgnore.add("eu.etaxonomy.cdm.model.common.TermVocabulary");
51
		//classesToIgnore.add("eu.etaxonomy.cdm.model.common.OrderedTermVocabulary");
52
		
53
	}
54
	
55
	/**
56
	 *  Point cut for the 'initialize' method of the AbstractLazyInitializer.
57
	 *  
58
	 */
59
	@Pointcut("execution(* org.hibernate.proxy.AbstractLazyInitializer.initialize())")
60
	public void possibleEntityLazyInitializationException() {
61
	}
62

  
63

  
64
	/**
65
	 *  'Around' advice for the initialization of CDM Entity Objects
66
	 *  
67
	 */
68
	@Around(value = "possibleEntityLazyInitializationException()")
69
	public Object preloadEntityOnDemand(ProceedingJoinPoint pjp) throws Throwable {		 
70
		if(enableWeaving) {
71
			LazyInitializer ll = (LazyInitializer)pjp.getTarget();		
72
			if(ll.isUninitialized()) {				
73
				int classid = ((Integer)ll.getIdentifier()).intValue();
74
				System.out.print("--> AspectJ Compile-Time Weaving " + ll.getEntityName() + " with id " + classid);
75
				Class clazz = (Class<? extends CdmBase>) Class.forName(ll.getEntityName());
76
				CdmBase cdmBase = CdmBase.deproxy(commonService.find(clazz,classid),clazz);
77
				ll.setImplementation(cdmBase);
78
				System.out.println("....Done");
79
			}
80
		}
81
		return pjp.proceed();		  	    	  
82
	}
83
	
84

  
85
	/**
86
	 *  Point cut for the 'initialize' method of the AbstractPersistentCollection.
87
	 *  
88
	 */
89
	@Pointcut("execution(protected final void org.hibernate.collection.internal.AbstractPersistentCollection.initialize(..))")
90
	public void possibleCollectionLazyInitializationException() {
91
	}
92
	
93
	/**
94
	 *  'Around' advice for the initialization of Collection objects
95
	 *  
96
	 */
97
	@Around(value = "possibleCollectionLazyInitializationException()")	
98
	public Object preloadCollectionOnDemand(ProceedingJoinPoint pjp) throws Throwable {		 
99
		if(enableWeaving) {
100
			PersistentCollection ps = (PersistentCollection) pjp.getTarget();
101
			if (ps.getOwner() != null && !classesToIgnore.contains(ps.getOwner().getClass().getName()) && !ps.wasInitialized() &&  !classes.contains(ps.getKey())) {
102
				System.out.print("--> AspectJCompile-Time Weaving " + ps.getRole());                
103
				classes.add(ps.getKey());
104
				try {
105
					String role = ps.getRole();
106
					String fieldName = role.substring(role.lastIndexOf(".") + 1);
107
					System.out.print(", field : " + fieldName);
108
					Object owner = ps.getOwner();
109

  
110
					PersistentCollection col = commonService.initializeCollection(ps); 
111
					ps.afterInitialize();
112

  
113
					Class<?> clazz = ps.getClass();
114
					if (clazz != null) {	
115
						CollectionField cf = getCollectionField(col);
116
						Field field = clazz.getDeclaredField(cf.getFieldName());
117
						field.setAccessible(true);
118
						field.set(ps, cf.getCollection());			       
119
					}		
120
				} catch (Exception ex) {
121
					ex.printStackTrace();
122
					System.out.println("Error in ReattachSessionAspect : " + ex.getMessage());
123
				} finally {
124
					classes.remove(ps.getKey());
125
					System.out.println("....Done");
126
				}	
127
			}
128
		} 
129
		return pjp.proceed();
130

  
131
	}
132
	
133
	private CollectionField getCollectionField(PersistentCollection pc) {
134
		if(pc != null) {
135
			if(pc instanceof PersistentSet) {
136
				return new CollectionField(new HashSet((Set)pc), "set");
137
			}
138
			if(pc instanceof PersistentSortedSet) {
139
				return new CollectionField(new TreeSet((Set)pc), "set");
140
			}
141
			if(pc instanceof PersistentList) {
142
				return new CollectionField(new ArrayList((List)pc), "list");
143
			}
144
			if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) {
145
				return new CollectionField(new HashMap((Map)pc), "map");
146
			}
147
			if(pc instanceof PersistentSortedMap) {
148
				return new CollectionField(new TreeMap((Map)pc), "map");
149
			}
150
		}
151
		return null;
152
	}
153
	
154
	private String getCollectionFieldName(PersistentCollection pc) {
155
		if(pc != null) {
156
			if(pc instanceof PersistentSet || pc instanceof PersistentSortedSet) {
157
				return "set";
158
			}			
159
			if(pc instanceof PersistentList) {
160
				return "list";
161
			}
162
			if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) {
163
				return "map";
164
			}
165
		}
166
		return null;
167
	}
168
	
169
	private class CollectionField {
170
		private Object col;
171
		private String fieldName;
172
		public CollectionField(Object col, String fieldName) {
173
			this.col = col;
174
			this.fieldName = fieldName;
175
		}
176
		
177
		public Object getCollection() {
178
			return this.col;
179
		}
180
		
181
		public String getFieldName() {
182
			return this.fieldName;
183
		}
184
	}
185

  
186
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmPersistentRemoteSource.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.remote;
11

  
12
import static eu.etaxonomy.cdm.common.XmlHelp.getBeansRoot;
13
import static eu.etaxonomy.cdm.common.XmlHelp.insertXmlBean;
14
import static eu.etaxonomy.cdm.common.XmlHelp.insertXmlValueProperty;
15
import static eu.etaxonomy.cdm.common.XmlHelp.saveToXml;
16

  
17
import java.util.ArrayList;
18
import java.util.Enumeration;
19
import java.util.List;
20
import java.util.Properties;
21

  
22
import org.apache.log4j.Logger;
23
import org.jdom.Attribute;
24
import org.jdom.Element;
25

  
26
import eu.etaxonomy.cdm.common.CdmUtils;
27
import eu.etaxonomy.cdm.common.XmlHelp;
28
import eu.etaxonomy.cdm.config.CdmPersistentSourceUtils;
29
import eu.etaxonomy.cdm.config.CdmPersistentXMLSource;
30
import eu.etaxonomy.cdm.config.CdmSourceException;
31
import eu.etaxonomy.cdm.config.ICdmPersistentSource;
32
import eu.etaxonomy.cdm.config.CdmPersistentXMLSource.CdmSourceProperties;
33
import eu.etaxonomy.cdm.database.CdmDataSource;
34
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
35
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
36
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
37
import eu.etaxonomy.cdm.database.ICdmDataSource;
38
import eu.etaxonomy.cdm.database.types.IDatabaseType;
39
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
40

  
41
/**
42
 * Class representing a CDM remote source which can be persisted to a source config file
43
 *
44
 */
45
public class CdmPersistentRemoteSource extends CdmRemoteSourceBase implements ICdmPersistentSource{
46
	private static final Logger logger = Logger.getLogger(CdmPersistentRemoteSource.class);
47
	
48
	public static final String REMOTESOURCE_BEAN_POSTFIX = "RemoteSource";
49
	private String beanName;
50
	private Properties cdmSourceProperties;
51
	private List<Attribute> cdmSourceAttributes;
52
	
53
	/**
54
	 * Creates a new instance of CdmPersistentRemoteSource
55
	 * 
56
	 * @param name
57
	 * @param server
58
	 * @param port
59
	 * @param contextPath
60
	 * @param nomenclaturalCode
61
	 * @return
62
	 * @throws CdmRemoteSourceException 
63
	 */
64
	public static CdmPersistentRemoteSource NewInstance(String remoteSource) throws CdmRemoteSourceException {
65
		if(exists(remoteSource)) {
66
			return new CdmPersistentRemoteSource(remoteSource);
67
		} else {
68
			throw new CdmRemoteSourceException("Remote source '" + remoteSource + "' does not exist in sources setting file");
69
		}
70
		
71
	}
72
	
73
	/**S
74
	 * Creates a new CdmPersistentRemoteSource
75
	 * 
76
	 * @param name
77
	 * @param server
78
	 * @param port
79
	 * @param contextPath
80
	 * @param nomenclaturalCode
81
	 * @throws CdmRemoteSourceException 
82
	 */
83
	private CdmPersistentRemoteSource(String remoteSource) throws CdmRemoteSourceException { 
84
		
85
		CdmPersistentXMLSource cdmPersistentXMLSource = CdmPersistentXMLSource.NewInstance(remoteSource, REMOTESOURCE_BEAN_POSTFIX);
86
		if(cdmPersistentXMLSource.getElement() != null) {
87
			beanName = cdmPersistentXMLSource.getBeanName();
88
			// properties from the persistent xml file 
89
			cdmSourceProperties = cdmPersistentXMLSource.getCdmSourceProperties();
90
			cdmSourceAttributes = cdmPersistentXMLSource.getCdmSourceAttributes();
91
			checkProperties(cdmSourceProperties);
92
		} else {
93
			throw new CdmRemoteSourceException("Remote source '" + remoteSource + "' does not exist in settings file");
94
		}		
95
		initDatabaseConnection();
96
	}
97
	
98
	private static void checkProperties(Properties cdmSourceProperties) throws CdmRemoteSourceException {
99
		if(!cdmSourceProperties.containsKey(CdmSourceProperties.SERVER.toString())) {
100
			throw new CdmRemoteSourceException("Could not initialise remote source. Required property '" + CdmSourceProperties.SERVER.toString() + "' is missing");			
101
		}
102
		String port = (String)cdmSourceProperties.get(CdmSourceProperties.PORT.toString());
103
		if(port == null || port.isEmpty()) {
104
			throw new CdmRemoteSourceException("Could not initialise remote source. Required property '" + CdmSourceProperties.SERVER.toString() + "' is missing");			
105
		}	
106
		if(!cdmSourceProperties.containsKey(CdmSourceProperties.CONTEXTPATH.toString())) {
107
			throw new CdmRemoteSourceException("Could not initialise remote source. Required property '" + CdmSourceProperties.SERVER.toString() + "' is missing");			
108
		}	
109
		// default NomenclaturalCode is always ICNAFP
110
		if(!cdmSourceProperties.containsKey(CdmSourceProperties.NOMENCLATURAL_CODE.toString())) {				
111
			cdmSourceProperties.put(CdmSourceProperties.NOMENCLATURAL_CODE.toString(), NomenclaturalCode.ICNAFP.name());
112
		}			
113
	}
114

  
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.cdm.config.ICdmPersistentSource#getBeanName()
117
	 */
118
	@Override
119
	public String getBeanName() {
120
		return beanName;
121
	}
122
	
123
	@Override
124
	public String getServer() {
125
		return cdmSourceProperties.getProperty(CdmSourceProperties.SERVER.toString());
126
	}
127
	
128
	@Override
129
	public int getPort() {
130
		String port = CdmUtils.Nz(cdmSourceProperties.getProperty(CdmSourceProperties.PORT.toString()));
131
		if (port == null || "".equals(port)){
132
			return -1;
133
		}else{
134
			//TODO exception if non integer
135
			return Integer.valueOf(port);
136
		}
137
	}
138
	
139
	@Override
140
	public String getContextPath() {
141
		return cdmSourceProperties.getProperty(CdmSourceProperties.CONTEXTPATH.toString());
142
	}
143
	
144
	@Override
145
	public NomenclaturalCode getNomenclaturalCode() {
146
		return NomenclaturalCode.fromString(cdmSourceProperties.getProperty(CdmSourceProperties.NOMENCLATURAL_CODE.toString()));
147
	}
148
	
149
	public static CdmPersistentRemoteSource save(String strRemoteSourceName, ICdmRemoteSource remoteSource) throws CdmRemoteSourceException {
150
		Properties cdmSourceProperties = new Properties();
151
		cdmSourceProperties.put(CdmSourceProperties.SERVER.toString(), remoteSource.getServer());
152
		cdmSourceProperties.put(CdmSourceProperties.PORT.toString(), String.valueOf(remoteSource.getPort()));
153
		cdmSourceProperties.put(CdmSourceProperties.CONTEXTPATH.toString(), remoteSource.getContextPath());
154
		cdmSourceProperties.put(CdmSourceProperties.NOMENCLATURAL_CODE.toString(), remoteSource.getNomenclaturalCode().name());
155
		checkProperties(cdmSourceProperties);
156
		return save(strRemoteSourceName, cdmSourceProperties);
157
	}
158
	
159
	private static CdmPersistentRemoteSource save(String strRemoteSourceName,Properties cdmSourceProperties) throws CdmRemoteSourceException {
160

  
161
		//root
162
		Element root = getBeansRoot(CdmPersistentSourceUtils.getCdmSourceInputStream());
163
		if (root == null){
164
			return null;
165
		}
166
		//bean
167
		Element bean = XmlHelp.getFirstAttributedChild(root, "bean", "id", CdmPersistentSourceUtils.getBeanName(strRemoteSourceName, REMOTESOURCE_BEAN_POSTFIX));
168
		if (bean != null){
169
			bean.detach();  //delete old version if necessary
170
		}
171
		bean = insertXmlBean(root, CdmPersistentSourceUtils.getBeanName(strRemoteSourceName, REMOTESOURCE_BEAN_POSTFIX), CdmPersistentRemoteSource.class.getName());
172

  
173

  
174
		Properties props = cdmSourceProperties;
175
		Enumeration e = props.propertyNames();
176

  
177
		while (e.hasMoreElements()) {
178
			String key = (String) e.nextElement();
179
			insertXmlValueProperty(bean, key, props.getProperty(key));
180
		}
181

  
182
		//save
183
		saveToXml(root.getDocument(), 
184
				CdmPersistentSourceUtils.getResourceDirectory(), 
185
				CdmPersistentXMLSource.CDMSOURCE_FILE_NAME, 
186
				XmlHelp.prettyFormat );
187

  
188
		return NewInstance(strRemoteSourceName) ;
189

  
190
	}
191
	
192
	/**
193
	 * @param strDataSourceName
194
	 * @param dataSource
195
	 * @param code 
196
	 * @return
197
	 * 			the updated dataSource, null if not succesful
198
	 */
199
	public static CdmPersistentRemoteSource update(String strRemoteSourceName,
200
			ICdmRemoteSource remoteSource) throws CdmRemoteSourceException {
201
		CdmPersistentSourceUtils.delete(CdmPersistentSourceUtils.getBeanName(strRemoteSourceName,REMOTESOURCE_BEAN_POSTFIX));
202
		return save(strRemoteSourceName, remoteSource);
203
	}
204
	
205
	/**
206
	 * Tests existing of the datsource in the according config  file.
207
	 * @return true if a datasource with the given name exists in the according datasource config file.
208
	 */
209
	public static boolean exists(String strRemoteSourceName){
210
		Element bean = CdmPersistentSourceUtils.getCdmSourceBeanXml(strRemoteSourceName, REMOTESOURCE_BEAN_POSTFIX);
211
		return (bean != null);
212
	}
213
	
214
	/**
215
	 * Returns a list of all datasources stored in the datasource config file
216
	 * @return all existing data sources
217
	 * @throws CdmRemoteSourceException 
218
	 */
219
	@SuppressWarnings("unchecked")
220
	static public List<CdmPersistentRemoteSource> getAllRemoteSources() throws CdmRemoteSourceException{
221
		List<CdmPersistentRemoteSource> remoteSources = new ArrayList<CdmPersistentRemoteSource>();
222
		
223
		Element root = getBeansRoot(CdmPersistentSourceUtils.getCdmSourceInputStream());
224
		if (root == null){
225
			return null;
226
		}else{
227
	    	List<Element> lsChildren  = root.getChildren("bean", root.getNamespace());
228
	    	
229
	    	for (Element elBean : lsChildren){
230
	    		String strId = elBean.getAttributeValue("id");
231
	    		if (strId != null && strId.endsWith(REMOTESOURCE_BEAN_POSTFIX)){
232
	    			strId = strId.replace(REMOTESOURCE_BEAN_POSTFIX, "");
233
	    			remoteSources.add(new CdmPersistentRemoteSource(strId));
234
	    		}
235
	    	}
236
		}
237
		return remoteSources;
238
	}
239
	
240
	@Override
241
	public String toString(){
242
		if (getName() != null){
243
			return getName();
244
		}else{
245
			return null;
246
		}
247
	}
248

  
249
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSource.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

  
11
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
12

  
13
/**
14
 * Class representing a CDM remote source 
15
 *
16
 */
17
public class CdmRemoteSource extends CdmRemoteSourceBase {
18
	
19
	/**
20
	 * Creates a new instance of CdmRemoteSource
21
	 * 
22
	 * @param name
23
	 * @param server
24
	 * @param port
25
	 * @param contextPath
26
	 * @param nomenclaturalCode
27
	 * @return
28
	 */
29
	public static CdmRemoteSource NewInstance() {
30
		return new CdmRemoteSource(DEFAULT_NAME, DEFAULT_SERVER, DEFAULT_PORT, DEFAULT_CONTEXT_PATH, DEFAULT_NOMENCLATURAL_CODE);
31
	}
32
	
33
	/**
34
	 * Creates a new instance of CdmRemoteSource
35
	 * 
36
	 * @param name
37
	 * @param server
38
	 * @param port
39
	 * @param contextPath
40
	 * @param nomenclaturalCode
41
	 * @return
42
	 */
43
	public static CdmRemoteSource NewInstance(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) {
44
		return new CdmRemoteSource(name, server, port, contextPath, nomenclaturalCode);
45
	}
46
	
47
	/**
48
	 * Creates a new CdmRemoteSource
49
	 * 
50
	 * @param name
51
	 * @param server
52
	 * @param port
53
	 * @param contextPath
54
	 * @param nomenclaturalCode
55
	 */
56
	private CdmRemoteSource(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) { 
57
		super(name, server, port, contextPath, nomenclaturalCode);
58
		
59
	}
60

  
61

  
62
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceBase.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

  
11
import java.util.Map;
12

  
13
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
14

  
15
import eu.etaxonomy.cdm.api.service.IDatabaseService;
16
import eu.etaxonomy.cdm.config.CdmSource;
17
import eu.etaxonomy.cdm.config.CdmSourceException;
18
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
19
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
20
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
21

  
22
/**
23
 * Base class representing a CDM remote source. 
24
 * This class handles all the configuration relating to the remoting aspect of
25
 * a CDM source.
26
 *
27
 */
28
public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
29

  
30
	protected static final String DEFAULT_NAME = "default";
31
	protected static final String DEFAULT_SERVER = "127.0.0.1";
32
	protected static final int DEFAULT_PORT = 8080;
33
	protected static final String DEFAULT_CONTEXT_PATH = "";
34
	protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE = NomenclaturalCode.ICNAFP;
35
	private String contextPath;
36
	private String baseUrl;
37
	
38
	private IDatabaseService databaseService;
39
	
40
	/**
41
	 * Constructs a CdmRemoteSourceBase object with default values.
42
	 * 
43
	 */
44
	protected CdmRemoteSourceBase() {
45
		setName(DEFAULT_NAME);
46
		setServer(DEFAULT_SERVER);
47
		setPort(DEFAULT_PORT);
48
		setContextPath(DEFAULT_CONTEXT_PATH);
49
		setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE);
50
	}
51
	
52
	/**
53
	 * Constructs a CdmRemoteSourceBase
54
	 * 
55
	 * @param name
56
	 * @param server
57
	 * @param port
58
	 * @param contextPath
59
	 * @param nomenclaturalCode
60
	 */
61
	protected CdmRemoteSourceBase(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) {
62
		setName(name);
63
		setServer(server);
64
		setPort(port);
65
		setContextPath(contextPath);
66
		setNomenclaturalCode(nomenclaturalCode);			
67
		initDatabaseConnection();
68
	}
69
	
70
	protected void initDatabaseConnection() {
71
		if(getContextPath() == null || getContextPath().equals("")) {
72
			setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()));
73
		} else {
74
			setBaseUrl("http://" + getServer()  + ":" + String.valueOf(getPort()) + "/" + getContextPath());
75
		}	
76
		// the database service needs to be initialised (before the spring
77
		// application context initialsation) since it is required to 
78
		// to make queries related to the source database
79
	    HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
80
	    proxy.setServiceInterface(IDatabaseService.class);
81
	    proxy.setServiceUrl(baseUrl + "/remoting/database.service");
82
	    proxy.afterPropertiesSet();
83
	    databaseService = (IDatabaseService) proxy.getObject();
84

  
85
	}
86
	
87
	/* (non-Javadoc)
88
	 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
89
	 */
90
	@Override
91
	public String getBaseUrl() {
92
		return baseUrl;
93
	}
94

  
95
	/**
96
	 * Sets the base url for the http-invoker services as listed in 
97
	 * httpInvokerServicesClients.xml.
98
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the 
99
	 * base url would be 'http://127.0.0.1:8080/col'
100
	 * 
101
	 * @param baseUrl
102
	 */
103
	public void setBaseUrl(String baseUrl) {
104
		this.baseUrl = baseUrl;
105
	}
106

  
107
	/* (non-Javadoc)
108
	 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
109
	 */
110
	@Override
111
	public String getContextPath() {
112
		return contextPath;
113
	}
114

  
115
	/**
116
	 * Sets the context path.
117
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the 
118
	 * context path would be 'col'
119
	 * 
120
	 * @param contextPath
121
	 */
122
	public void setContextPath(String contextPath) {
123
		this.contextPath = contextPath;
124
	}
125

  
126
	/* (non-Javadoc)
127
	 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
128
	 */
129
	@Override
130
	public String getDbSchemaVersion() throws CdmSourceException {
131
		return databaseService.getDbSchemaVersion();
132

  
133
	}
134

  
135
	/* (non-Javadoc)
136
	 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
137
	 */
138
	@Override
139
	public boolean isDbEmpty() throws CdmSourceException {
140
		return databaseService.isDbEmpty();
141

  
142
	}
143

  
144
	/* (non-Javadoc)
145
	 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
146
	 */
147
	@Override
148
	public boolean checkConnection() throws CdmSourceException {
149
		// assuming that database service works implies 
150
		// the connection is up
151
		// if no exception is thrown then we assume that the 
152
		// connection is up
153
		// FIXME:Remoting is this really correct?
154
		databaseService.getDbSchemaVersion();
155

  
156
		return true;
157
	}
158

  
159
	/* (non-Javadoc)
160
	 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
161
	 */
162
	@Override
163
	public String getConnectionMessage() {
164
		return "Conncting to Remote CDM Server " + getName();
165
	}
166

  
167
		
168
	@Override
169
	public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
170
		return databaseService.getCdmMetadataMap();
171
	}
172

  
173

  
174
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceException.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.remote;
5

  
6
/**
7
 * 
8
 *
9
 */
10
public class CdmRemoteSourceException extends Exception {
11
	
12
	public CdmRemoteSourceException(String message) {
13
		super(message);
14
	}
15

  
16
	public CdmRemoteSourceException(Exception e) {
17
		super(e);
18
	}
19
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/ICdmRemoteSource.java
1
/**
2
* Copyright (C) 2014 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

  
11
import eu.etaxonomy.cdm.config.ICdmSource;
12

  
13
/**
14
 * Interface representing a CDM remote source
15
 *
16
 */
17
public interface ICdmRemoteSource extends ICdmSource {
18
	
19
	/**
20
	 * Gets the context path.
21
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the 
22
	 * context path would be 'col'
23
	 */
24
	public String getContextPath();
25
	
26
	/**
27
	 * Gets the base url for the http-invoker services as listed in 
28
	 * httpInvokerServicesClients.xml.
29
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the 
30
	 * base url would be 'http://127.0.0.1:8080/col'
31
	 */
32
	public String getBaseUrl();	
33

  
34
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java
1

  
2

  
3
/*
4
 * Hibernate, Relational Persistence for Idiomatic Java
5
 *
6
 * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
7
 * indicated by the @author tags or express copyright attribution
8
 * statements applied by the authors.  All third-party contributions are
9
 * distributed under license by Red Hat Inc.
10
 *
11
 * This copyrighted material is made available to anyone wishing to use, modify,
12
 * copy, or redistribute it subject to the terms and conditions of the GNU
13
 * Lesser General Public License, as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
18
 * for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21
 * along with this distribution; if not, write to:
22
 * Free Software Foundation, Inc.
23
 * 51 Franklin Street, Fifth Floor
24
 * Boston, MA  02110-1301  USA
25
 */
26
package org.hibernate.collection.internal;
27

  
28
import java.io.Serializable;
29
import java.lang.reflect.Field;
30
import java.util.ArrayList;
31
import java.util.Collection;
32
import java.util.Collections;
33
import java.util.HashMap;
34
import java.util.HashSet;
35
import java.util.Iterator;
36
import java.util.List;
37
import java.util.ListIterator;
38
import java.util.Map;
39
import java.util.Set;
40
import java.util.TreeMap;
41
import java.util.TreeSet;
42

  
43
import javax.naming.NamingException;
44

  
45
import org.hibernate.AssertionFailure;
46
import org.hibernate.HibernateException;
47
import org.hibernate.LazyInitializationException;
48
import org.hibernate.Session;
49
import org.hibernate.collection.spi.PersistentCollection;
50
import org.hibernate.engine.internal.ForeignKeys;
51
import org.hibernate.engine.spi.CollectionEntry;
52
import org.hibernate.engine.spi.EntityEntry;
53
import org.hibernate.engine.spi.SessionFactoryImplementor;
54
import org.hibernate.engine.spi.SessionImplementor;
55
import org.hibernate.engine.spi.Status;
56
import org.hibernate.engine.spi.TypedValue;
57
import org.hibernate.internal.SessionFactoryRegistry;
58
import org.hibernate.internal.util.MarkerObject;
59
import org.hibernate.internal.util.collections.EmptyIterator;
60
import org.hibernate.internal.util.collections.IdentitySet;
61
import org.hibernate.persister.collection.CollectionPersister;
62
import org.hibernate.persister.entity.EntityPersister;
63
import org.hibernate.pretty.MessageHelper;
64
import org.hibernate.type.Type;
65
import org.jboss.logging.Logger;
66

  
67
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
68
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
69
import eu.etaxonomy.cdm.api.service.ICommonService;
70
import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
71

  
72
/**
73
 * Base class implementing {@link org.hibernate.collection.spi.PersistentCollection}
74
 *
75
 * @author Gavin King
76
 */
77
public abstract class AbstractPersistentCollection implements Serializable, PersistentCollection {
78
	private static final Logger log = Logger.getLogger( AbstractPersistentCollection.class );
79

  
80
	private static final long serialVersionUID = -7238232378593030571L;
81
	
82
	private transient SessionImplementor session;
83
	private boolean initialized;
84
	private transient List<DelayedOperation> operationQueue;
85
	private transient boolean directlyAccessible;
86
	private transient boolean initializing;
87
	private Object owner;
88
	private int cachedSize = -1;
89

  
90
	private String role;
91
	private Serializable key;
92
	// collections detect changes made via their public interface and mark
93
	// themselves as dirty as a performance optimization
94
	private boolean dirty;
95
	private Serializable storedSnapshot;
96

  
97
	private String sessionFactoryUuid;
98
	private boolean specjLazyLoad = false;
99

  
100
	public final String getRole() {
101
		return role;
102
	}
103

  
104
	public final Serializable getKey() {
105
		return key;
106
	}
107

  
108
	public final boolean isUnreferenced() {
109
		return role == null;
110
	}
111

  
112
	public final boolean isDirty() {
113
		return dirty;
114
	}
115

  
116
	public final void clearDirty() {
117
		dirty = false;
118
	}
119

  
120
	public final void dirty() {
121
		dirty = true;
122
	}
123

  
124
	public final Serializable getStoredSnapshot() {
125
		return storedSnapshot;
126
	}
127

  
128
	//Careful: these methods do not initialize the collection.
129

  
130
	/**
131
	 * Is the initialized collection empty?
132
	 */
133
	public abstract boolean empty();
134

  
135
	/**
136
	 * Called by any read-only method of the collection interface
137
	 */
138
	protected final void read() {
139
		initialize( false );
140
	}
141

  
142
	/**
143
	 * Called by the {@link Collection#size} method
144
	 */
145
	@SuppressWarnings({"JavaDoc"})
146
	protected boolean readSize() {
147
		if ( !initialized ) {
148
			if ( cachedSize != -1 && !hasQueuedOperations() ) {
149
				return true;
150
			}
151
			else {
152
				// In remoting we are sure that session is null
153
				// both when using property paths and switching off conversations
154
				if(session == null && remoting) {				
155
					log.info("--> readSize, of " + getRole() + " with key " + getKey());
156
					read();								
157
				} else {
158
					boolean isExtraLazy = withTemporarySessionIfNeeded(
159
							new LazyInitializationWork<Boolean>() {
160
								@Override
161
								public Boolean doWork() {
162
									CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
163

  
164
									if ( entry != null ) {
165
										CollectionPersister persister = entry.getLoadedPersister();
166
										if ( persister.isExtraLazy() ) {
167
											if ( hasQueuedOperations() ) {
168
												session.flush();
169
											}
170
											cachedSize = persister.getSize( entry.getLoadedKey(), session );
171
											return true;
172
										}
173
										else {
174
											read();
175
										}
176
									}
177
									else{
178
										throwLazyInitializationExceptionIfNotConnected();
179
									}
180
									return false;
181
								}
182
							}
183
							);
184
					if ( isExtraLazy ) {
185
						return true;
186
					}
187
				}
188
			}
189
		}
190
		return false;
191
	}
192

  
193
	public static interface LazyInitializationWork<T> {
194
		public T doWork();
195
	}
196

  
197
	private <T> T withTemporarySessionIfNeeded(LazyInitializationWork<T> lazyInitializationWork) {
198
		SessionImplementor originalSession = null;
199
		boolean isTempSession = false;
200
		boolean isJTA = false;
201

  
202
		if ( session == null ) {
203
			if ( specjLazyLoad ) {
204
				session = openTemporarySessionForLoading();
205
				isTempSession = true;
206
			}
207
			else {
208
				throwLazyInitializationException( "could not initialize proxy - no Session" );
209
			}
210
		}
211
		else if ( !session.isOpen() ) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff