/*
* (c) Copyright 2005-2012 JAXIO, www.jaxio.com
* Source code generated by Celerio, a Jaxio product
* Want to use Celerio within your company? email us at info@jaxio.com
* Follow us on twitter: @springfuse
* Template pack-backend-sd:src/main/java/project/repository/support/JpaUtil.p.vm.java
*/
package com.company.demo.repository.support;
import static java.lang.reflect.Modifier.isPublic;
import java.lang.reflect.Method;
import javax.persistence.EmbeddedId;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
public abstract class JpaUtil {
public static boolean isEntityIdManuallyAssigned(Class<?> type) {
for (Method method : type.getMethods()) {
if (isPrimaryKey(method)) {
return isManuallyAssigned(method);
}
}
return false; // no pk found, should not happen
}
private static boolean isPrimaryKey(Method method) {
return isPublic(method.getModifiers())
&& (method.getAnnotation(Id.class) != null || method.getAnnotation(EmbeddedId.class) != null);
}
private static boolean isManuallyAssigned(Method method) {
if (method.getAnnotation(Id.class) != null) {
return method.getAnnotation(GeneratedValue.class) == null;
} else if (method.getAnnotation(EmbeddedId.class) != null) {
return true;
} else {
return true;
}
}
}