This is an automated email from the ASF dual-hosted git repository. alien11689 pushed a commit to branch ARIES-2171-use-blueprint-maven-plugin-in-samples in repository https://gitbox.apache.org/repos/asf/aries.git
commit b24b22f46153960516bdb754dd4d782a7f1e0d99 Author: Dominik Przybysz <[email protected]> AuthorDate: Sun Mar 16 11:35:05 2025 +0100 ARIES-2171: Use blueprint-maven-plugin in samples (idverifier untouched) --- .../ariestrader/modules/ariestrader-core/pom.xml | 13 ++ .../ariestrader/core/TradeDBManagerImpl.java | 4 + .../ariestrader/core/TradeServicesManagerImpl.java | 136 +++++------ .../resources/OSGI-INF/blueprint/blueprint.xml | 41 ---- .../resources/OSGI-INF/blueprint/blueprint.xml | 17 +- .../modules/ariestrader-persist-jdbc/pom.xml | 13 ++ .../ariestrader/persist/jdbc/TradeJdbc.java | 30 ++- .../resources/OSGI-INF/blueprint/blueprint.xml | 35 --- .../modules/ariestrader-persist-jpa-am/pom.xml | 20 ++ .../ariestrader/persist/jpa/am/TradeJpaAm.java | 21 +- .../resources/OSGI-INF/blueprint/blueprint.xml | 36 --- .../modules/ariestrader-persist-jpa-cm/pom.xml | 28 +++ .../ariestrader/persist/jpa/cm/TradeJpaCm.java | 248 ++++++++++----------- .../resources/OSGI-INF/blueprint/blueprint.xml | 38 ---- samples/blog/blog-biz/pom.xml | 19 ++ .../samples/blog/biz/BlogAuthorManagerImpl.java | 36 +-- .../samples/blog/biz/BlogCommentManagerImpl.java | 10 +- .../samples/blog/biz/BlogEntryManagerImpl.java | 5 +- .../samples/blog/biz/BloggingServiceImpl.java | 23 +- .../resources/OSGI-INF/blueprint/blueprint.xml | 47 ---- samples/blog/blog-persistence-jdbc/pom.xml | 24 +- .../jdbc/BlogPersistenceServiceImpl.java | 104 +++++---- .../blog/persistence/jdbc/DatasourceProducer.java} | 31 +-- .../resources/OSGI-INF/blueprint/blueprint.xml | 34 --- samples/blog/blog-persistence-jpa/pom.xml | 29 ++- .../jpa/BlogPersistenceServiceImpl.java | 78 ++++--- .../resources/OSGI-INF/blueprint/blueprint.xml | 34 --- .../helloworld/api/HelloWorldService.java | 10 +- .../blueprint/helloworld/helloworld-client/pom.xml | 15 ++ .../helloworld/client/HelloWorldClient.java | 37 +-- .../main/resources/OSGI-INF/blueprint/config.xml | 27 --- .../blueprint/helloworld/helloworld-server/pom.xml | 15 ++ .../helloworld/server/HelloWorldServiceImpl.java | 25 ++- .../main/resources/OSGI-INF/blueprint/config.xml | 27 --- .../blueprint-sample-idverifier-client.xml | 68 ------ samples/pom.xml | 58 +++++ 36 files changed, 662 insertions(+), 774 deletions(-) diff --git a/samples/ariestrader/modules/ariestrader-core/pom.xml b/samples/ariestrader/modules/ariestrader-core/pom.xml index 78a4071f8..27097a2a0 100644 --- a/samples/ariestrader/modules/ariestrader-core/pom.xml +++ b/samples/ariestrader/modules/ariestrader-core/pom.xml @@ -41,6 +41,15 @@ <artifactId>org.apache.aries.samples.ariestrader.api</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + </dependency> </dependencies> <build> @@ -56,6 +65,10 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> </plugins> </build> </project> diff --git a/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java b/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java index 6c9a16323..83ee8d08e 100644 --- a/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java +++ b/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java @@ -18,6 +18,8 @@ package org.apache.aries.samples.ariestrader.core; import javax.sql.DataSource; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.samples.ariestrader.api.persistence.RunStatsDataBean; import org.apache.aries.samples.ariestrader.util.Log; import org.apache.aries.samples.ariestrader.util.MDBStats; @@ -42,6 +44,8 @@ import java.sql.Statement; * org.apache.aries.samples.ariestrader.api.TradeDBManager */ +@Service +@Bean(initMethod = "init", destroyMethod = "destroy") public class TradeDBManagerImpl implements TradeDBManager { private DataSource dataSource = null; diff --git a/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java b/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java index 44e0d05e2..169c3bf79 100644 --- a/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java +++ b/samples/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java @@ -1,26 +1,27 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.aries.samples.ariestrader.core; import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import java.util.Map; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.referencelistener.ReferenceListener; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.samples.ariestrader.api.persistence.MarketSummaryDataBean; import org.apache.aries.samples.ariestrader.util.Log; import org.apache.aries.samples.ariestrader.util.TradeConfig; @@ -32,32 +33,33 @@ import org.apache.aries.samples.ariestrader.api.TradeServices; * TradeServicesManagerImpl coordinates access to the currently * selected TradeServices implementation and manages the list of * currently available TradeServices implementations. - * - * @see - * org.apache.geronimo.samples.daytrader.api.TradeServicesManager - * + * + * @see org.apache.aries.samples.ariestrader.api.TradeServicesManager + * */ - +@Service +@ReferenceListener(referenceInterface = TradeServices.class, bindMethod = "bindService", unbindMethod = "unbindService") +@Bean(initMethod = "init") public class TradeServicesManagerImpl implements TradeServicesManager { - private static TradeServices[] tradeServicesList = new TradeServices[TradeConfig.runTimeModeNames.length] ; + private static TradeServices[] tradeServicesList = new TradeServices[TradeConfig.runTimeModeNames.length]; // This lock is used to serialize market summary operations. private static final Integer marketSummaryLock = new Integer(0); private static long nextMarketSummary = System.currentTimeMillis(); - private static MarketSummaryDataBean cachedMSDB = null; - + private static MarketSummaryDataBean cachedMSDB = null; + /** - * TradeServicesManagerImpl null constructor - */ + * TradeServicesManagerImpl null constructor + */ public TradeServicesManagerImpl() { if (Log.doTrace()) Log.trace("TradeServicesManagerImpl()"); } /** - * init - */ + * init + */ public void init() { if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:init()"); @@ -65,13 +67,13 @@ public class TradeServicesManagerImpl implements TradeServicesManager { /** - * Get CurrentModes that are registered - */ + * Get CurrentModes that are registered + */ public ArrayList<Integer> getCurrentModes() { if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:getCurrentModes()"); ArrayList<Integer> modes = new ArrayList<Integer>(); - for (int i=0; i<tradeServicesList.length; i++) { + for (int i = 0; i < tradeServicesList.length; i++) { TradeServices tradeServicesRef = tradeServicesList[i]; if (tradeServicesRef != null) { modes.add(i); @@ -81,17 +83,17 @@ public class TradeServicesManagerImpl implements TradeServicesManager { } /** - * Get TradeServices reference - */ + * Get TradeServices reference + */ public TradeServices getTradeServices() { - if (Log.doTrace()) + if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:getTradeServices()"); return tradeServicesList[TradeConfig.getRunTimeMode().ordinal()]; } /** - * Bind a new TradeServices implementation - */ + * Bind a new TradeServices implementation + */ public void bindService(TradeServices tradeServices, Map props) { if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:bindService()", tradeServices, props); @@ -102,8 +104,8 @@ public class TradeServicesManagerImpl implements TradeServicesManager { } /** - * Unbind a TradeServices implementation - */ + * Unbind a TradeServices implementation + */ public void unbindService(TradeServices tradeServices, Map props) { if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:unbindService()", tradeServices, props); @@ -123,47 +125,47 @@ public class TradeServicesManagerImpl implements TradeServicesManager { * @return An instance of the market summary */ public MarketSummaryDataBean getMarketSummary() throws Exception { - + if (Log.doActionTrace()) { Log.trace("TradeAction:getMarketSummary()"); } - + if (Log.doTrace()) Log.trace("TradeServicesManagerImpl:getMarketSummary()"); if (TradeConfig.getMarketSummaryInterval() == 0) return getMarketSummaryInternal(); if (TradeConfig.getMarketSummaryInterval() < 0) return cachedMSDB; - + /** * This is a little funky. If its time to fetch a new Market summary then we'll synchronize * access to make sure only one requester does it. Others will merely return the old copy until * the new MarketSummary has been executed. */ - long currentTime = System.currentTimeMillis(); - - if (currentTime > nextMarketSummary) { - long oldNextMarketSummary = nextMarketSummary; - boolean fetch = false; - - synchronized (marketSummaryLock) { - /** - * Is it still ahead or did we miss lose the race? If we lost then let's get out - * of here as the work has already been done. - */ - if (oldNextMarketSummary == nextMarketSummary) { - fetch = true; - nextMarketSummary += TradeConfig.getMarketSummaryInterval()*1000; - - /** - * If the server has been idle for a while then its possible that nextMarketSummary - * could be way off. Rather than try and play catch up we'll simply get in sync with the - * current time + the interval. - */ - if (nextMarketSummary < currentTime) { - nextMarketSummary = currentTime + TradeConfig.getMarketSummaryInterval()*1000; - } - } - } + long currentTime = System.currentTimeMillis(); + + if (currentTime > nextMarketSummary) { + long oldNextMarketSummary = nextMarketSummary; + boolean fetch = false; + + synchronized (marketSummaryLock) { + /** + * Is it still ahead or did we miss lose the race? If we lost then let's get out + * of here as the work has already been done. + */ + if (oldNextMarketSummary == nextMarketSummary) { + fetch = true; + nextMarketSummary += TradeConfig.getMarketSummaryInterval() * 1000; + + /** + * If the server has been idle for a while then its possible that nextMarketSummary + * could be way off. Rather than try and play catch up we'll simply get in sync with the + * current time + the interval. + */ + if (nextMarketSummary < currentTime) { + nextMarketSummary = currentTime + TradeConfig.getMarketSummaryInterval() * 1000; + } + } + } /** * If we're the lucky one then let's update the MarketSummary @@ -172,7 +174,7 @@ public class TradeServicesManagerImpl implements TradeServicesManager { cachedMSDB = getMarketSummaryInternal(); } } - + return cachedMSDB; } diff --git a/samples/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 317ddef98..000000000 --- a/samples/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<blueprint default-activation="lazy" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - - <bean id="tradeServicesManagerBean" class="org.apache.aries.samples.ariestrader.core.TradeServicesManagerImpl" init-method="init"> - </bean> - - <service id="TradeServicesManager" ref="tradeServicesManagerBean" interface="org.apache.aries.samples.ariestrader.api.TradeServicesManager"/> - - <bean id="tradeDBManagerBean" class="org.apache.aries.samples.ariestrader.core.TradeDBManagerImpl" init-method="init"> - </bean> - - <service id="TradeDBManager" ref="tradeDBManagerBean" interface="org.apache.aries.samples.ariestrader.api.TradeDBManager"> - </service> - - <reference-list id="tradeServicesList" availability="optional" activation="eager" interface="org.apache.aries.samples.ariestrader.api.TradeServices"> - <reference-listener ref="tradeServicesManagerBean" bind-method="bindService" unbind-method="unbindService" /> - </reference-list> - - -</blueprint> - diff --git a/samples/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 517f4b095..97a98acfb 100644 --- a/samples/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/samples/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -16,33 +16,32 @@ limitations under the License. --> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - default-activation="eager"> - + default-activation="eager"> + <bean id="derbyXADataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource"> <property name="databaseName" value="tradedb"/> <!-- This creates the database on the fly. See the persistence.xml under ariestrader-entities for property configuration. The DB is created from persistence entities, this is not recommended for production use. --> - <property name="createDatabase" value="create" /> + <property name="createDatabase" value="create"/> </bean> - + <service id="TradeDataSource" ref="derbyXADataSource" interface="javax.sql.XADataSource"> <service-properties> <entry key="osgi.jndi.service.name" value="jdbc/TradeDataSource"/> </service-properties> </service> - + <bean id="derbyDataSource" class="org.apache.derby.jdbc.EmbeddedDataSource"> <property name="databaseName" value="tradedb"/> <!-- This creates the database on the fly. --> - <property name="createDatabase" value="create" /> + <property name="createDatabase" value="create"/> </bean> - + <service id="NoTxTradeDataSource" ref="derbyDataSource" interface="javax.sql.DataSource"> <service-properties> <entry key="osgi.jndi.service.name" value="jdbc/NoTxTradeDataSource"/> </service-properties> </service> - + </blueprint> diff --git a/samples/ariestrader/modules/ariestrader-persist-jdbc/pom.xml b/samples/ariestrader/modules/ariestrader-persist-jdbc/pom.xml index 80e1ae094..58d8155e5 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jdbc/pom.xml +++ b/samples/ariestrader/modules/ariestrader-persist-jdbc/pom.xml @@ -46,6 +46,15 @@ <artifactId>org.apache.aries.samples.ariestrader.beans</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + </dependency> </dependencies> <build> @@ -64,6 +73,10 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> </plugins> </build> </project> diff --git a/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/TradeJdbc.java b/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/TradeJdbc.java index 2cdc7ac60..9efae30a7 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/TradeJdbc.java +++ b/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/TradeJdbc.java @@ -19,8 +19,12 @@ package org.apache.aries.samples.ariestrader.persist.jdbc; import java.math.BigDecimal; import java.util.Collection; import java.util.ArrayList; +import javax.inject.Inject; import javax.sql.DataSource; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; +import org.apache.aries.blueprint.annotation.service.ServiceProperty; import org.apache.aries.samples.ariestrader.api.TradeServices; import org.apache.aries.samples.ariestrader.beans.AccountDataBeanImpl; import org.apache.aries.samples.ariestrader.beans.AccountProfileDataBeanImpl; @@ -50,17 +54,20 @@ import java.sql.Timestamp; * Trade online broker application. These business methods represent the * features and operations that can be performed by customers of the brokerage * such as login, logout, get a stock quote, buy or sell a stock, etc. and are - * specified in the {@link org.apache.aries.samples.ariestrader.TradeServices} + * specified in the {@link org.apache.aries.samples.ariestrader.api.TradeServices} * interface - * + * * Note: In order for this class to be thread-safe, a new TradeJDBC must be * created for each call to a method from the TradeInterface interface. * Otherwise, pooled connections may not be released. - * - * @see org.apache.aries.samples.ariestrader.TradeServices - * + * + * @see org.apache.aries.samples.ariestrader.api.TradeServices + * */ - +@Service(properties = { + @ServiceProperty(name = "mode", values = "JDBC") +}) +@Bean(initMethod = "init") public class TradeJdbc implements TradeServices { private DataSource dataSource= null; @@ -80,6 +87,7 @@ public class TradeJdbc implements TradeServices { /** * Zero arg constructor for TradeJdbc */ + @Inject public TradeJdbc() { } @@ -1004,7 +1012,7 @@ public class TradeJdbc implements TradeServices { /** * @see TradeServices#updateAccountProfile(AccountProfileDataBean) */ - public AccountProfileDataBean updateAccountProfile(String userID, String password, String fullName, String address, String email, String creditcard) throws Exception { + public AccountProfileDataBean updateAccountProfile(String userID, String password, String fullName, String address, String email, String creditcard) throws Exception { AccountProfileDataBean accountProfileData = null; Connection conn = null; @@ -1094,7 +1102,7 @@ public class TradeJdbc implements TradeServices { /** * Update a quote's price and volume - * + * * @param symbol * The PK of the quote * @param changeFactor @@ -1581,7 +1589,7 @@ public class TradeJdbc implements TradeServices { /** * Gets the inGlobalTxn - * + * * @return Returns a boolean */ private boolean getInGlobalTxn() { @@ -1590,7 +1598,7 @@ public class TradeJdbc implements TradeServices { /** * Sets the inGlobalTxn - * + * * @param inGlobalTxn * The inGlobalTxn to set */ @@ -1600,7 +1608,7 @@ public class TradeJdbc implements TradeServices { /** * Get mode - returns the persistence mode (TradeConfig.JDBC) - * + * * @return TradeConfig.ModeType */ public TradeConfig.ModeType getMode() { diff --git a/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index b5a5fcc4e..000000000 --- a/samples/ariestrader/modules/ariestrader-persist-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<blueprint default-activation="lazy" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - - <bean id="tradeServicesBeanJDBC" class="org.apache.aries.samples.ariestrader.persist.jdbc.TradeJdbc" init-method="init"> - <!--<property name="inSession" value="true"/>--> - </bean> - - <service id="tradeServicesJDBC" ref="tradeServicesBeanJDBC" interface="org.apache.aries.samples.ariestrader.api.TradeServices"> - <service-properties> - <entry key="mode" value="JDBC"/> - </service-properties> - </service> - -</blueprint> - diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-am/pom.xml b/samples/ariestrader/modules/ariestrader-persist-jpa-am/pom.xml index cc39e2777..1144c0a2b 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-am/pom.xml +++ b/samples/ariestrader/modules/ariestrader-persist-jpa-am/pom.xml @@ -55,6 +55,14 @@ <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + </dependency> </dependencies> <build> @@ -74,6 +82,18 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <configuration> + <namespaces> + <namespace>http://aries.apache.org/xmlns/jpa/v1.1.0</namespace> + </namespaces> + <customParameters> + <transaction.enableAnnotation>false</transaction.enableAnnotation> + </customParameters> + </configuration> + </plugin> </plugins> </build> </project> diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/am/TradeJpaAm.java b/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/am/TradeJpaAm.java index edd6b8b97..55302194e 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/am/TradeJpaAm.java +++ b/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/am/TradeJpaAm.java @@ -24,8 +24,12 @@ import java.util.Iterator; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; import javax.persistence.Query; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; +import org.apache.aries.blueprint.annotation.service.ServiceProperty; import org.apache.aries.samples.ariestrader.api.TradeServices; import org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl; import org.apache.aries.samples.ariestrader.entities.AccountProfileDataBeanImpl; @@ -50,17 +54,20 @@ import org.apache.aries.samples.ariestrader.util.TradeConfig; * by customers of the brokerage such as login, logout, get a * stock quote, buy or sell a stock, etc. and are specified in * the {@link - * org.apache.aries.samples.ariestrader.TradeServices} + * org.apache.aries.samples.ariestrader.api.TradeServices} * interface * - * @see org.apache.aries.samples.ariestrader.TradeServices + * @see org.apache.aries.samples.ariestrader.api.TradeServices * */ - +@Service(properties = { + @ServiceProperty(name = "mode", values = "JPA_AM") +}) +@Bean(initMethod = "init", destroyMethod = "destroy") public class TradeJpaAm implements TradeServices { -// @PersistenceUnit(unitName="ariestrader-am") - private static EntityManagerFactory emf; + @PersistenceUnit(unitName="ariestrader-am") + private EntityManagerFactory emf; private static boolean initialized = false; @@ -70,10 +77,6 @@ public class TradeJpaAm implements TradeServices { public TradeJpaAm() { } - public void setEmf (EntityManagerFactory emf) { - this.emf = emf; - } - public void init() { if (initialized) return; diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index e121f1f44..000000000 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-am/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<blueprint default-activation="lazy" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"> - - <bean id="tradeServicesBeanJPA-AM" class="org.apache.aries.samples.ariestrader.persist.jpa.am.TradeJpaAm" init-method="init"> - <jpa:unit property="emf" unitname="ariestrader-am" /> - </bean> - - <service id="tradeServicesJPA-AM" ref="tradeServicesBeanJPA-AM" interface="org.apache.aries.samples.ariestrader.api.TradeServices"> - <service-properties> - <entry key="mode" value="JPA_AM"/> - </service-properties> - </service> - -</blueprint> - diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/pom.xml b/samples/ariestrader/modules/ariestrader-persist-jpa-cm/pom.xml index af9547410..69bd737f5 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/pom.xml +++ b/samples/ariestrader/modules/ariestrader-persist-jpa-cm/pom.xml @@ -55,6 +55,21 @@ <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.transaction</groupId> + <artifactId>javax.transaction-api</artifactId> + <optional>true</optional> + </dependency> </dependencies> <build> @@ -74,6 +89,19 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <configuration> + <namespaces> + <namespace>http://aries.apache.org/xmlns/jpa/v1.1.0</namespace> + <namespace>http://aries.apache.org/xmlns/transactions/v1.2.0</namespace> + </namespaces> + <customParameters> + <transaction.enableAnnotation>false</transaction.enableAnnotation> + </customParameters> + </configuration> + </plugin> </plugins> </build> </project> diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/cm/TradeJpaCm.java b/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/cm/TradeJpaCm.java index 74d048f1d..ffbd55463 100644 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/cm/TradeJpaCm.java +++ b/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/java/org/apache/aries/samples/ariestrader/persist/jpa/cm/TradeJpaCm.java @@ -1,46 +1,50 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.aries.samples.ariestrader.persist.jpa.cm; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import javax.persistence.EntityManager; -import javax.persistence.Query; - +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; +import org.apache.aries.blueprint.annotation.service.ServiceProperty; import org.apache.aries.samples.ariestrader.api.TradeServices; -import org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl; -import org.apache.aries.samples.ariestrader.entities.AccountProfileDataBeanImpl; -import org.apache.aries.samples.ariestrader.entities.HoldingDataBeanImpl; -import org.apache.aries.samples.ariestrader.entities.OrderDataBeanImpl; -import org.apache.aries.samples.ariestrader.entities.QuoteDataBeanImpl; import org.apache.aries.samples.ariestrader.api.persistence.AccountDataBean; import org.apache.aries.samples.ariestrader.api.persistence.AccountProfileDataBean; import org.apache.aries.samples.ariestrader.api.persistence.HoldingDataBean; import org.apache.aries.samples.ariestrader.api.persistence.MarketSummaryDataBean; import org.apache.aries.samples.ariestrader.api.persistence.OrderDataBean; import org.apache.aries.samples.ariestrader.api.persistence.QuoteDataBean; +import org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl; +import org.apache.aries.samples.ariestrader.entities.AccountProfileDataBeanImpl; +import org.apache.aries.samples.ariestrader.entities.HoldingDataBeanImpl; +import org.apache.aries.samples.ariestrader.entities.OrderDataBeanImpl; +import org.apache.aries.samples.ariestrader.entities.QuoteDataBeanImpl; import org.apache.aries.samples.ariestrader.util.FinancialUtils; import org.apache.aries.samples.ariestrader.util.Log; import org.apache.aries.samples.ariestrader.util.TradeConfig; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import javax.transaction.Transactional; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + /** * TradeJpaCm uses JPA via Container Managed (CM) Entity * Managers to implement the business methods of the Trade @@ -48,24 +52,23 @@ import org.apache.aries.samples.ariestrader.util.TradeConfig; * the features and operations that can be performed by * customers of the brokerage such as login, logout, get a stock * quote, buy or sell a stock, etc. and are specified in the - * {@link org.apache.aries.samples.ariestrader.TradeServices} + * {@link org.apache.aries.samples.ariestrader.api.TradeServices} * interface - * - * @see org.apache.aries.samples.ariestrader.TradeServices - * + * + * @see org.apache.aries.samples.ariestrader.api.TradeServices */ - +@Service(properties = { + @ServiceProperty(name = "mode", values = "JPA_CM") +}) +@Bean(initMethod = "init", destroyMethod = "destroy") +@Transactional(Transactional.TxType.REQUIRED) public class TradeJpaCm implements TradeServices { - private EntityManager entityManager; + @PersistenceContext(unitName = "ariestrader-cm") + EntityManager entityManager; private static boolean initialized = false; -// @PersistenceContext(unitName="ariestrader-cm") - public void setEntityManager (EntityManager em) { - entityManager = em; - } - /** * Zero arg constructor for TradeJpaCm */ @@ -89,8 +92,7 @@ public class TradeJpaCm implements TradeServices { if (!initialized) return; Log.trace("TradeJpaCm:destroy"); - } - catch (Exception e) { + } catch (Exception e) { Log.error("TradeJpaCm:destroy", e); } @@ -112,7 +114,7 @@ public class TradeJpaCm implements TradeServices { QuoteDataBean[] quoteArray = (QuoteDataBean[]) quotes.toArray(new QuoteDataBean[quotes.size()]); ArrayList<QuoteDataBean> topGainers = new ArrayList<QuoteDataBean>( - 5); + 5); ArrayList<QuoteDataBean> topLosers = new ArrayList<QuoteDataBean>(5); BigDecimal TSIA = FinancialUtils.ZERO; BigDecimal openTSIA = FinancialUtils.ZERO; @@ -133,15 +135,14 @@ public class TradeJpaCm implements TradeServices { totalVolume += volume; } TSIA = TSIA.divide(new BigDecimal(quoteArray.length), - FinancialUtils.ROUND); + FinancialUtils.ROUND); openTSIA = openTSIA.divide(new BigDecimal(quoteArray.length), - FinancialUtils.ROUND); + FinancialUtils.ROUND); } marketSummaryData = new MarketSummaryDataBean(TSIA, openTSIA, - totalVolume, topGainers, topLosers); - } - catch (Exception e) { + totalVolume, topGainers, topLosers); + } catch (Exception e) { Log.error("TradeJpaCm:getMarketSummary", e); throw new RuntimeException("TradeJpaCm:getMarketSummary -- error ", e); } @@ -164,7 +165,7 @@ public class TradeJpaCm implements TradeServices { HoldingDataBeanImpl holding = null; // The holding will be created by this buy order - order = createOrder( account, (QuoteDataBean) quote, (HoldingDataBean) holding, "buy", quantity); + order = createOrder(account, (QuoteDataBean) quote, (HoldingDataBean) holding, "buy", quantity); // order = createOrder(account, quote, holding, "buy", quantity); // UPDATE - account should be credited during completeOrder @@ -179,8 +180,7 @@ public class TradeJpaCm implements TradeServices { completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); - } - catch (Exception e) { + } catch (Exception e) { Log.error("TradeJpaCm:buy(" + userID + "," + symbol + "," + quantity + ") --> failed", e); /* On exception - cancel the order */ // TODO figure out how to do this with JPA @@ -212,8 +212,8 @@ public class TradeJpaCm implements TradeServices { if (holding == null) { Log.error("TradeJpaCm:sell User " + userID - + " attempted to sell holding " + holdingID - + " which has already been sold"); + + " attempted to sell holding " + holdingID + + " which has already been sold"); OrderDataBean orderData = new OrderDataBeanImpl(); orderData.setOrderStatus("cancelled"); @@ -245,8 +245,7 @@ public class TradeJpaCm implements TradeServices { else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); - } - catch (Exception e) { + } catch (Exception e) { Log.error("TradeJpaCm:sell(" + userID + "," + holdingID + ") --> failed", e); // TODO figure out JPA cancel if (order != null) @@ -264,9 +263,9 @@ public class TradeJpaCm implements TradeServices { public void queueOrder(Integer orderID, boolean twoPhase) { Log - .error("TradeJpaCm:queueOrder() not implemented for this runtime mode"); + .error("TradeJpaCm:queueOrder() not implemented for this runtime mode"); throw new UnsupportedOperationException( - "TradeJpaCm:queueOrder() not implemented for this runtime mode"); + "TradeJpaCm:queueOrder() not implemented for this runtime mode"); } public OrderDataBean completeOrder(Integer orderID, boolean twoPhase) throws Exception { @@ -296,9 +295,9 @@ public class TradeJpaCm implements TradeServices { if (Log.doTrace()) Log.trace("TradeJpaCm:completeOrder--> Completing Order " - + order.getOrderID() + "\n\t Order info: " + order - + "\n\t Account info: " + account + "\n\t Quote info: " - + quote + "\n\t Holding info: " + holding); + + order.getOrderID() + "\n\t Order info: " + order + + "\n\t Account info: " + account + "\n\t Quote info: " + + quote + "\n\t Holding info: " + holding); HoldingDataBean newHolding = null; if (order.isBuy()) { @@ -325,8 +324,7 @@ public class TradeJpaCm implements TradeServices { Log.error("TradeJpaCm:completeOrder -- Unable to sell order " + order.getOrderID() + " holding already sold"); order.cancel(); return order; - } - else { + } else { entityManager.remove(holding); order.setHolding(null); } @@ -338,12 +336,11 @@ public class TradeJpaCm implements TradeServices { if (Log.doTrace()) Log.trace("TradeJpaCm:completeOrder--> Completed Order " - + order.getOrderID() + "\n\t Order info: " + order - + "\n\t Account info: " + account + "\n\t Quote info: " - + quote + "\n\t Holding info: " + holding); + + order.getOrderID() + "\n\t Order info: " + order + + "\n\t Account info: " + account + "\n\t Quote info: " + + quote + "\n\t Holding info: " + holding); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } @@ -398,8 +395,7 @@ public class TradeJpaCm implements TradeServices { Query updateStatus = entityManager.createNamedQuery("orderejb.completeClosedOrders"); updateStatus.setParameter("userID", userID); updateStatus.executeUpdate(); - } - else if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) { + } else if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) { /* * Add logic to do update orders operation, because JBoss5' * Hibernate 3.3.1GA DB2Dialect and MySQL5Dialect do not work @@ -407,31 +403,30 @@ public class TradeJpaCm implements TradeServices { * in OrderDatabean */ Query findaccountid = entityManager.createNativeQuery( - "select " - + "a.ACCOUNTID, " - + "a.LOGINCOUNT, " - + "a.LOGOUTCOUNT, " - + "a.LASTLOGIN, " - + "a.CREATIONDATE, " - + "a.BALANCE, " - + "a.OPENBALANCE, " - + "a.PROFILE_USERID " - + "from accountejb a where a.profile_userid = ?", - org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl.class); + "select " + + "a.ACCOUNTID, " + + "a.LOGINCOUNT, " + + "a.LOGOUTCOUNT, " + + "a.LASTLOGIN, " + + "a.CREATIONDATE, " + + "a.BALANCE, " + + "a.OPENBALANCE, " + + "a.PROFILE_USERID " + + "from accountejb a where a.profile_userid = ?", + org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl.class); findaccountid.setParameter(1, userID); AccountDataBeanImpl account = (AccountDataBeanImpl) findaccountid.getSingleResult(); Integer accountid = account.getAccountID(); Query updateStatus = entityManager.createNativeQuery("UPDATE orderejb o SET o.orderStatus = 'completed' WHERE " - + "o.orderStatus = 'closed' AND o.ACCOUNT_ACCOUNTID = ?"); + + "o.orderStatus = 'closed' AND o.ACCOUNT_ACCOUNTID = ?"); updateStatus.setParameter(1, accountid.intValue()); updateStatus.executeUpdate(); } return results; - } - catch (Exception e) { + } catch (Exception e) { Log.error("TradeJpaCm.getClosedOrders", e); throw new RuntimeException( - "TradeJpaCm.getClosedOrders - error", e); + "TradeJpaCm.getClosedOrders - error", e); } @@ -447,8 +442,7 @@ public class TradeJpaCm implements TradeServices { Log.trace("TradeJpaCm:createQuote-->" + quote); return quote; - } - catch (Exception e) { + } catch (Exception e) { Log.error("TradeJpaCm:createQuote -- exception creating Quote", e); throw new RuntimeException(e); } @@ -489,10 +483,10 @@ public class TradeJpaCm implements TradeServices { if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) { quote = entityManager.find(QuoteDataBeanImpl.class, symbol); } else if (TradeConfig.jpaLayer == TradeConfig.OPENJPA) { - + Query q = entityManager.createNamedQuery("quoteejb.quoteForUpdate"); q.setParameter(1, symbol); - + quote = (QuoteDataBeanImpl) q.getSingleResult(); } @@ -569,12 +563,12 @@ public class TradeJpaCm implements TradeServices { return apb; } - public AccountProfileDataBean updateAccountProfile( String userID, - String password, - String fullName, - String address, - String email, - String creditcard) throws Exception { + public AccountProfileDataBean updateAccountProfile(String userID, + String password, + String fullName, + String address, + String email, + String creditcard) throws Exception { if (Log.doTrace()) @@ -586,9 +580,9 @@ public class TradeJpaCm implements TradeServices { * profileData.getUserID()); // In order for the object to merge * correctly, the account has to be hooked into the temp object... // - * may need to reverse this and obtain the full object first - * + * * profileData.setAccount(temp.getAccount()); - * + * * //TODO this might not be correct temp = * entityManager.merge(profileData); //System.out.println(temp); */ @@ -605,7 +599,7 @@ public class TradeJpaCm implements TradeServices { } public AccountDataBean login(String userID, String password) - throws Exception { + throws Exception { AccountProfileDataBeanImpl profile = entityManager.find(AccountProfileDataBeanImpl.class, userID); @@ -639,11 +633,11 @@ public class TradeJpaCm implements TradeServices { Log.trace("TradeJpaCm:logout(" + userID + ") success"); } - public AccountDataBean register(String userID, - String password, - String fullname, - String address, - String email, + public AccountDataBean register(String userID, + String password, + String fullname, + String address, + String email, String creditcard, BigDecimal openBalance) throws Exception { AccountDataBeanImpl account = null; @@ -659,13 +653,12 @@ public class TradeJpaCm implements TradeServices { if (profile != null) { Log.error("Failed to register new Account - AccountProfile with userID(" + userID + ") already exists"); return null; - } - else { + } else { profile = new AccountProfileDataBeanImpl(userID, password, fullname, - address, email, creditcard); + address, email, creditcard); account = new AccountDataBeanImpl(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID); - profile.setAccount((AccountDataBean)account); - account.setProfile((AccountProfileDataBean)profile); + profile.setAccount((AccountDataBean) account); + account.setProfile((AccountProfileDataBean) profile); entityManager.persist(profile); entityManager.persist(account); // Uncomment this line to verify that datasources has been enlisted. After rebuild attempt to register a user with @@ -695,23 +688,22 @@ public class TradeJpaCm implements TradeServices { OrderDataBeanImpl order; if (Log.doTrace()) Log.trace("TradeJpaCm:createOrder(orderID=" + " account=" - + ((account == null) ? null : account.getAccountID()) - + " quote=" + ((quote == null) ? null : quote.getSymbol()) - + " orderType=" + orderType + " quantity=" + quantity); + + ((account == null) ? null : account.getAccountID()) + + " quote=" + ((quote == null) ? null : quote.getSymbol()) + + " orderType=" + orderType + " quantity=" + quantity); try { - order = new OrderDataBeanImpl(orderType, - "open", - new Timestamp(System.currentTimeMillis()), - null, - quantity, - quote.getPrice().setScale(FinancialUtils.SCALE, FinancialUtils.ROUND), - TradeConfig.getOrderFee(orderType), - account, - quote, - holding); - entityManager.persist(order); - } - catch (Exception e) { + order = new OrderDataBeanImpl(orderType, + "open", + new Timestamp(System.currentTimeMillis()), + null, + quantity, + quote.getPrice().setScale(FinancialUtils.SCALE, FinancialUtils.ROUND), + TradeConfig.getOrderFee(orderType), + account, + quote, + holding); + entityManager.persist(order); + } catch (Exception e) { Log.error("TradeJpaCm:createOrder -- failed to create Order", e); throw new RuntimeException("TradeJpaCm:createOrder -- failed to create Order", e); } @@ -719,18 +711,18 @@ public class TradeJpaCm implements TradeServices { } private HoldingDataBean createHolding(AccountDataBean account, - QuoteDataBean quote, - double quantity, + QuoteDataBean quote, + double quantity, BigDecimal purchasePrice) throws Exception { HoldingDataBeanImpl newHolding = new HoldingDataBeanImpl(quantity, - purchasePrice, new Timestamp(System.currentTimeMillis()), - account, quote); + purchasePrice, new Timestamp(System.currentTimeMillis()), + account, quote); entityManager.persist(newHolding); return newHolding; } public double investmentReturn(double investment, double NetValue) - throws Exception { + throws Exception { if (Log.doTrace()) Log.trace("TradeJpaCm:investmentReturn"); @@ -754,7 +746,7 @@ public class TradeJpaCm implements TradeServices { /** * Get mode - returns the persistence mode (TradeConfig.JPA) - * + * * @return TradeConfig.ModeType */ public TradeConfig.ModeType getMode() { diff --git a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index c1c030fc2..000000000 --- a/samples/ariestrader/modules/ariestrader-persist-jpa-cm/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<blueprint default-activation="lazy" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" - xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"> - - <bean id="tradeServicesBeanJPA-CM" class="org.apache.aries.samples.ariestrader.persist.jpa.cm.TradeJpaCm" init-method="init"> - <jpa:context property="entityManager" unitname="ariestrader-cm" /> - <tx:transaction method="*" value="Required"/> - </bean> - - <service id="tradeServicesJPA-CM" ref="tradeServicesBeanJPA-CM" interface="org.apache.aries.samples.ariestrader.api.TradeServices"> - <service-properties> - <entry key="mode" value="JPA_CM"/> - </service-properties> - </service> - -</blueprint> - diff --git a/samples/blog/blog-biz/pom.xml b/samples/blog/blog-biz/pom.xml index c2039f773..be52ae0ea 100644 --- a/samples/blog/blog-biz/pom.xml +++ b/samples/blog/blog-biz/pom.xml @@ -45,7 +45,26 @@ <groupId>org.apache.aries.samples.blog</groupId> <artifactId>org.apache.aries.samples.blog.api</artifactId> </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </project> diff --git a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogAuthorManagerImpl.java b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogAuthorManagerImpl.java index e4b8412b7..a9c754e2a 100644 --- a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogAuthorManagerImpl.java +++ b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogAuthorManagerImpl.java @@ -25,38 +25,38 @@ import java.util.Date; import java.util.Iterator; import java.util.List; +import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.samples.blog.api.*; import org.apache.aries.samples.blog.api.persistence.Author; import org.apache.aries.samples.blog.api.persistence.BlogPersistenceService; +import javax.inject.Singleton; - +@Singleton public class BlogAuthorManagerImpl implements BlogAuthorManager { private BlogPersistenceService persistenceService; - // Blueprint injection used to set the persistenceService - public void setPersistenceService(BlogPersistenceService persistenceService) - { - this.persistenceService = persistenceService; - } - - public void createAuthor(String email, String dob, String name, String displayName, String bio) throws ParseException + public BlogAuthorManagerImpl(@Reference BlogPersistenceService persistenceService) { + this.persistenceService = persistenceService; + } + + public void createAuthor(String email, String dob, String name, String displayName, String bio) throws ParseException { if(email == null) throw new IllegalArgumentException("Email must not be null"); - + Date dateOfBirth; dateOfBirth = (dob == null || "".equals(dob)) ? null : new SimpleDateFormat("yyyy-MM-dd").parse(dob); - + persistenceService.createAuthor(email, dateOfBirth, name, displayName, bio); } - + public List<? extends BlogAuthor> getAllAuthors() { List<? extends Author> authors = persistenceService.getAllAuthors(); return adaptAuthor(authors); } - + public BlogAuthor getAuthor(String emailAddress) { if(emailAddress == null) throw new IllegalArgumentException("Email must not be null"); @@ -66,25 +66,25 @@ public class BlogAuthorManagerImpl implements BlogAuthorManager else return null; } - + public void removeAuthor(String emailAddress) { if(emailAddress == null) throw new IllegalArgumentException("Email must not be null"); persistenceService.removeAuthor(emailAddress); } - + public void updateAuthor(String email, String dob, String name, String displayName, String bio) throws ParseException - { + { if(email == null) throw new IllegalArgumentException("Email must not be null"); - + Date dateOfBirth; dateOfBirth = (dob == null || "".equals(dob)) ? null : new SimpleDateFormat("yyyy-MM-dd").parse(dob); persistenceService.updateAuthor(email, dateOfBirth, name, displayName, bio); } - + private List<? extends BlogAuthor> adaptAuthor(List<? extends Author> authors) { return new BlogListAdapter<BlogAuthor, Author>(authors, BlogAuthorImpl.class, Author.class); } - + } diff --git a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogCommentManagerImpl.java b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogCommentManagerImpl.java index 3513ae7f5..f5e929bb1 100644 --- a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogCommentManagerImpl.java +++ b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogCommentManagerImpl.java @@ -23,18 +23,26 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.aries.blueprint.annotation.referencelistener.ReferenceListener; +import org.apache.aries.blueprint.annotation.service.Availability; +import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.samples.blog.api.BlogComment; import org.apache.aries.samples.blog.api.BlogCommentManager; import org.apache.aries.samples.blog.api.comment.persistence.BlogCommentService; import org.apache.aries.samples.blog.api.comment.persistence.Comment; +import javax.inject.Inject; +import javax.inject.Singleton; +@ReferenceListener(referenceInterface = BlogCommentService.class, bindMethod = "blogServiceBound", unbindMethod = "blogServiceUnbound") +@Singleton public class BlogCommentManagerImpl implements BlogCommentManager { private BlogCommentService commentService; private boolean commentServiceValid; - // Injected via blueprint + @Inject + @Reference(availability = Availability.OPTIONAL) public void setCommentService(BlogCommentService bcs) { commentService = bcs; } diff --git a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogEntryManagerImpl.java b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogEntryManagerImpl.java index 6806568f7..9c16fb860 100644 --- a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogEntryManagerImpl.java +++ b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BlogEntryManagerImpl.java @@ -30,14 +30,17 @@ import org.apache.aries.samples.blog.api.BlogEntryManager; import org.apache.aries.samples.blog.api.persistence.BlogPersistenceService; import org.apache.aries.samples.blog.api.persistence.Entry; +import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class BlogEntryManagerImpl implements BlogEntryManager { private BlogPersistenceService persistenceService; - // Injected via blueprint + @Inject public void setPersistenceService(BlogPersistenceService persistenceService) { this.persistenceService = persistenceService; diff --git a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BloggingServiceImpl.java b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BloggingServiceImpl.java index 06c5604fd..eb2b62e33 100644 --- a/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BloggingServiceImpl.java +++ b/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/biz/BloggingServiceImpl.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.samples.blog.api.BlogAuthor; import org.apache.aries.samples.blog.api.BlogAuthorManager; import org.apache.aries.samples.blog.api.BlogComment; @@ -31,28 +32,22 @@ import org.apache.aries.samples.blog.api.BlogEntry; import org.apache.aries.samples.blog.api.BlogEntryManager; import org.apache.aries.samples.blog.api.BloggingService; +import javax.inject.Singleton; + /** Implementation of the BloggingService */ +@Service(classes = BloggingService.class) +@Singleton public class BloggingServiceImpl implements BloggingService { private BlogEntryManager blogEntryManager; private BlogAuthorManager blogAuthorManager; private BlogCommentManager blogCommentManager; - // Injected via blueprint - public void setBlogEntryManager(BlogEntryManager blogPostManager) { - this.blogEntryManager = blogPostManager; - } - - // Injected via blueprint - public void setBlogAuthorManager(BlogAuthorManager authorManager) { - this.blogAuthorManager = authorManager; + public BloggingServiceImpl(BlogEntryManager blogEntryManager, BlogAuthorManager blogAuthorManager, BlogCommentManager blogCommentManager) { + this.blogEntryManager = blogEntryManager; + this.blogAuthorManager = blogAuthorManager; + this.blogCommentManager = blogCommentManager; } - // Injected via blueprint - public void setBlogCommentManager(BlogCommentManager commentManager) { - this.blogCommentManager = commentManager; - } - - public String getBlogTitle() { return new BlogImpl().getBlogTitle(); } diff --git a/samples/blog/blog-biz/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/blog/blog-biz/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 0f7077f91..000000000 --- a/samples/blog/blog-biz/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - - <bean id="blogAuthorManager" class="org.apache.aries.samples.blog.biz.BlogAuthorManagerImpl"> - <property name="persistenceService" ref="persistenceManager"/> - </bean> - - <bean id="blogEntryManager" class="org.apache.aries.samples.blog.biz.BlogEntryManagerImpl"> - <property name="persistenceService" ref="persistenceManager"/> - </bean> - - <bean id="blogCommentManager" class="org.apache.aries.samples.blog.biz.BlogCommentManagerImpl"> - <property name="commentService" ref="commentPersistenceService"/> - </bean> - - - <bean id="bloggingServiceComponent" class="org.apache.aries.samples.blog.biz.BloggingServiceImpl"> - <property name="blogEntryManager" ref="blogEntryManager"/> - <property name="blogAuthorManager" ref="blogAuthorManager"/> - <property name="blogCommentManager" ref="blogCommentManager"/> - </bean> - - <service ref="bloggingServiceComponent" interface="org.apache.aries.samples.blog.api.BloggingService"/> - - <reference id="persistenceManager" interface="org.apache.aries.samples.blog.api.persistence.BlogPersistenceService"/> - - <reference id="commentPersistenceService" availability="optional" interface="org.apache.aries.samples.blog.api.comment.persistence.BlogCommentService"> - <reference-listener ref="blogCommentManager" bind-method="blogServiceBound" unbind-method="blogServiceUnbound"/> - </reference> -</blueprint> diff --git a/samples/blog/blog-persistence-jdbc/pom.xml b/samples/blog/blog-persistence-jdbc/pom.xml index 0a453de6e..f54d9385f 100644 --- a/samples/blog/blog-persistence-jdbc/pom.xml +++ b/samples/blog/blog-persistence-jdbc/pom.xml @@ -53,8 +53,30 @@ <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <optional>true</optional> + </dependency> </dependencies> - + <build> + <plugins> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> + </plugins> + </build> </project> diff --git a/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/BlogPersistenceServiceImpl.java b/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/BlogPersistenceServiceImpl.java index 3e4719f95..ba2ad110a 100644 --- a/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/BlogPersistenceServiceImpl.java +++ b/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/BlogPersistenceServiceImpl.java @@ -28,8 +28,15 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; import javax.sql.DataSource; +import org.apache.aries.blueprint.annotation.bean.Activation; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.samples.blog.api.persistence.BlogPersistenceService; import org.apache.aries.samples.blog.persistence.jdbc.entity.AuthorImpl; import org.apache.aries.samples.blog.persistence.jdbc.entity.EntryImpl; @@ -37,9 +44,11 @@ import org.apache.aries.samples.blog.persistence.jdbc.entity.EntryImpl; /** * This class is the implementation of the blogPersistenceService */ +@Service(classes = BlogPersistenceService.class) +@Bean(activation = Activation.LAZY) public class BlogPersistenceServiceImpl implements BlogPersistenceService { private DataSource dataSource; - + private Statements statements; public BlogPersistenceServiceImpl() { @@ -49,10 +58,12 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * set data source */ + @Inject public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } + @PostConstruct public void init() { Statement s = null; Connection connection = null; @@ -85,6 +96,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { } } + @PreDestroy public void destroy() { Statement s = null; Connection connection = null; @@ -115,10 +127,10 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { } } } - + /** * Create an author record - * + * * @param a * The author object to be created * @throws ParseException @@ -126,12 +138,12 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { */ public void createAuthor(String email, Date dob, String name, String displayName, String bio) { - - + + try { Connection connection = dataSource.getConnection(); String sql = "INSERT INTO AUTHOR VALUES (?,?,?,?,?)"; - + PreparedStatement ppsm = connection.prepareStatement(sql); ppsm.setString(1, email); ppsm.setString(2, bio); @@ -144,7 +156,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { int insertRows = ppsm.executeUpdate(); ppsm.close(); connection.close(); - + if (insertRows != 1) throw new IllegalArgumentException("The Author " + email + " cannot be inserted."); @@ -157,25 +169,25 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Create a blog entry record - * - * @param a + * + * @param a * The author - * @param title + * @param title * The title of the post - * @param blogText + * @param blogText * The text of the post * @param tags - * + * */ public void createBlogPost(String authorEmail, String title, String blogText, List<String> tags) { - + AuthorImpl a = getAuthor(authorEmail); - + if(title == null) title = ""; Date publishDate = new Date(System.currentTimeMillis()); if(tags == null) tags = new ArrayList<String>(); - + try { Connection connection = dataSource.getConnection(); @@ -188,10 +200,10 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { long max_id = rs.getLong(1); ppsm.close(); - + long post_id = max_id + 1; sql = "INSERT INTO BLOGENTRY VALUES (?,?,?,?,?,?)"; - + ppsm = connection.prepareStatement(sql); ppsm.setLong(1, post_id); ppsm.setString(2, blogText); @@ -202,7 +214,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { else ppsm.setDate(3, null); ppsm.setString(4, title); - + ppsm.setDate(5, null); ppsm.setString(6, a.getEmail()); int rows = ppsm.executeUpdate(); @@ -211,7 +223,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { "The blog entry record cannot be inserted: " + blogText); ppsm.close(); - + // insert a row in the relationship table sql = "INSERT INTO Author_BlogEntry VALUES (?,?)"; @@ -222,7 +234,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { rows = ppsm.executeUpdate(); ppsm.close(); connection.close(); - + if (rows != 1) throw new IllegalArgumentException( "The Author_BlogEntry record cannot be inserted: " @@ -236,7 +248,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Find the blog entry record with the specified title - * + * * @param The title to be searched * @return The blogEntry record */ @@ -248,7 +260,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { + "'"; List<EntryImpl> blogEntries = findBlogs(sql); - + // just return the first blog entry for the time being if ((blogEntries != null) && (blogEntries.size() > 0)) be = blogEntries.get(0); @@ -257,7 +269,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return all author records in the Author table - * + * * @return the list of Author records */ public List<AuthorImpl> getAllAuthors() { @@ -271,7 +283,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return all blog entry records from BlogEntry table with the most recent * published blog entries first - * + * * @return a list of blogEntry object */ public List<EntryImpl> getAllBlogEntries() { @@ -284,7 +296,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return the number of the blog entry records - * + * * @return the number of the blog Entry records */ public int getNoOfBlogEntries() { @@ -310,7 +322,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return the portion of blog Entries - * + * * @param firstPostIndex * The index of the first blog entry to be returned * @param noOfPosts @@ -346,7 +358,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return the author with the specified email address - * + * * @param emailAddress * The email address * @return The author record @@ -367,7 +379,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return the blog entries modified between the date range of [start, end] - * + * * @param start * The start date * @param end @@ -396,7 +408,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return a list of blog entries belonging to the author with the specified * email address - * + * * @param emailAddress * the author's email address * @return The list of blog entries @@ -410,7 +422,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Update the author record - * + * * @param email * The email associated with an author * @param dob @@ -425,7 +437,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { public void updateAuthor(String email, Date dob, String name, String displayName, String bio) { - + String sql = "UPDATE AUTHOR a SET bio = ?, displayName = ?, dob = ?, name =? WHERE email ='" + email + "'"; int updatedRows = 0; @@ -440,10 +452,10 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { ppsm.setDate(3, null); ppsm.setString(4, name); updatedRows = ppsm.executeUpdate(); - + ppsm.close(); connection.close(); - + if (updatedRows != 1) throw new IllegalArgumentException("The Author " + email + " cannot be updated."); @@ -454,11 +466,11 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Update the blog entry record - * - * + * + * */ public void updateBlogEntry(long id, String email, String title, String blogText, List<String> tags, Date updatedDate) { - + if (id == -1) throw new IllegalArgumentException( "Not a BlogEntry returned by this interface"); @@ -484,7 +496,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { String sql = "UPDATE BLOGENTRY bp SET bp.blogText = ?, bp.publishDate = ?, bp.title = ?, bp.updatedDate = ?, bp.AUTHOR_EMAIL = ? where bp.id = " + id; int updatedRows = 0; - + try { Connection connection = dataSource.getConnection(); PreparedStatement ppsm = connection.prepareStatement(sql); @@ -505,9 +517,9 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { ppsm.setString(5, email); updatedRows = ppsm.executeUpdate(); - + ppsm.close(); - + connection.close(); if (updatedRows != 1) @@ -542,10 +554,10 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Delete the author record with the specified email address - * + * * @param emailAddress * The author's email address - * + * */ public void removeAuthor(String emailAddress) { @@ -558,7 +570,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { PreparedStatement ppsm = connection.prepareStatement(sql); ppsm.executeUpdate(); ppsm.close(); - + // delete the records from Author_BlogEntry sql = "DELETE FROM Author_BlogEntry ab WHERE ab.AUTHOR_EMAIL = '" + emailAddress + "'"; @@ -581,7 +593,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Delete the blog entry record specified by the blogEntry - * + * * @param blogEntry * the blog entry record to be deleted */ @@ -614,7 +626,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return the blog entry record with the specified id - * + * * @param postId * The blogEntry record id */ @@ -630,7 +642,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return a list of authors with the sql query - * + * * @param sql * The SQL query * @return A list of author records @@ -684,7 +696,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { /** * Return a list of blog entries with the sql query - * + * * @param sql * The sql query to be executed * @return a list of blogEntry records diff --git a/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java b/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/DatasourceProducer.java similarity index 52% copy from samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java copy to samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/DatasourceProducer.java index 3c3b012e3..e2d0fbdc5 100644 --- a/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java +++ b/samples/blog/blog-persistence-jdbc/src/main/java/org/apache/aries/samples/blog/persistence/jdbc/DatasourceProducer.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -16,18 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.aries.samples.blueprint.helloworld.server; -import org.apache.aries.samples.blueprint.helloworld.api.*; +package org.apache.aries.samples.blog.persistence.jdbc; -public class HelloWorldServiceImpl implements HelloWorldService { +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource; - public void hello() { - System.out.println("======>>> A message from the server: Hello World!"); - } +import javax.inject.Singleton; - public void startUp() { - System.out.println("======>>> Starting HelloWorld Server"); - } -} +@Singleton +public class DatasourceProducer { - \ No newline at end of file + @Bean + public EmbeddedConnectionPoolDataSource dataSource() { + EmbeddedConnectionPoolDataSource embeddedConnectionPoolDataSource = new EmbeddedConnectionPoolDataSource(); + embeddedConnectionPoolDataSource.setDatabaseName("memory:blogDB"); + embeddedConnectionPoolDataSource.setCreateDatabase("create"); + return embeddedConnectionPoolDataSource; + } +} diff --git a/samples/blog/blog-persistence-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/blog/blog-persistence-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 2df999ccd..000000000 --- a/samples/blog/blog-persistence-jdbc/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - - <bean id="datasource" class="org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource"> - <property name="databaseName" value="memory:blogDB"/> - <property name="createDatabase" value="create" /> - </bean> - - <bean id="persistenceImpl" class="org.apache.aries.samples.blog.persistence.jdbc.BlogPersistenceServiceImpl" activation="lazy" init-method="init" destroy-method="destroy"> - <property name="dataSource" ref="datasource" /> - </bean> - - <service ref="persistenceImpl" interface="org.apache.aries.samples.blog.api.persistence.BlogPersistenceService"/> - - -</blueprint> diff --git a/samples/blog/blog-persistence-jpa/pom.xml b/samples/blog/blog-persistence-jpa/pom.xml index 6cb158160..9ad3284e1 100644 --- a/samples/blog/blog-persistence-jpa/pom.xml +++ b/samples/blog/blog-persistence-jpa/pom.xml @@ -75,7 +75,19 @@ </execution> </executions> </plugin> - + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <configuration> + <namespaces> + <namespace>http://aries.apache.org/xmlns/jpa/v1.0.0</namespace> + <namespace>http://aries.apache.org/xmlns/transactions/v1.2.0</namespace> + </namespaces> + <customParameters> + <transaction.enableAnnotation>false</transaction.enableAnnotation> + </customParameters> + </configuration> + </plugin> </plugins> </build> @@ -122,6 +134,21 @@ </dependency> <!-- end OpenJPA PCEnhancer depends --> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.transaction</groupId> + <artifactId>javax.transaction-api</artifactId> + <optional>true</optional> + </dependency> </dependencies> </project> diff --git a/samples/blog/blog-persistence-jpa/src/main/java/org/apache/aries/samples/blog/persistence/jpa/BlogPersistenceServiceImpl.java b/samples/blog/blog-persistence-jpa/src/main/java/org/apache/aries/samples/blog/persistence/jpa/BlogPersistenceServiceImpl.java index 18e8ca4f1..0bc4be4a6 100644 --- a/samples/blog/blog-persistence-jpa/src/main/java/org/apache/aries/samples/blog/persistence/jpa/BlogPersistenceServiceImpl.java +++ b/samples/blog/blog-persistence-jpa/src/main/java/org/apache/aries/samples/blog/persistence/jpa/BlogPersistenceServiceImpl.java @@ -25,8 +25,13 @@ import java.util.Date; import java.util.List; import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import javax.persistence.Query; +import javax.transaction.Transactional; +import org.apache.aries.blueprint.annotation.bean.Activation; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.samples.blog.api.persistence.BlogPersistenceService; import org.apache.aries.samples.blog.api.persistence.Entry; import org.apache.aries.samples.blog.persistence.jpa.entity.AuthorImpl; @@ -35,35 +40,34 @@ import org.apache.aries.samples.blog.persistence.jpa.entity.EntryImpl; /** * This class is the implementation of the blogPersistenceService */ +@Service(classes = BlogPersistenceService.class) +@Transactional(Transactional.TxType.REQUIRED) +@Bean(activation = Activation.LAZY) public class BlogPersistenceServiceImpl implements BlogPersistenceService { - private EntityManager em; - - public BlogPersistenceServiceImpl() { - } + @PersistenceContext(unitName = "blogExample") + EntityManager entityManager; - - public void setEntityManager(EntityManager e) { - em = e; - } - + public void setEntityManager(EntityManager entityManager) { + this.entityManager = entityManager; + } - public void createAuthor(String email, Date dob, String name, - String displayName, String bio) { + public void createAuthor(String email, Date dob, String name, + String displayName, String bio) { AuthorImpl a = new AuthorImpl(); a.setEmail(email); a.setName(name); a.setDisplayName(displayName); a.setBio(bio); a.setDob(dob); - em.persist(a); + entityManager.persist(a); } public void createBlogPost(String authorEmail, String title, String blogText, List<String> tags) { - AuthorImpl a = em.find(AuthorImpl.class, authorEmail); + AuthorImpl a = entityManager.find(AuthorImpl.class, authorEmail); EntryImpl b = new EntryImpl(); Date publishDate = new Date(System.currentTimeMillis()); @@ -75,12 +79,12 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { b.setTags((tags == null) ? new ArrayList<String>() : tags); a.updateEntries(b); - em.persist(b); - em.merge(b.getAuthor()); + entityManager.persist(b); + entityManager.merge(b.getAuthor()); } public Entry findBlogEntryByTitle(String title) { - Query q = em + Query q = entityManager .createQuery("SELECT e FROM BLOGENTRY e WHERE e.title = ?1"); q.setParameter(1, title); Entry b = (Entry) q.getSingleResult(); @@ -89,7 +93,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { public List<AuthorImpl> getAllAuthors() { @SuppressWarnings("unchecked") - List<AuthorImpl> list = em.createQuery("SELECT a FROM AUTHOR a") + List<AuthorImpl> list = entityManager.createQuery("SELECT a FROM AUTHOR a") .getResultList(); return list; @@ -97,7 +101,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { public List<EntryImpl> getAllBlogEntries() { @SuppressWarnings("unchecked") - List<EntryImpl> list = em.createQuery( + List<EntryImpl> list = entityManager.createQuery( "SELECT b FROM BLOGENTRY b ORDER BY b.publishDate DESC") .getResultList(); return list; @@ -105,13 +109,13 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { } public int getNoOfBlogEntries() { - Number n = (Number) em.createQuery( + Number n = (Number) entityManager.createQuery( "SELECT COUNT(b) FROM BLOGENTRY b").getSingleResult(); return n.intValue(); } public List<EntryImpl> getBlogEntries(int firstPostIndex, int noOfPosts) { - Query q = em + Query q = entityManager .createQuery("SELECT b FROM BLOGENTRY b ORDER BY b.publishDate DESC"); q.setFirstResult(firstPostIndex); q.setMaxResults(noOfPosts); @@ -123,12 +127,12 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { } public AuthorImpl getAuthor(String emailAddress) { - AuthorImpl a = em.find(AuthorImpl.class, emailAddress); + AuthorImpl a = entityManager.find(AuthorImpl.class, emailAddress); return a; } public List<EntryImpl> getBlogEntriesModifiedBetween(Date start, Date end) { - Query q = em + Query q = entityManager .createQuery("SELECT b FROM BLOGENTRY b WHERE (b.updatedDate >= :start AND b.updatedDate <= :end) OR (b.publishDate >= :start AND b.publishDate <= :end) ORDER BY b.publishDate ASC"); q.setParameter("start", start); q.setParameter("end", end); @@ -141,7 +145,7 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { public List<EntryImpl> getBlogsForAuthor(String emailAddress) { - List<EntryImpl> list = em.find(AuthorImpl.class, emailAddress) + List<EntryImpl> list = entityManager.find(AuthorImpl.class, emailAddress) .getEntries(); return list; @@ -150,56 +154,56 @@ public class BlogPersistenceServiceImpl implements BlogPersistenceService { public void updateAuthor(String email, Date dob, String name, String displayName, String bio) { - AuthorImpl a = em.find(AuthorImpl.class, email); + AuthorImpl a = entityManager.find(AuthorImpl.class, email); a.setEmail(email); a.setName(name); a.setDisplayName(displayName); a.setBio(bio); a.setDob(dob); - em.merge(a); + entityManager.merge(a); } public void updateBlogEntry(long id, String email, String title, String blogText, List<String> tags, Date updatedDate) { - EntryImpl b = em.find(EntryImpl.class, id); + EntryImpl b = entityManager.find(EntryImpl.class, id); b.setTitle(title); b.setBlogText(blogText); b.setTags(tags); b.setUpdatedDate(updatedDate); - em.merge(b); + entityManager.merge(b); } public void removeAuthor(String emailAddress) { - em.remove(em.find(AuthorImpl.class, emailAddress)); + entityManager.remove(entityManager.find(AuthorImpl.class, emailAddress)); } public void removeBlogEntry(long id) { - EntryImpl b = em.find(EntryImpl.class, id); - b = em.merge(b); + EntryImpl b = entityManager.find(EntryImpl.class, id); + b = entityManager.merge(b); b.getAuthor().getEntries().remove(b); - em.remove(em.merge(b)); - em.merge(b.getAuthor()); + entityManager.remove(entityManager.merge(b)); + entityManager.merge(b.getAuthor()); } public EntryImpl getBlogEntryById(long postId) { - EntryImpl b = em.find(EntryImpl.class, postId); + EntryImpl b = entityManager.find(EntryImpl.class, postId); return b; } public void setPublishDate (long postId, Date date) { //Added for testing - EntryImpl b = em.find(EntryImpl.class, postId); + EntryImpl b = entityManager.find(EntryImpl.class, postId); b.setPublishDate(date); - em.merge(b); + entityManager.merge(b); } public void setUpdatedDate (long postId, Date date) { //Added for testing - EntryImpl b = em.find(EntryImpl.class, postId); + EntryImpl b = entityManager.find(EntryImpl.class, postId); b.setUpdatedDate(date); - em.merge(b); + entityManager.merge(b); } } diff --git a/samples/blog/blog-persistence-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/samples/blog/blog-persistence-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index ef2a1dfb1..000000000 --- a/samples/blog/blog-persistence-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - <!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version - 2.0 (the "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 Unless required by - applicable law or agreed to in writing, software distributed under the - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the - License. - --> - -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" - xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" - default-activation="lazy"> - - <bean id="persistenceImpl" - class="org.apache.aries.samples.blog.persistence.jpa.BlogPersistenceServiceImpl"> - <tx:transaction method="*" value="Required" /> - <jpa:context property="entityManager" unitname="blogExample" /> - </bean> - - <service ref="persistenceImpl" - interface="org.apache.aries.samples.blog.api.persistence.BlogPersistenceService"> - </service> - -</blueprint> diff --git a/samples/blueprint/helloworld/helloworld-api/src/main/java/org/apache/aries/samples/blueprint/helloworld/api/HelloWorldService.java b/samples/blueprint/helloworld/helloworld-api/src/main/java/org/apache/aries/samples/blueprint/helloworld/api/HelloWorldService.java index 2fb4af5ee..52bcc934b 100644 --- a/samples/blueprint/helloworld/helloworld-api/src/main/java/org/apache/aries/samples/blueprint/helloworld/api/HelloWorldService.java +++ b/samples/blueprint/helloworld/helloworld-api/src/main/java/org/apache/aries/samples/blueprint/helloworld/api/HelloWorldService.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -20,7 +20,7 @@ package org.apache.aries.samples.blueprint.helloworld.api; public interface HelloWorldService { - public void hello(); + void hello(); - public void startUp(); + void startUp(); } diff --git a/samples/blueprint/helloworld/helloworld-client/pom.xml b/samples/blueprint/helloworld/helloworld-client/pom.xml index 85dc95df6..30013882c 100644 --- a/samples/blueprint/helloworld/helloworld-client/pom.xml +++ b/samples/blueprint/helloworld/helloworld-client/pom.xml @@ -40,13 +40,28 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> </plugins> </build> + <dependencies> <dependency> <groupId>org.apache.aries.samples.blueprint.helloworld</groupId> <artifactId>org.apache.aries.samples.blueprint.helloworld.api</artifactId> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> </dependencies> </project> diff --git a/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java b/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java index cea424cbc..8d3446d9f 100644 --- a/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java +++ b/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,26 +18,33 @@ */ package org.apache.aries.samples.blueprint.helloworld.client; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.samples.blueprint.helloworld.api.HelloWorldService; +import javax.inject.Inject; + +@Bean(initMethod = "startUp") public class HelloWorldClient { - HelloWorldService helloWorldService = null; + HelloWorldService helloWorldService = null; - public void startUp() { - System.out.println("========>>>>Client HelloWorld: About to execute a method from the Hello World service"); - helloWorldService.hello(); - System.out.println("========>>>>Client HelloWorld: ... if you didn't just see a Hello World message something went wrong"); - } + public void startUp() { + System.out.println("========>>>>Client HelloWorld: About to execute a method from the Hello World service"); + helloWorldService.hello(); + System.out.println("========>>>>Client HelloWorld: ... if you didn't just see a Hello World message something went wrong"); + } - public HelloWorldService getHelloWorldService() { - return helloWorldService; - } + public HelloWorldService getHelloWorldService() { + return helloWorldService; + } - public void setHelloWorldService(HelloWorldService helloWorldService) { - this.helloWorldService = helloWorldService; + @Inject + @Reference + public void setHelloWorldService(HelloWorldService helloWorldService) { + this.helloWorldService = helloWorldService; - } + } } diff --git a/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml b/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml deleted file mode 100644 index daa74105b..000000000 --- a/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> - <!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version - 2.0 (the "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 Unless required by - applicable law or agreed to in writing, software distributed under the - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the - License. - --> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - - <reference id="helloservice" - interface="org.apache.aries.samples.blueprint.helloworld.api.HelloWorldService" /> - - - <bean id="helloclient" class="org.apache.aries.samples.blueprint.helloworld.client.HelloWorldClient" - init-method="startUp"> - <property name="helloWorldService" ref="helloservice" /> - </bean> -</blueprint> diff --git a/samples/blueprint/helloworld/helloworld-server/pom.xml b/samples/blueprint/helloworld/helloworld-server/pom.xml index 734529923..32ed4f938 100644 --- a/samples/blueprint/helloworld/helloworld-server/pom.xml +++ b/samples/blueprint/helloworld/helloworld-server/pom.xml @@ -47,13 +47,28 @@ </instructions> </configuration> </plugin> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + </plugin> </plugins> </build> + <dependencies> <dependency> <groupId>org.apache.aries.samples.blueprint.helloworld</groupId> <artifactId>org.apache.aries.samples.blueprint.helloworld.api</artifactId> </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <optional>true</optional> + </dependency> </dependencies> </project> diff --git a/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java b/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java index 3c3b012e3..a53fb65af 100644 --- a/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java +++ b/samples/blueprint/helloworld/helloworld-server/src/main/java/org/apache/aries/samples/blueprint/helloworld/server/HelloWorldServiceImpl.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -17,17 +17,22 @@ * under the License. */ package org.apache.aries.samples.blueprint.helloworld.server; -import org.apache.aries.samples.blueprint.helloworld.api.*; +import org.apache.aries.blueprint.annotation.bean.Bean; +import org.apache.aries.blueprint.annotation.service.Service; +import org.apache.aries.samples.blueprint.helloworld.api.HelloWorldService; + +@Service +@Bean(initMethod = "startUp") public class HelloWorldServiceImpl implements HelloWorldService { - public void hello() { - System.out.println("======>>> A message from the server: Hello World!"); - } + public void hello() { + System.out.println("======>>> A message from the server: Hello World!"); + } - public void startUp() { - System.out.println("======>>> Starting HelloWorld Server"); - } + public void startUp() { + System.out.println("======>>> Starting HelloWorld Server"); + } } \ No newline at end of file diff --git a/samples/blueprint/helloworld/helloworld-server/src/main/resources/OSGI-INF/blueprint/config.xml b/samples/blueprint/helloworld/helloworld-server/src/main/resources/OSGI-INF/blueprint/config.xml deleted file mode 100644 index ec39e8638..000000000 --- a/samples/blueprint/helloworld/helloworld-server/src/main/resources/OSGI-INF/blueprint/config.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> - <!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version - 2.0 (the "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 Unless required by - applicable law or agreed to in writing, software distributed under the - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the - License. - --> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - - <bean id="helloservice" - class="org.apache.aries.samples.blueprint.helloworld.server.HelloWorldServiceImpl" - init-method="startUp"> - </bean> - - <service ref="helloservice" - interface="org.apache.aries.samples.blueprint.helloworld.api.HelloWorldService" /> - -</blueprint> diff --git a/samples/blueprint/idverifier/idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml b/samples/blueprint/idverifier/idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml index ef1772050..c62da4981 100644 --- a/samples/blueprint/idverifier/idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml +++ b/samples/blueprint/idverifier/idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml @@ -48,74 +48,6 @@ <idref component-id="bankinfo" /> </property> -<!-- Inlined service does not work--> -<!-- <property name="svcreg4cro">--> -<!-- <service auto-export="disabled"--> -<!-- ranking="100">--> -<!-- <description>Inlined service about querying credit records.</description>--> -<!-- <interfaces>--> -<!-- <value>org.apache.aries.samples.blueprint.idverifier.api.CreditRecordOperation</value>--> -<!-- </interfaces>--> -<!-- <service-properties>--> -<!-- <entry key="mode" value="formal"> --> -<!-- </entry>--> -<!-- </service-properties>--> -<!-- <registration-listener --> -<!-- registration-method="reg" unregistration-method="unreg">--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditQueryRegistrationListener">--> -<!-- <description>Inlined service registration bean</description> --> -<!-- </bean>--> -<!-- </registration-listener>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordOperationImpl">--> -<!-- <description>Inlined bean for CreditRecordOperation interface implementation</description>--> -<!-- <argument index="0">--> -<!-- <description>inlined bean for CreditRecordStore</description>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordStore">--> -<!-- <argument index="0">--> -<!-- <set>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordFactory"--> -<!-- factory-method="staticCreateBean">--> -<!-- <argument>--> -<!-- <value>310115197011076874:003:2009-12-30:good:4rd donation to charity.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean factory-ref="creditrecordfactory" factory-method="dynamicCreateBean">--> -<!-- <argument>--> -<!-- <value>310115197011076874:004:2009-12-18:good:3rd donation to charity.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">--> -<!-- <argument>--> -<!-- <value>310115197011277844:001:2009-12-29:good:Donation to charity</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">--> -<!-- <argument>--> -<!-- <value>310115197011277844:002:2009-12-01:bad:No pay to bill.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">--> -<!-- <argument>--> -<!-- <value>110108197710016853:002:2009-12-02:good:Paied the bill.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">--> -<!-- <argument>--> -<!-- <value>110108197710016853:001:1977-10-01:good:I'm born.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">--> -<!-- <argument>--> -<!-- <value>11010819541001366X:001:1954-10-01:good:I'm born.</value>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- </set>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- </argument>--> -<!-- </bean>--> -<!-- </service>--> -<!-- </property>--> <property name="cro"> <bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordOperationImpl"> <description>Inlined bean for CreditRecordOperation interface implementation</description> diff --git a/samples/pom.xml b/samples/pom.xml index 94860397f..f8ca7b44e 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -133,11 +133,17 @@ <!-- Aries bundle dependencies--> <asm.version>9.7.1</asm.version> + <javax.annotation-api.version>1.3.2</javax.annotation-api.version> + <javax.inject.version>1</javax.inject.version> + <javax.persistence-api.version>2.2</javax.persistence-api.version> + <javax.transaction-api.version>1.2</javax.transaction-api.version> <osgi.core.version>8.0.0</osgi.core.version> <slf4j.version>1.7.36</slf4j.version> <pax-logging.version>1.11.17</pax-logging.version> <!-- Aries dependencies --> + <blueprint-maven-plugin-annotation.version>1.3.0</blueprint-maven-plugin-annotation.version> + <blueprint-maven-plugin.version>1.10.0</blueprint-maven-plugin.version> <org.apache.aries.blueprint.api.version>1.0.1</org.apache.aries.blueprint.api.version> <org.apache.aries.blueprint.cm.version>1.3.2</org.apache.aries.blueprint.cm.version> <org.apache.aries.blueprint.core.version>1.10.3</org.apache.aries.blueprint.core.version> @@ -518,9 +524,61 @@ <artifactId>org.apache.aries.util</artifactId> <version>${org.apache.aries.util.version}</version> </dependency> + + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin-annotation</artifactId> + <version>${blueprint-maven-plugin-annotation.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>${javax.inject.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.transaction</groupId> + <artifactId>javax.transaction-api</artifactId> + <version>${javax.transaction-api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>javax.persistence-api</artifactId> + <version>${javax.persistence-api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>${javax.annotation-api.version}</version> + <scope>provided</scope> + </dependency> </dependencies> </dependencyManagement> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <version>${blueprint-maven-plugin.version}</version> + <executions> + <execution> + <phase>process-classes</phase> + <goals> + <goal>add-resource-dir</goal> + <goal>blueprint-generate</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> + <modules> <module>ariestrader</module> <module>blog</module>
