BAEL-202: Consolidated Couchbase SDK and Spring Data Couchbase from five modules down to two

This commit is contained in:
Kevin Gilmore 2016-10-01 21:25:26 -05:00
parent 1c742b5f44
commit 78998f1d20
86 changed files with 254 additions and 1582 deletions

View File

@ -1 +0,0 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.7.3.201602250914-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
</configs>
<autoconfigs>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@ -1,9 +0,0 @@
package com.baeldung.couchbase;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages={"com.baeldung.couchbase"})
public class IntegrationTestConfig {
}

View File

@ -1 +0,0 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip

View File

@ -1,233 +0,0 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# 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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=$(cd "$wdir/.."; pwd)
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} "$@"

View File

@ -1,145 +0,0 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
set MAVEN_CMD_LINE_ARGS=%*
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>couchbase-sdk-intro</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>couchbase-sdk-intro</name>
<description>Intro to the Couchbase SDK</description>
<dependencies>
<!-- Couchbase SDK -->
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>${couchbase.client.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<couchbase.client.version>2.2.6</couchbase.client.version>
</properties>
</project>

View File

@ -1 +0,0 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip

View File

@ -1,233 +0,0 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# 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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=$(cd "$wdir/.."; pwd)
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} "$@"

View File

@ -1,145 +0,0 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
set MAVEN_CMD_LINE_ARGS=%*
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%

View File

@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>couchbase-sdk-spring-service</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>couchbase-sdk-spring-service</name>
<description>Intro to the Couchbase SDK</description>
<dependencies>
<!-- Couchbase SDK -->
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>${couchbase.client.version}</version>
</dependency>
<!-- Spring Context for Dependency Injection -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- Test-Scoped Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<couchbase.client.version>2.2.6</couchbase.client.version>
<spring-framework.version>4.2.4.RELEASE</spring-framework.version>
<logback.version>1.1.3</logback.version>
<org.slf4j.version>1.7.12</org.slf4j.version>
<junit.version>4.11</junit.version>
<commons-lang3.version>3.4</commons-lang3.version>
</properties>
</project>

View File

@ -1,31 +0,0 @@
package com.baeldung.couchbase.person;
import org.springframework.stereotype.Service;
import com.baeldung.couchbase.service.JsonDocumentConverter;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
@Service
public class FluentPersonDocumentConverter implements JsonDocumentConverter<Person> {
@Override
public JsonDocument toDocument(Person p) {
JsonObject content = JsonObject.empty()
.put("type", "Person")
.put("name", p.getName())
.put("homeTown", p.getHomeTown());
return JsonDocument.create(p.getId(), content);
}
@Override
public Person fromDocument(JsonDocument doc) {
JsonObject content = doc.content();
return Person.Builder.newInstance()
.id(doc.id())
.type("Person")
.name(content.getString("name"))
.homeTown(content.getString("homeTown"))
.build();
}
}

View File

@ -1,17 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="com.baeldung" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

50
couchbase-sdk/README.md Normal file
View File

