Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2cde239855e4c831a78d5416eb42c1b968ef241b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2008, 2016 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.connection;

import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapterXXXX;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitTransactionType;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkConnection;
import org.eclipse.jpt.jpa.eclipselink.ui.JptJpaEclipseLinkUiMessages;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;

/**
 *  ConnectionPropertiesComposite
 */
public class EclipseLinkConnectionPropertiesComposite<T extends EclipseLinkConnection> 
	extends Pane<T>
{
	public EclipseLinkConnectionPropertiesComposite(
					Pane<T> parentComposite, 
					Composite parent) {

		super(parentComposite, parent);
	}

	public String getHelpID() {
		return JpaHelpContextIds.PERSISTENCE_XML_CONNECTION;
	}

	@Override
	protected Composite addComposite(Composite container) {
		return addTitledGroup(
			container,
			JptJpaEclipseLinkUiMessages.CONNECTION_PROPERTIES_COMPOSITE_DATABASE_GROUP_BOX,
			2,
			null
		);
	}

	@Override
	protected void initializeLayout(Composite container) {
		// JTA Data Source
		PropertyValueModel<Boolean> jtaEnabled = this.buildJTADataSourceModel();
		addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CONNECTION_TAB_JTA_DATA_SOURCE_LABEL, jtaEnabled);
		addText(container, this.buildJtaDataSourceModel(), this.getHelpID(), jtaEnabled);

		// Non-JTA Data Source
		PropertyValueModel<Boolean> nonJtaEnabled = this.buildNonJTADataSourceModel();
		addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CONNECTION_TAB_NON_JTA_DATA_SOURCE_LABEL, nonJtaEnabled);
		addText(container, buildNonJtaDataSourceModel(), this.getHelpID(), nonJtaEnabled);


		PropertyValueModel<Boolean> enabledModel = buildTransacationTypeResourceLocalEnabledModel();

		// EclipseLink Connection Pool
		EclipseLinkJdbcPropertiesComposite<T> jdbcComposite = new EclipseLinkJdbcPropertiesComposite<>(this, container, enabledModel);
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		jdbcComposite.getControl().setLayoutData(gridData);

		// Exclusive Connections
		EclipseLinkJdbcExclusiveConnectionsPropertiesComposite<T> exclusiveConnectionsComposite = new EclipseLinkJdbcExclusiveConnectionsPropertiesComposite<>(this, container, enabledModel);
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		exclusiveConnectionsComposite.getControl().setLayoutData(gridData);
	}



	private PropertyValueModel<Boolean> buildTransacationTypeResourceLocalEnabledModel() {
		return PropertyValueModelTools.valueIsIdentical(this.buildTransactionTypeModel(), PersistenceUnitTransactionType.RESOURCE_LOCAL);
	}
	
	private ModifiablePropertyValueModel<String> buildJtaDataSourceModel() {
		return new PropertyAspectAdapterXXXX<PersistenceUnit, String>(buildPersistenceUnitModel(), PersistenceUnit.JTA_DATA_SOURCE_PROPERTY) {
			@Override
			protected String buildValue_() {
				return this.subject.getJtaDataSource();
			}

			@Override
			protected void setValue_(String value) {
				if (value.length() == 0) {
					value = null;
				}
				this.subject.setJtaDataSource(value);
			}
		};
	}

	private PropertyValueModel<Boolean> buildJTADataSourceModel() {
		return PropertyValueModelTools.valueAffirms_(this.buildTransactionTypeModel(), TRANSACTION_TYPE_IS_JTA_PREDICATE);
	}

	private static final Predicate<PersistenceUnitTransactionType> TRANSACTION_TYPE_IS_JTA_PREDICATE = new TransactionTypeIsJTAPredicate();
	static class TransactionTypeIsJTAPredicate
		extends PredicateAdapter<PersistenceUnitTransactionType>
	{
		@Override
		public boolean evaluate(PersistenceUnitTransactionType type) {
			return (type == null) || (type == PersistenceUnitTransactionType.JTA);
		}
	}

	private ModifiablePropertyValueModel<String> buildNonJtaDataSourceModel() {
		return new PropertyAspectAdapterXXXX<PersistenceUnit, String>(buildPersistenceUnitModel(), PersistenceUnit.NON_JTA_DATA_SOURCE_PROPERTY) {
			@Override
			protected String buildValue_() {
				return this.subject.getNonJtaDataSource();
			}

			@Override
			protected void setValue_(String value) {
				if (value.length() == 0) {
					value = null;
				}
				this.subject.setNonJtaDataSource(value);
			}
		};
	}

	private PropertyValueModel<Boolean> buildNonJTADataSourceModel() {
		return PropertyValueModelTools.valueIsIdentical_(this.buildTransactionTypeModel(), PersistenceUnitTransactionType.RESOURCE_LOCAL);
	}

	private PropertyValueModel<PersistenceUnitTransactionType> buildTransactionTypeModel() {
		return new PropertyAspectAdapterXXXX<PersistenceUnit, PersistenceUnitTransactionType>(
				buildPersistenceUnitModel(), 
				PersistenceUnit.SPECIFIED_TRANSACTION_TYPE_PROPERTY, 
				PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY) {
			@Override
			protected PersistenceUnitTransactionType buildValue_() {
				return this.subject.getTransactionType();
			}
		};
	}

	private PropertyValueModel<PersistenceUnit> buildPersistenceUnitModel() {
		return new PropertyAspectAdapterXXXX<EclipseLinkConnection, PersistenceUnit>(getSubjectHolder()) {
			@Override
			protected PersistenceUnit buildValue_() {
				return this.subject.getPersistenceUnit();
			}
		};
	}
}

Back to the top