Skip to content

Commit 46cbb72

Browse files
author
eugenp
committed
started work on search - introducing the JPA 2 metamodel
1 parent e4c34f5 commit 46cbb72

6 files changed

Lines changed: 144 additions & 29 deletions

File tree

‎eclipse/BUILD.launch‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<listEntry value="persistenceTarget=mysql"/>
1111
</listAttribute>
1212
<stringAttribute key="M2_RUNTIME" value="/opt/maven/instances/apache-maven-3.0.4"/>
13-
<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
13+
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
1414
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
1515
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
1616
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/rest}"/>

‎eclipse/INTEGRATION-SINGLE.launch‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
33
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4-
<listEntry value="/rest/src/test/java/org/rest/sec/persistence/service/RoleServicePersistenceIntegrationTest.java"/>
4+
<listEntry value="/rest/src/test/java/org/rest/sec/web/privilege/PrivilegeLogicRESTIntegrationTest.java"/>
55
</listAttribute>
66
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
77
<listEntry value="1"/>
@@ -12,10 +12,10 @@
1212
</mapAttribute>
1313
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
1414
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
15-
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value="givenEntityExistsWithAssociationScenarios_whenDeletingEverything_thenNoException"/>
15+
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value="whenResourcesAreRetrieved_thenResourcesAreCorrectlyRetrieved"/>
1616
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
1717
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
18-
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.persistence.service.RoleServicePersistenceIntegrationTest"/>
18+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.web.privilege.PrivilegeLogicRESTIntegrationTest"/>
1919
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="rest"/>
2020
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
2121
</launchConfiguration>

‎pom.xml‎

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,16 @@
157157
<!-- persistence - query -->
158158

159159
<!-- Querydsl -->
160-
<dependency>
161-
<groupId>com.mysema.querydsl</groupId>
162-
<artifactId>querydsl-core</artifactId>
163-
<version>${querydsl.version}</version>
164-
</dependency>
160+
<!--(temporarily disabled) -->
161+
<!-- <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-core</artifactId> <version>${querydsl.version}</version> </dependency>
162+
<dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>${querydsl.version}</version> </dependency>
163+
<dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> <version>${querydsl.version}</version> </dependency> -->
165164

165+
<!-- persistence - JPA 2 metamodel -->
166166
<dependency>
167-
<groupId>com.mysema.querydsl</groupId>
168-
<artifactId>querydsl-apt</artifactId>
169-
<version>${querydsl.version}</version>
170-
</dependency>
171-
172-
<dependency>
173-
<groupId>com.mysema.querydsl</groupId>
174-
<artifactId>querydsl-jpa</artifactId>
175-
<version>${querydsl.version}</version>
167+
<groupId>org.hibernate</groupId>
168+
<artifactId>hibernate-jpamodelgen</artifactId>
169+
<version>1.2.0.CR1</version>
176170
</dependency>
177171

178172
<!-- logging -->
@@ -246,7 +240,6 @@
246240
<groupId>org.apache.commons</groupId>
247241
<artifactId>commons-lang3</artifactId>
248242
<version>${commons-lang3.version}</version>
249-
<scope>test</scope>
250243
</dependency>
251244

252245
<dependency>
@@ -304,6 +297,7 @@
304297
<configuration>
305298
<source>1.6</source>
306299
<target>1.6</target>
300+
<compilerArgument>-proc:none</compilerArgument>
307301
</configuration>
308302
</plugin>
309303

@@ -340,6 +334,52 @@
340334
</executions>
341335
</plugin>
342336

337+
338+
<!-- Querydsl - used to generate metadata -->
339+
<!--(temporarily disabled) -->
340+
<!-- <plugin> <groupId>com.mysema.maven</groupId> <artifactId>maven-apt-plugin</artifactId> <version>1.0.2</version> <executions> <execution>
341+
<phase>generate-sources</phase> <goals> <goal>process</goal> </goals> <configuration> <outputDirectory>target/generated-sources</outputDirectory>
342+
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor> </configuration> </execution> </executions> </plugin> -->
343+
344+
<!-- JPA 2 metamodel -->
345+
<!-- -->
346+
<plugin>
347+
<groupId>org.bsc.maven</groupId>
348+
<artifactId>maven-processor-plugin</artifactId>
349+
<version>2.0.5</version>
350+
<executions>
351+
<execution>
352+
<id>process</id>
353+
<goals>
354+
<goal>process</goal>
355+
</goals>
356+
<phase>generate-sources</phase>
357+
<configuration>
358+
source output directory
359+
<outputDirectory>target/metamodel</outputDirectory>
360+
</configuration>
361+
</execution>
362+
</executions>
363+
</plugin>
364+
<plugin>
365+
<groupId>org.codehaus.mojo</groupId>
366+
<artifactId>build-helper-maven-plugin</artifactId>
367+
<version>1.7</version>
368+
<executions>
369+
<execution>
370+
<id>add-source</id>
371+
<phase>generate-sources</phase>
372+
<goals>
373+
<goal>add-source</goal>
374+
</goals>
375+
<configuration>
376+
<sources>
377+
<source>target/metamodel</source>
378+
</sources>
379+
</configuration>
380+
</execution>
381+
</executions>
382+
</plugin>
343383
</plugins>
344384