@ -0,0 +1,50 @@
## Couchbase SDK Tutorial Project
### Relevant Articles:
- [Introduction to Couchbase SDK for Java](http://www.baeldung.com/java-couchbase-sdk)
- [Using Couchbase in a Spring Application](http://www.baeldung.com/couchbase-sdk-spring)
- [Asynchronous Batch Opereations in Couchbase](http://www.baeldung.com/async-batch-operations-in-couchbase)
### Overview
This Maven project contains the Java code for the Couchbase entities and Spring services
as described in the tutorials, as well as a unit/integration test
for each service implementation.
### Working with the Code
The project was developed and tested using Java 7 and 8 in the Eclipse-based
Spring Source Toolkit (STS) and therefore should run fine in any
recent version of Eclipse or another IDE of your choice
that supports Java 7 or later.
### Building the Project
You can also build the project using Maven outside of any IDE:
```
mvn clean install
```
### Package Organization
Java classes for the intro tutorial are in the
org.baeldung.couchbase.intro package.
Java classes for the Spring service tutorial are in the
org.baeldung.couchbase.spring package hierarchy.
Java classes for the Asynchronous Couchbase tutorial are in the
org.baeldung.couchbase.async package hierarchy.
### Running the tests
The test classes for the Spring service tutorial are:
- org.baeldung.couchbase.spring.service.ClusterServiceTest
- org.baeldung.couchbase.spring.person.PersonCrudServiceTest
The test classes for the Asynchronous Couchbase tutorial are in the
org.baeldung.couchbase.async package hierarchy:
- org.baeldung.couchbase.async.service.ClusterServiceTest
- org.baeldung.couchbase.async.person.PersonCrudServiceTest
The test classes may be run as JUnit tests from your IDE
or using the Maven command line:
```
mvn test
```

View File

@ -3,11 +3,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>couchbase-sdk-async</artifactId>
<artifactId>couchbase-sdk</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>couchbase-sdk-async</name>
<description>Couchbase SDK Asynchronous Operations</description>
<name>couchbase-sdk</name>
<description>Couchbase SDK Tutorials</description>
<dependencies>
<!-- Couchbase SDK -->

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async;
public interface CouchbaseEntity {

View File

@ -1,6 +1,6 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.async.person;
import com.baeldung.couchbase.service.CouchbaseEntity;
import com.baeldung.couchbase.async.CouchbaseEntity;
public class Person implements CouchbaseEntity {

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.async.person;
import javax.annotation.PostConstruct;
@ -6,8 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.baeldung.couchbase.service.AbstractCrudService;
import com.baeldung.couchbase.service.BucketService;
import com.baeldung.couchbase.async.service.AbstractCrudService;
import com.baeldung.couchbase.async.service.BucketService;
@Service
public class PersonCrudService extends AbstractCrudService<Person> {

View File

@ -1,8 +1,8 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.async.person;
import org.springframework.stereotype.Service;
import com.baeldung.couchbase.service.JsonDocumentConverter;
import com.baeldung.couchbase.async.service.JsonDocumentConverter;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.async.person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import com.couchbase.client.java.Bucket;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import java.util.ArrayList;
import java.util.List;
@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.couchbase.async.CouchbaseEntity;
import com.couchbase.client.core.BackpressureException;
import com.couchbase.client.core.time.Delay;
import com.couchbase.client.java.AsyncBucket;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import com.couchbase.client.java.Bucket;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import com.couchbase.client.java.Bucket;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import com.couchbase.client.java.document.JsonDocument;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import javax.annotation.PostConstruct;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.examples;
package com.baeldung.couchbase.intro;
import java.util.List;
import java.util.UUID;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.spring.person;
public class Person {

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.spring.person;
import java.util.List;
import java.util.UUID;
@ -8,8 +8,9 @@ import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.couchbase.service.CrudService;
import com.baeldung.couchbase.service.TutorialBucketService;import com.couchbase.client.java.Bucket;
import com.baeldung.couchbase.spring.service.CrudService;
import com.baeldung.couchbase.spring.service.TutorialBucketService;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.ReplicaMode;
import com.couchbase.client.java.document.JsonDocument;

View File

@ -1,8 +1,8 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.spring.person;
import org.springframework.stereotype.Service;
import com.baeldung.couchbase.service.JsonDocumentConverter;
import com.baeldung.couchbase.spring.service.JsonDocumentConverter;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.spring.person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import com.couchbase.client.java.Bucket;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
public interface CrudService<T> {

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import com.couchbase.client.java.document.JsonDocument;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import javax.annotation.PostConstruct;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase;
package com.baeldung.couchbase.async;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { IntegrationTestConfig.class })
@ContextConfiguration(classes = { AsyncIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public abstract class IntegrationTest {
public abstract class AsyncIntegrationTest {
}

View File

@ -0,0 +1,9 @@
package com.baeldung.couchbase.async;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages={"com.baeldung.couchbase.async"})
public class AsyncIntegrationTestConfig {
}

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.async.person;
import static org.junit.Assert.*;
@ -13,12 +13,15 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.baeldung.couchbase.IntegrationTest;
import com.baeldung.couchbase.service.BucketService;
import com.baeldung.couchbase.async.AsyncIntegrationTest;
import com.baeldung.couchbase.async.person.Person;
import com.baeldung.couchbase.async.person.PersonCrudService;
import com.baeldung.couchbase.async.person.PersonDocumentConverter;
import com.baeldung.couchbase.async.service.BucketService;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument;
public class PersonCrudServiceTest extends IntegrationTest {
public class PersonCrudServiceTest extends AsyncIntegrationTest {
@Autowired
private PersonCrudService personService;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.async.service;
import static org.junit.Assert.*;
@ -10,14 +10,15 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import com.baeldung.couchbase.IntegrationTest;
import com.baeldung.couchbase.IntegrationTestConfig;
import com.baeldung.couchbase.async.AsyncIntegrationTest;
import com.baeldung.couchbase.async.AsyncIntegrationTestConfig;
import com.baeldung.couchbase.async.service.ClusterService;
import com.couchbase.client.java.Bucket;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { IntegrationTestConfig.class })
@ContextConfiguration(classes = { AsyncIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public class ClusterServiceTest extends IntegrationTest {
public class ClusterServiceTest extends AsyncIntegrationTest {
@Autowired
private ClusterService couchbaseService;

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase;
package com.baeldung.couchbase.spring;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;

View File

@ -1,9 +1,9 @@
package com.baeldung.couchbase;
package com.baeldung.couchbase.spring;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages={"com.baeldung.couchbase"})
@ComponentScan(basePackages={"com.baeldung.couchbase.spring"})
public class IntegrationTestConfig {
}

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.person;
package com.baeldung.couchbase.spring.person;
import static org.junit.Assert.*;
@ -8,7 +8,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.baeldung.couchbase.IntegrationTest;
import com.baeldung.couchbase.spring.IntegrationTest;
public class PersonCrudServiceTest extends IntegrationTest {

View File

@ -1,4 +1,4 @@
package com.baeldung.couchbase.service;
package com.baeldung.couchbase.spring.service;
import static org.junit.Assert.*;
@ -10,8 +10,8 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import com.baeldung.couchbase.IntegrationTest;
import com.baeldung.couchbase.IntegrationTestConfig;
import com.baeldung.couchbase.spring.IntegrationTest;
import com.baeldung.couchbase.spring.IntegrationTestConfig;
import com.couchbase.client.java.Bucket;
@RunWith(SpringJUnit4ClassRunner.class)

View File

@ -19,8 +19,7 @@
<module>autovalue-tutorial</module>
<module>core-java</module>
<module>core-java-8</module>
<module>couchbase-sdk-intro</module>
<module>couchbase-sdk-spring-service</module>
<module>couchbase-sdk</module>
<module>dependency-injection</module>
<module>gatling</module>
@ -61,7 +60,6 @@
<module>spring-cucumber</module>
<module>spring-data-cassandra</module>
<module>spring-data-couchbase-2</module>
<module>spring-data-couchbase-2b</module>
<module>spring-data-elasticsearch</module>
<module>spring-data-neo4j</module>
<module>spring-data-mongodb</module>

View File

@ -3,6 +3,7 @@
### Relevant Articles:
- [Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
- [Entity Validation, Query Consistency, and Optimistic Locking in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
- [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries)
### Overview
This Maven project contains the Java code for Spring Data Couchbase
@ -11,7 +12,7 @@ as described in the tutorials, as well as a unit/integration test
for each service implementation.
### Working with the Code
The project was developed and tested using Java 7 nad 8 in the Eclipse-based
The project was developed and tested using Java 7 and 8 in the Eclipse-based
Spring Source Toolkit (STS) and therefore should run fine in any
recent version of Eclipse or another IDE of your choice
that supports Java 7 or later.
@ -22,8 +23,15 @@ You can also build the project using Maven outside of any IDE:
mvn clean install
```
### Package Organization
Java classes for the first two tutorials listed above are in src/main/java in the package hierarchy
org.baeldung.spring.data.couchbase
Java classes for the multiple-bucket tutorials are in src/main/java in the package hierarchy
org.baeldung.spring.data.couchbase2b
### Running the tests
The following test classes are in src/test/java in the package
The test classes for the single-bucket tutorials are in src/test/java in the package
org.baeldung.spring.data.couchbase.service:
- PersonServiceTest (abstract)
- PersonRepositoryTest (concrete)
@ -32,6 +40,12 @@ org.baeldung.spring.data.couchbase.service:
- StudentRepositoryTest (concrete)
- StudentTemplateServiceTest (concrete)
The concrete test classes for the multiple-bucket tutorial are in src/test/java in the package
org.baeldung.spring.data.couchbase2b.service:
- CampusRepositoryServiceImplTest
- PersonRepositoryServiceImplTest
- StudentRepositoryServiceImplTest
The concrete test classes may be run as JUnit tests from your IDE
or using the Maven command line:
```

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.repos;
package org.baeldung.spring.data.couchbase2b.repos;
import java.util.Set;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.repos;
package org.baeldung.spring.data.couchbase2b.repos;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.repos;
package org.baeldung.spring.data.couchbase2b.repos;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.Set;

View File

@ -1,20 +1,18 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.baeldung.spring.data.couchbase.model.Campus;
import org.baeldung.spring.data.couchbase.repos.CampusRepository;
import org.baeldung.spring.data.couchbase2b.repos.CampusRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Point;
import org.springframework.stereotype.Service;
@Service
@Qualifier("CampusRepositoryService")
public class CampusRepositoryService implements CampusService {
public class CampusServiceImpl implements CampusService {
private CampusRepository repo;
@Autowired

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.List;

View File

@ -1,20 +1,18 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.baeldung.spring.data.couchbase.model.Person;
import org.baeldung.spring.data.couchbase.repos.PersonRepository;
import org.baeldung.spring.data.couchbase2b.repos.PersonRepository;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
@Qualifier("PersonRepositoryService")
public class PersonRepositoryService implements PersonService {
public class PersonServiceImpl implements PersonService {
private PersonRepository repo;
@Autowired
public void setPersonRepository(PersonRepository repo) {

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.List;

View File

@ -1,20 +1,18 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.baeldung.spring.data.couchbase.model.Student;
import org.baeldung.spring.data.couchbase.repos.StudentRepository;
import org.baeldung.spring.data.couchbase2b.repos.StudentRepository;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
@Qualifier("StudentRepositoryService")
public class StudentRepositoryService implements StudentService {
public class StudentServiceImpl implements StudentService {
private StudentRepository repo;
@Autowired
public void setStudentRepository(StudentRepository repo) {

View File

@ -1,17 +1,11 @@
package org.baeldung.spring.data.couchbase;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.query.Consistency;
public class TestCouchbaseConfig extends MyCouchbaseConfig {
public class CustomTypeKeyCouchbaseConfig extends MyCouchbaseConfig {
@Override
public String typeKey() {
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
}
@Override
public Consistency getDefaultConsistency() {
return Consistency.READ_YOUR_OWN_WRITES;
}
}

View File

@ -0,0 +1,11 @@
package org.baeldung.spring.data.couchbase;
import org.springframework.data.couchbase.core.query.Consistency;
public class ReadYourOwnWritesCouchbaseConfig extends MyCouchbaseConfig {
@Override
public Consistency getDefaultConsistency() {
return Consistency.READ_YOUR_OWN_WRITES;
}
}

View File

@ -83,13 +83,6 @@ public abstract class PersonServiceTest extends IntegrationTest {
assertTrue(allResultsContainExpectedLastName(resultList, expectedLastName));
}
@Test
public void whenFindingByFirstNameJohn_thenReturnsOnePersonNamedJohn() {
final String expectedFirstName = john;
final List<Person> resultList = personService.findByFirstName(expectedFirstName);
assertTrue(resultList.size() == 1);
}
private boolean resultContains(List<Person> resultList, Person person) {
boolean found = false;
for (final Person p : resultList) {

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase;
package org.baeldung.spring.data.couchbase2b;
import java.util.Arrays;
import java.util.List;
@ -17,9 +17,9 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import com.couchbase.client.java.Bucket;
@Configuration
@EnableCouchbaseRepositories(basePackages={"org.baeldung.spring.data.couchbase"})
public class MyCouchbaseConfig extends AbstractCouchbaseConfiguration {
@EnableCouchbaseRepositories(basePackages = { "org.baeldung.spring.data.couchbase2b" })
public class MultiBucketCouchbaseConfig extends AbstractCouchbaseConfiguration {
public static final List<String> NODE_LIST = Arrays.asList("localhost");
public static final String DEFAULT_BUCKET_NAME = "baeldung";
public static final String DEFAULT_BUCKET_PASSWORD = "";
@ -44,11 +44,13 @@ public class MyCouchbaseConfig extends AbstractCouchbaseConfiguration {
return couchbaseCluster().openBucket("baeldung2", "");
}
@Bean
@Bean(name = "campusTemplate")
public CouchbaseTemplate campusTemplate() throws Exception {
CouchbaseTemplate template = new CouchbaseTemplate(
couchbaseClusterInfo(), campusBucket(),
mappingCouchbaseConverter(), translationService());
couchbaseClusterInfo(),
campusBucket(),
mappingCouchbaseConverter(),
translationService());
template.setDefaultConsistency(getDefaultConsistency());
return template;
}

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase;
package org.baeldung.spring.data.couchbase2b;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
@ -7,7 +7,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MyCouchbaseConfig.class, IntegrationTestConfig.class })
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public abstract class IntegrationTest {
public abstract class MultiBucketIntegationTest {
}

View File

@ -0,0 +1,10 @@
package org.baeldung.spring.data.couchbase2b;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = { "org.baeldung.spring.data.couchbase2b" })
public class MultiBucketIntegrationTestConfig {
}

View File

@ -1,26 +1,27 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.baeldung.spring.data.couchbase.IntegrationTest;
import org.baeldung.spring.data.couchbase.model.Campus;
import org.baeldung.spring.data.couchbase.repos.CampusRepository;
import org.baeldung.spring.data.couchbase2b.MultiBucketIntegationTest;
import org.baeldung.spring.data.couchbase2b.repos.CampusRepository;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
public class CampusRepositoryServiceTest extends IntegrationTest {
public class CampusServiceImplTest extends MultiBucketIntegationTest {
@Autowired
@Qualifier("CampusRepositoryService")
private CampusRepositoryService campusService;
private CampusServiceImpl campusService;
@Autowired
private CampusRepository campusRepo;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -7,14 +7,13 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import org.baeldung.spring.data.couchbase.IntegrationTest;
import org.baeldung.spring.data.couchbase.MyCouchbaseConfig;
import org.baeldung.spring.data.couchbase.model.Person;
import org.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
import org.baeldung.spring.data.couchbase2b.MultiBucketIntegationTest;
import org.joda.time.DateTime;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
@ -22,37 +21,28 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
public class PersonRepositoryServiceTest extends IntegrationTest {
public class PersonServiceImplTest extends MultiBucketIntegationTest {
private static final String typeField = "_class";
private static final String john = "John";
private static final String smith = "Smith";
private static final String johnSmithId = "person:" + john + ":" + smith;
private static final Person johnSmith = new Person(johnSmithId, john, smith);
private static final JsonObject jsonJohnSmith = JsonObject.empty()
.put(typeField, Person.class.getName())
.put("firstName", john)
.put("lastName", smith)
.put("created", DateTime.now().getMillis());
static final String typeField = "_class";
static final String john = "John";
static final String smith = "Smith";
static final String johnSmithId = "person:" + john + ":" + smith;
static final Person johnSmith = new Person(johnSmithId, john, smith);
static final JsonObject jsonJohnSmith = JsonObject.empty().put(typeField, Person.class.getName()).put("firstName", john).put("lastName", smith).put("created", DateTime.now().getMillis());
static final String foo = "Foo";
static final String bar = "Bar";
static final String foobarId = "person:" + foo + ":" + bar;
static final Person foobar = new Person(foobarId, foo, bar);
static final JsonObject jsonFooBar = JsonObject.empty().put(typeField, Person.class.getName()).put("firstName", foo).put("lastName", bar).put("created", DateTime.now().getMillis());
private static final String foo = "Foo";
private static final String bar = "Bar";
private static final String foobarId = "person:" + foo + ":" + bar;
private static final Person foobar = new Person(foobarId, foo, bar);
private static final JsonObject jsonFooBar = JsonObject.empty()
.put(typeField, Person.class.getName())
.put("firstName", foo)
.put("lastName", bar)
.put("created", DateTime.now().getMillis());
@Autowired
@Qualifier("PersonRepositoryService")
private PersonService personService;
private PersonServiceImpl personService;
@BeforeClass
public static void setupBeforeClass() {
Cluster cluster = CouchbaseCluster.create(MyCouchbaseConfig.NODE_LIST);
Bucket bucket = cluster.openBucket(MyCouchbaseConfig.DEFAULT_BUCKET_NAME, MyCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
final Cluster cluster = CouchbaseCluster.create(MultiBucketCouchbaseConfig.NODE_LIST);
final Bucket bucket = cluster.openBucket(MultiBucketCouchbaseConfig.DEFAULT_BUCKET_NAME, MultiBucketCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
bucket.upsert(JsonDocument.create(johnSmithId, jsonJohnSmith));
bucket.upsert(JsonDocument.create(foobarId, jsonFooBar));
bucket.close();
@ -61,7 +51,7 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
@Test
public void whenFindingPersonByJohnSmithId_thenReturnsJohnSmith() {
Person actualPerson = personService.findOne(johnSmithId);
final Person actualPerson = personService.findOne(johnSmithId);
assertNotNull(actualPerson);
assertNotNull(actualPerson.getCreated());
assertEquals(johnSmith, actualPerson);
@ -69,7 +59,7 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
@Test
public void whenFindingAllPersons_thenReturnsTwoOrMorePersonsIncludingJohnSmithAndFooBar() {
List<Person> resultList = personService.findAll();
final List<Person> resultList = personService.findAll();
assertNotNull(resultList);
assertFalse(resultList.isEmpty());
assertTrue(resultContains(resultList, johnSmith));
@ -79,8 +69,8 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
@Test
public void whenFindingByFirstNameJohn_thenReturnsOnlyPersonsNamedJohn() {
String expectedFirstName = john;
List<Person> resultList = personService.findByFirstName(expectedFirstName);
final String expectedFirstName = john;
final List<Person> resultList = personService.findByFirstName(expectedFirstName);
assertNotNull(resultList);
assertFalse(resultList.isEmpty());
assertTrue(allResultsContainExpectedFirstName(resultList, expectedFirstName));
@ -88,17 +78,17 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
@Test
public void whenFindingByLastNameSmith_thenReturnsOnlyPersonsNamedSmith() {
String expectedLastName = smith;
List<Person> resultList = personService.findByLastName(expectedLastName);
final String expectedLastName = smith;
final List<Person> resultList = personService.findByLastName(expectedLastName);
assertNotNull(resultList);
assertFalse(resultList.isEmpty());
assertTrue(allResultsContainExpectedLastName(resultList, expectedLastName));
}
private boolean resultContains(List<Person> resultList, Person person) {
boolean found = false;
for(Person p : resultList) {
if(p.equals(person)) {
for (final Person p : resultList) {
if (p.equals(person)) {
found = true;
break;
}
@ -108,8 +98,8 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
private boolean allResultsContainExpectedFirstName(List<Person> resultList, String firstName) {
boolean found = false;
for(Person p : resultList) {
if(p.getFirstName().equals(firstName)) {
for (final Person p : resultList) {
if (p.getFirstName().equals(firstName)) {
found = true;
break;
}
@ -119,8 +109,8 @@ public class PersonRepositoryServiceTest extends IntegrationTest {
private boolean allResultsContainExpectedLastName(List<Person> resultList, String lastName) {
boolean found = false;
for(Person p : resultList) {
if(p.getLastName().equals(lastName)) {
for (final Person p : resultList) {
if (p.getLastName().equals(lastName)) {
found = true;
break;
}

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.couchbase.service;
package org.baeldung.spring.data.couchbase2b.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -9,14 +9,13 @@ import java.util.List;
import javax.validation.ConstraintViolationException;
import org.baeldung.spring.data.couchbase.IntegrationTest;
import org.baeldung.spring.data.couchbase.MyCouchbaseConfig;
import org.baeldung.spring.data.couchbase.model.Student;
import org.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
import org.baeldung.spring.data.couchbase2b.MultiBucketIntegationTest;
import org.joda.time.DateTime;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
@ -24,47 +23,46 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
public class StudentRepositoryServiceTest extends IntegrationTest {
public class StudentServiceImplTest extends MultiBucketIntegationTest {
private static final String typeField = "_class";
private static final String joe = "Joe";
private static final String college = "College";
private static final String joeCollegeId = "student:" + joe + ":" + college;
private static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
private static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
private static final JsonObject jsonJoeCollege = JsonObject.empty()
static final String typeField = "_class";
static final String joe = "Joe";
static final String college = "College";
static final String joeCollegeId = "student:" + joe + ":" + college;
static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
static final JsonObject jsonJoeCollege = JsonObject.empty()
.put(typeField, Student.class.getName())
.put("firstName", joe)
.put("lastName", college)
.put("created", DateTime.now().getMillis())
.put("version", 1);
private static final String judy = "Judy";
private static final String jetson = "Jetson";
private static final String judyJetsonId = "student:" + judy + ":" + jetson;
private static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
private static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
private static final JsonObject jsonJudyJetson = JsonObject.empty()
static final String judy = "Judy";
static final String jetson = "Jetson";
static final String judyJetsonId = "student:" + judy + ":" + jetson;
static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
static final JsonObject jsonJudyJetson = JsonObject.empty()
.put(typeField, Student.class.getName())
.put("firstName", judy)
.put("lastName", jetson)
.put("created", DateTime.now().getMillis())
.put("version", 1);
@Autowired
@Qualifier("StudentRepositoryService")
private StudentService studentService;
StudentServiceImpl studentService;
@BeforeClass
public static void setupBeforeClass() {
Cluster cluster = CouchbaseCluster.create(MyCouchbaseConfig.NODE_LIST);
Bucket bucket = cluster.openBucket(MyCouchbaseConfig.DEFAULT_BUCKET_NAME, MyCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
Cluster cluster = CouchbaseCluster.create(MultiBucketCouchbaseConfig.NODE_LIST);
Bucket bucket = cluster.openBucket(MultiBucketCouchbaseConfig.DEFAULT_BUCKET_NAME, MultiBucketCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
bucket.upsert(JsonDocument.create(joeCollegeId, jsonJoeCollege));
bucket.upsert(JsonDocument.create(judyJetsonId, jsonJudyJetson));
bucket.close();
cluster.disconnect();
}
@Test
public void whenCreatingStudent_thenDocumentIsPersisted() {
String firstName = "Eric";
@ -134,7 +132,7 @@ public class StudentRepositoryServiceTest extends IntegrationTest {
assertFalse(resultList.isEmpty());
assertTrue(allResultsContainExpectedLastName(resultList, expectedLastName));
}
private boolean resultContains(List<Student> resultList, Student student) {
boolean found = false;
for(Student p : resultList) {

View File

@ -1,36 +0,0 @@
## Spring Data Couchbase Tutorial Project
### Relevant Articles:
- [Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
- [Entity Validation, Query Consistency, and Optimistic Locking in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
### Overview
This Maven project contains the Java code for Spring Data Couchbase
entities, repositories, and repository-based services
as described in the tutorials, as well as a unit/integration test
for each service implementation.
### Working with the Code
The project was developed and tested using Java 7 and 8 in the Eclipse-based
Spring Source Toolkit (STS) and therefore should run fine in any
recent version of Eclipse or another IDE of your choice
that supports Java 7 or later.
### Building the Project
You can also build the project using Maven outside of any IDE:
```
mvn clean install
```
### Running the tests
The following test classes are in src/test/java in the package
org.baeldung.spring.data.couchbase.service:
- CampusRepositoryServiceTest
- PersonRepositoryServiceTest
- StudentRepositoryServiceTest
These may be run as JUnit tests from your IDE
or using the Maven command line:
```
mvn test
```

View File

@ -1,105 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>spring-data-couchbase-2b</artifactId>
<version>0.1-SNAPSHOT</version>
<name>spring-data-couchbase-2b</name>
<packaging>jar</packaging>
<dependencies>
<!-- Spring Context and Couchbase Peristence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>${spring-data-couchbase.version}</version>
</dependency>
<!-- Hibernate JSR-303 Bean Validation -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- Test-Scoped Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-framework.version>4.2.4.RELEASE</spring-framework.version>
<spring-data-couchbase.version>2.1.1.RELEASE</spring-data-couchbase.version>
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
<joda-time.version>2.9.2</joda-time.version>
<logback.version>1.1.3</logback.version>
<org.slf4j.version>1.7.12</org.slf4j.version>
<junit.version>4.11</junit.version>
</properties>
</project>

View File

@ -1,87 +0,0 @@
package org.baeldung.spring.data.couchbase.model;
import javax.validation.constraints.NotNull;
import org.joda.time.DateTime;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import com.couchbase.client.java.repository.annotation.Field;
@Document
public class Person {
@Id
private String id;
@Field
@NotNull
private String firstName;
@Field
@NotNull
private String lastName;
@Field
@NotNull
private DateTime created;
@Field
private DateTime updated;
public Person(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public DateTime getCreated() {
return created;
}
public void setCreated(DateTime created) {
this.created = created;
}
public DateTime getUpdated() {
return updated;
}
public void setUpdated(DateTime updated) {
this.updated = updated;
}
@Override
public int hashCode() {
int hash = 1;
if(id != null) {
hash = hash * 31 + id.hashCode();
}
if(firstName != null) {
hash = hash * 31 + firstName.hashCode();
}
if(lastName != null) {
hash = hash * 31 + lastName.hashCode();
}
return hash;
}
@Override
public boolean equals(Object obj) {
if((obj == null) || (obj.getClass() != this.getClass())) return false;
if(obj == this) return true;
Person other = (Person) obj;
return this.hashCode() == other.hashCode();
}
}

View File

@ -1,113 +0,0 @@
package org.baeldung.spring.data.couchbase.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.joda.time.DateTime;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.couchbase.core.mapping.Document;
import com.couchbase.client.java.repository.annotation.Field;
@Document
public class Student {
private static final String NAME_REGEX = "^[a-zA-Z .'-]+$";
@Id
private String id;
@Field
@NotNull
@Size(min=1, max=20)
@Pattern(regexp=NAME_REGEX)
private String firstName;
@Field
@NotNull
@Size(min=1, max=20)
@Pattern(regexp=NAME_REGEX)
private String lastName;
@Field
@Past
private DateTime dateOfBirth;
@Field
@NotNull
private DateTime created;
@Field
private DateTime updated;
@Version
private long version;
public Student() {}
public Student(String id, String firstName, String lastName, DateTime dateOfBirth) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public DateTime getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(DateTime dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public DateTime getCreated() {
return created;
}
public void setCreated(DateTime created) {
this.created = created;
}
public DateTime getUpdated() {
return updated;
}
public void setUpdated(DateTime updated) {
this.updated = updated;
}
@Override
public int hashCode() {
int hash = 1;
if(id != null) {
hash = hash * 31 + id.hashCode();
}
if(firstName != null) {
hash = hash * 31 + firstName.hashCode();
}
if(lastName != null) {
hash = hash * 31 + lastName.hashCode();
}
if(dateOfBirth != null) {
hash = hash * 31 + dateOfBirth.hashCode();
}
return hash;
}
@Override
public boolean equals(Object obj) {
if((obj == null) || (obj.getClass() != this.getClass())) return false;
if(obj == this) return true;
Student other = (Student) obj;
return this.hashCode() == other.hashCode();
}
}

View File

@ -1,17 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="org.baeldung" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Spring Batch: ${project.name}">
<bannerLeft>
<name>Spring Sample: ${project.name}</name>
<href>index.html</href>
</bannerLeft>
<skin>
<groupId>org.springframework.maven.skins</groupId>
<artifactId>maven-spring-skin</artifactId>
<version>1.0.5</version>
</skin>
<body>
<links>
<item name="${project.name}" href="index.html"/>
</links>
<menu ref="reports"/>
</body>
</project>

View File

@ -1,9 +0,0 @@
package org.baeldung.spring.data.couchbase;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = "org.baeldung.spring.data.couchbase")
public class IntegrationTestConfig {
}

View File

@ -1,17 +0,0 @@
package org.baeldung.spring.data.couchbase;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.query.Consistency;
public class TestCouchbaseConfig extends MyCouchbaseConfig {
@Override
public String typeKey() {
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
}
@Override
public Consistency getDefaultConsistency() {
return Consistency.READ_YOUR_OWN_WRITES;
}
}

View File

@ -1,17 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="org.baeldung" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>