345385
<!-- generated by m2e -->
@@ -372,6 +412,45 @@
372412
<ignore></ignore>
373413
</action>
374414
</pluginExecution>
415+
<pluginExecution>
416+
<pluginExecutionFilter>
417+
<groupId>com.mysema.maven</groupId>
418+
<artifactId>maven-apt-plugin</artifactId>
419+
<versionRange>[1.0.2,)</versionRange>
420+
<goals>
421+
<goal>process</goal>
422+
</goals>
423+
</pluginExecutionFilter>
424+
<action>
425+
<ignore></ignore>
426+
</action>
427+
</pluginExecution>
428+
<pluginExecution>
429+
<pluginExecutionFilter>
430+
<groupId>org.bsc.maven</groupId>
431+
<artifactId>maven-processor-plugin</artifactId>
432+
<versionRange>[2.0.5,)</versionRange>
433+
<goals>
434+
<goal>process</goal>
435+
</goals>
436+
</pluginExecutionFilter>
437+
<action>
438+
<ignore></ignore>
439+
</action>
440+
</pluginExecution>
441+
<pluginExecution>
442+
<pluginExecutionFilter>
443+
<groupId>org.codehaus.mojo</groupId>
444+
<artifactId>build-helper-maven-plugin</artifactId>
445+
<versionRange>[1.3,)</versionRange>
446+
<goals>
447+
<goal>add-source</goal>
448+
</goals>
449+
</pluginExecutionFilter>
450+
<action>
451+
<ignore></ignore>
452+
</action>
453+
</pluginExecution>
375454
</pluginExecutions>
376455
</lifecycleMappingMetadata>
377456
</configuration>

‎src/main/java/org/rest/persistence/service/AbstractService.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public void delete( final long id ){
9191
this.getDao().delete( id );
9292
}
9393

94+
// search
95+
96+
public List< T > search(){
97+
// getDao().
98+
return null;
99+
}
100+
94101
//
95102
protected abstract PagingAndSortingRepository< T, Long > getDao();
96103

‎src/main/java/org/rest/sec/persistence/dao/IPrivilegeJpaDAO.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import org.rest.sec.model.Privilege;
44
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
56

6-
public interface IPrivilegeJpaDAO extends JpaRepository< Privilege, Long >{
7+
public interface IPrivilegeJpaDAO extends JpaRepository< Privilege, Long >, JpaSpecificationExecutor< Privilege >{
78

89
Privilege findByName( final String name );
910

‎src/test/java/org/rest/testing/marshaller/JacksonMarshaller.java‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package org.rest.testing.marshaller;
22

33
import java.io.IOException;
4+
import java.util.List;
45

56
import org.codehaus.jackson.JsonParseException;
67
import org.codehaus.jackson.map.JsonMappingException;
78
import org.codehaus.jackson.map.ObjectMapper;
9+
import org.codehaus.jackson.type.TypeReference;
810
import org.slf4j.Logger;
911
import org.slf4j.LoggerFactory;
1012
import org.springframework.http.MediaType;
1113
import org.springframework.stereotype.Component;
1214

1315
import com.google.common.base.Preconditions;
16+
import com.google.common.collect.Lists;
1417

1518
@Component( "jacksonMarshaller" )
1619
public final class JacksonMarshaller implements IMarshaller{
@@ -33,10 +36,16 @@ public final < T >String encode( final T entity ){
3336
try{
3437
entityAsJSON = objectMapper.writeValueAsString( entity );
3538
}
36-
catch( final Exception ex ){
37-
logger.error( "", ex );
39+
catch( final JsonParseException parseEx ){
40+
logger.error( "", parseEx );
3841
}
39-
42+
catch( final JsonMappingException mappingEx ){
43+
logger.error( "", mappingEx );
44+
}
45+
catch( final IOException ioEx ){
46+
logger.error( "", ioEx );
47+
}
48+
4049
return entityAsJSON;
4150
}
4251

@@ -48,19 +57,38 @@ public final < T >T decode( final String entityAsString, final Class< T > clazz
4857
try{
4958
entity = objectMapper.readValue( entityAsString, clazz );
5059
}
51-
catch( final JsonParseException e ){
52-
e.printStackTrace();
60+
catch( final JsonParseException parseEx ){
61+
logger.error( "", parseEx );
5362
}
54-
catch( final JsonMappingException e ){
55-
e.printStackTrace();
63+
catch( final JsonMappingException mappingEx ){
64+
logger.error( "", mappingEx );
5665
}
57-
catch( final IOException e ){
58-
e.printStackTrace();
66+
catch( final IOException ioEx ){
67+
logger.error( "", ioEx );
5968
}
6069

6170
return entity;
6271
}
6372

73+
public final < T >List< T > decodeList( final String entitiesAsString ){
74+
try{
75+
return objectMapper.readValue( entitiesAsString, new TypeReference< List< T >>(){
76+
// ...
77+
} );
78+
}
79+
catch( final JsonParseException parseEx ){
80+
logger.error( "", parseEx );
81+
}
82+
catch( final JsonMappingException mappingEx ){
83+
logger.error( "", mappingEx );
84+
}
85+
catch( final IOException ioEx ){
86+
logger.error( "", ioEx );
87+
}
88+
89+
return Lists.newArrayList();
90+
}
91+
6492
@Override
6593
public final String getMime(){
6694
return MediaType.APPLICATION_JSON.toString();

0 commit comments

Comments
 (0)