Java Examples for org.hibernate.annotations.GenericGenerator
The following java examples will help you to understand the usage of org.hibernate.annotations.GenericGenerator. These source code samples are taken from different open source projects.
Example 1
| Project: openmicroscopy-master File: SequencesTest.java View source code |
@BeforeClass
public void setup() {
gg = Image.class.getAnnotation(GenericGenerator.class);
seq_name = gg.name();
incr_value = -999990000;
for (Parameter parameter : gg.parameters()) {
if (parameter.name().equals("increment_size")) {
incr_value = Integer.valueOf(parameter.value());
break;
}
}
}Example 2
| Project: deadcode4j-master File: HibernateAnnotationsAnalyzer.java View source code |
private void processGenericGenerator(AnalysisContext analysisContext, CtClass clazz, Annotation annotation) {
String className = clazz.getName();
Optional<String> resolvedStrategyClass = classPoolAccessorFor(analysisContext).resolveClass(getMandatoryStringFrom(annotation, "strategy"));
if (resolvedStrategyClass.isPresent()) {
analysisContext.addDependencies(className, resolvedStrategyClass.get());
}
String generatorName = getMandatoryStringFrom(annotation, "name");
String previousEntry = this.generatorDefinitions.put(generatorName, className);
if (previousEntry != null) {
logger.warn("The @GenericGenerator named [{}] is defined both by {} and {}.", generatorName, previousEntry, className);
}
}Example 3
| Project: jeffaschenk-commons-master File: PlatformSequenceGenerator.java View source code |
// **************************************
// Private Helper Methods
// **************************************
/**
* Obtain the Identity Sequence which we are to
* use based upon the getId method for the specified Class.
*/
private String obtainIdentitySequence(Class<? extends RootElement> clazz) {
// *************************************
// Obtain the getID method for this
// RootElement Entity Class.
Method getIDMethod = null;
try {
getIDMethod = clazz.getMethod("getId", new Class<?>[] {});
} catch (NoSuchMethodException nsme) {
log.error("Illegal Object Class:[" + clazz.getName() + "] no Method Specified for getId()!");
throw new IllegalArgumentException("The Specified Object has no getId() method signature!");
}
if (getIDMethod == null) {
log.error("Illegal Object Class:[" + clazz.getName() + "] no Method Specified for getId()!");
throw new IllegalArgumentException("The Specified Object has no getId() method signature!");
}
// **************************************
// Determine the Sequence we need to use
// for this RootElement Class from the
// specified annotation.
String annotationString = null;
AnnotationParser annotationParser = new AnnotationParser();
Map<String, String> methodAnnotations = annotationParser.parseSpecificClassMethodAnnotations(getIDMethod);
if (log.isDebugEnabled()) {
for (String key : methodAnnotations.keySet()) {
log.debug("Annotation Mapping Key:[" + key + "], Value:[" + methodAnnotations.get(key) + "]");
}
}
if (methodAnnotations != null) {
annotationString = methodAnnotations.get("getId:org.hibernate.annotations.GenericGenerator.parameters");
}
if (annotationString == null) {
log.error("Illegal Object Class:[" + clazz.getName() + "] no valid Annotations found for getId() method, unable to determine Sequence Name!");
throw new IllegalArgumentException("Illegal Object Class:[" + clazz.getName() + "] no valid Annotations found for getId() method, unable to determine Sequence Name!");
}
// **************************************
// Now Parse The Annotation String
String[] array = annotationString.split("value=|\\)|}");
if (log.isDebugEnabled()) {
log.debug("Parsing Annotation String:[" + annotationString + "]");
for (int i = 0; i < array.length; i++) {
log.debug("Array[" + i + "]:[" + array[i] + "]");
}
}
if ((array == null) || (array.length <= 1) || (array[1] == null) || (array[1].isEmpty())) {
log.error("Illegal Object Class:[" + clazz.getName() + "] no valid Annotation Found Sequence Value found in :[" + annotationString + "], for getId() method, unable to determine Sequence Name!");
throw new IllegalArgumentException("Illegal Object Class:[" + clazz.getName() + "] no valid Annotation Found Sequence Value found in:[" + annotationString + "], for getId() method, unable to determine Sequence Name!");
}
String sequenceName = array[1];
if (log.isDebugEnabled()) {
log.debug("Parsed Sequence Name:[" + sequenceName + "]");
}
// Return the Sequence Name to use for this Identity.
return sequenceName;
}Example 4
| Project: Broadleaf-eCommerce-master File: SequenceGeneratorCorruptionDetection.java View source code |
@Override
@Transactional("blTransactionManager")
public void onApplicationEvent(ContextRefreshedEvent event) {
if (detectSequenceGeneratorInconsistencies) {
SessionFactory sessionFactory = ((HibernateEntityManager) em).getSession().getSessionFactory();
for (Object item : sessionFactory.getAllClassMetadata().values()) {
ClassMetadata metadata = (ClassMetadata) item;
String idProperty = metadata.getIdentifierPropertyName();
Class<?> mappedClass = metadata.getMappedClass();
Field idField;
try {
idField = mappedClass.getDeclaredField(idProperty);
} catch (NoSuchFieldException e) {
continue;
}
idField.setAccessible(true);
GenericGenerator genericAnnot = idField.getAnnotation(GenericGenerator.class);
TableGenerator tableAnnot = idField.getAnnotation(TableGenerator.class);
String segmentValue = null;
String tableName = null;
String segmentColumnName = null;
String valueColumnName = null;
if (genericAnnot != null && genericAnnot.strategy().equals(IdOverrideTableGenerator.class.getName())) {
//This is a BLC style ID generator
for (Parameter param : genericAnnot.parameters()) {
if (param.name().equals("segment_value")) {
segmentValue = param.value();
}
if (param.name().equals("table_name")) {
tableName = param.value();
}
if (param.name().equals("segment_column_name")) {
segmentColumnName = param.value();
}
if (param.name().equals("value_column_name")) {
valueColumnName = param.value();
}
}
// to redefine them. If they aren't defined in the annotation, glean them from the defaults
if (StringUtils.isBlank(tableName)) {
tableName = IdOverrideTableGenerator.DEFAULT_TABLE_NAME;
}
if (StringUtils.isBlank(segmentColumnName)) {
segmentColumnName = IdOverrideTableGenerator.DEFAULT_SEGMENT_COLUMN_NAME;
}
if (StringUtils.isBlank(valueColumnName)) {
valueColumnName = IdOverrideTableGenerator.DEFAULT_VALUE_COLUMN_NAME;
}
} else if (tableAnnot != null) {
//This is a traditional Hibernate generator
segmentValue = tableAnnot.pkColumnValue();
tableName = tableAnnot.table();
segmentColumnName = tableAnnot.pkColumnName();
valueColumnName = tableAnnot.valueColumnName();
}
if (!StringUtils.isEmpty(segmentValue) && !StringUtils.isEmpty(tableName) && !StringUtils.isEmpty(segmentColumnName) && !StringUtils.isEmpty(valueColumnName)) {
StringBuilder sb2 = new StringBuilder();
sb2.append("select ");
sb2.append(valueColumnName);
sb2.append(" from ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
sb2.append(tableName);
sb2.append(" where ");
sb2.append(segmentColumnName);
sb2.append(" = '");
sb2.append(segmentValue);
sb2.append("'");
Long maxSequenceId = 0l;
boolean sequenceEntryExists = false;
List results2 = em.createNativeQuery(sb2.toString()).getResultList();
if (CollectionUtils.isNotEmpty(results2) && results2.get(0) != null) {
maxSequenceId = ((Number) results2.get(0)).longValue();
sequenceEntryExists = true;
}
LOG.info("Detecting id sequence state between " + mappedClass.getName() + " and " + segmentValue + " in " + tableName);
StringBuilder sb = new StringBuilder();
sb.append("select max(");
sb.append(idField.getName());
sb.append(") from ");
sb.append(mappedClass.getName());
sb.append(" entity");
List results;
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
try {
context.setInternalIgnoreFilters(true);
results = em.createQuery(sb.toString()).getResultList();
} finally {
context.setInternalIgnoreFilters(false);
}
if (CollectionUtils.isNotEmpty(results) && results.get(0) != null) {
Long maxEntityId = (Long) results.get(0);
if (maxEntityId > maxSequenceId) {
LOG.error(String.format("The sequence value for %s in %s was found as %d (or an entry did not exist) but the actual max sequence in" + " %s's table was found as %d", segmentValue, tableName, maxSequenceId, mappedClass.getName(), maxEntityId));
if (automaticallyCorrectInconsistencies) {
long newMaxId = maxEntityId + 10;
if (sequenceEntryExists) {
String log = String.format("Correcting sequences for entity %s. Updating the sequence value" + " to %d", mappedClass.getName(), newMaxId);
LOG.warn(log);
StringBuilder updateQuery = new StringBuilder();
updateQuery.append("update ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
updateQuery.append(tableName);
updateQuery.append(" set ");
updateQuery.append(valueColumnName);
updateQuery.append(" = ");
updateQuery.append(String.valueOf(newMaxId));
updateQuery.append(" where ");
updateQuery.append(segmentColumnName);
updateQuery.append(" = '");
updateQuery.append(segmentValue);
updateQuery.append("'");
int response = em.createNativeQuery(updateQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
} else {
String log = String.format("Correcting sequences for entity %s. Did not find an entry in" + " %s, inserting the new sequence value as %d", mappedClass.getName(), tableName, newMaxId);
LOG.warn(log);
StringBuilder insertQuery = new StringBuilder();
insertQuery.append("insert into ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
insertQuery.append(tableName);
insertQuery.append(" (" + segmentColumnName + "," + valueColumnName + ")");
insertQuery.append("values ('" + segmentValue + "','" + String.valueOf(newMaxId) + "')");
int response = em.createNativeQuery(insertQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
}
} else {
String reason = "A data inconsistency has been detected between the " + tableName + " table and one or more entity tables for which it manages current max primary key values.\n" + "The inconsistency was detected between the managed class (" + mappedClass.getName() + ") and the identifier (" + segmentValue + ") in " + tableName + ". Broadleaf\n" + "has stopped startup of the application in order to allow you to resolve the issue and avoid possible data corruption. If you wish to disable this detection, you may\n" + "set the 'detect.sequence.generator.inconsistencies' property to false in your application's common.properties or common-shared.properties. If you would like for this component\n" + "to autocorrect these problems by setting the sequence generator value to a value greater than the max entity id, then set the 'auto.correct.sequence.generator.inconsistencies'\n" + "property to true in your application's common.properties or common-shared.properties. If you would like to provide a default schema to be used to qualify table names used in the\n" + "queries for this detection, set the 'default.schema.sequence.generator' property in your application's common.properties or common-shared.properties. Also, if you are upgrading\n" + "from 1.6 or below, please refer to http://docs.broadleafcommerce.org/current/1.6-to-2.0-Migration.html for important information regarding migrating your SEQUENCE_GENERATOR table.";
LOG.error("Broadleaf Commerce failed to start", new RuntimeException(reason));
System.exit(1);
}
}
}
}
}
}
}Example 5
| Project: BroadleafCommerce-master File: SequenceGeneratorCorruptionDetection.java View source code |
@Override
@Transactional("blTransactionManager")
public void onApplicationEvent(ContextRefreshedEvent event) {
if (detectSequenceGeneratorInconsistencies) {
SessionFactory sessionFactory = ((HibernateEntityManager) em).getSession().getSessionFactory();
for (Object item : sessionFactory.getAllClassMetadata().values()) {
ClassMetadata metadata = (ClassMetadata) item;
String idProperty = metadata.getIdentifierPropertyName();
Class<?> mappedClass = metadata.getMappedClass();
Field idField;
try {
idField = mappedClass.getDeclaredField(idProperty);
} catch (NoSuchFieldException e) {
continue;
}
idField.setAccessible(true);
GenericGenerator genericAnnot = idField.getAnnotation(GenericGenerator.class);
TableGenerator tableAnnot = idField.getAnnotation(TableGenerator.class);
String segmentValue = null;
String tableName = null;
String segmentColumnName = null;
String valueColumnName = null;
if (genericAnnot != null && genericAnnot.strategy().equals(IdOverrideTableGenerator.class.getName())) {
//This is a BLC style ID generator
for (Parameter param : genericAnnot.parameters()) {
if (param.name().equals("segment_value")) {
segmentValue = param.value();
}
if (param.name().equals("table_name")) {
tableName = param.value();
}
if (param.name().equals("segment_column_name")) {
segmentColumnName = param.value();
}
if (param.name().equals("value_column_name")) {
valueColumnName = param.value();
}
}
// to redefine them. If they aren't defined in the annotation, glean them from the defaults
if (StringUtils.isBlank(tableName)) {
tableName = IdOverrideTableGenerator.DEFAULT_TABLE_NAME;
}
if (StringUtils.isBlank(segmentColumnName)) {
segmentColumnName = IdOverrideTableGenerator.DEFAULT_SEGMENT_COLUMN_NAME;
}
if (StringUtils.isBlank(valueColumnName)) {
valueColumnName = IdOverrideTableGenerator.DEFAULT_VALUE_COLUMN_NAME;
}
} else if (tableAnnot != null) {
//This is a traditional Hibernate generator
segmentValue = tableAnnot.pkColumnValue();
tableName = tableAnnot.table();
segmentColumnName = tableAnnot.pkColumnName();
valueColumnName = tableAnnot.valueColumnName();
}
if (!StringUtils.isEmpty(segmentValue) && !StringUtils.isEmpty(tableName) && !StringUtils.isEmpty(segmentColumnName) && !StringUtils.isEmpty(valueColumnName)) {
StringBuilder sb2 = new StringBuilder();
sb2.append("select ");
sb2.append(valueColumnName);
sb2.append(" from ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
sb2.append(tableName);
sb2.append(" where ");
sb2.append(segmentColumnName);
sb2.append(" = '");
sb2.append(segmentValue);
sb2.append("'");
Long maxSequenceId = 0l;
boolean sequenceEntryExists = false;
List results2 = em.createNativeQuery(sb2.toString()).getResultList();
if (CollectionUtils.isNotEmpty(results2) && results2.get(0) != null) {
maxSequenceId = ((Number) results2.get(0)).longValue();
sequenceEntryExists = true;
}
LOG.info("Detecting id sequence state between " + mappedClass.getName() + " and " + segmentValue + " in " + tableName);
StringBuilder sb = new StringBuilder();
sb.append("select max(");
sb.append(idField.getName());
sb.append(") from ");
sb.append(mappedClass.getName());
sb.append(" entity");
List results;
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
try {
context.setInternalIgnoreFilters(true);
results = em.createQuery(sb.toString()).getResultList();
} finally {
context.setInternalIgnoreFilters(false);
}
if (CollectionUtils.isNotEmpty(results) && results.get(0) != null) {
Long maxEntityId = (Long) results.get(0);
if (maxEntityId > maxSequenceId) {
LOG.error(String.format("The sequence value for %s in %s was found as %d (or an entry did not exist) but the actual max sequence in" + " %s's table was found as %d", segmentValue, tableName, maxSequenceId, mappedClass.getName(), maxEntityId));
if (automaticallyCorrectInconsistencies) {
long newMaxId = maxEntityId + 10;
if (sequenceEntryExists) {
String log = String.format("Correcting sequences for entity %s. Updating the sequence value" + " to %d", mappedClass.getName(), newMaxId);
LOG.warn(log);
StringBuilder updateQuery = new StringBuilder();
updateQuery.append("update ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
updateQuery.append(tableName);
updateQuery.append(" set ");
updateQuery.append(valueColumnName);
updateQuery.append(" = ");
updateQuery.append(String.valueOf(newMaxId));
updateQuery.append(" where ");
updateQuery.append(segmentColumnName);
updateQuery.append(" = '");
updateQuery.append(segmentValue);
updateQuery.append("'");
int response = em.createNativeQuery(updateQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
} else {
String log = String.format("Correcting sequences for entity %s. Did not find an entry in" + " %s, inserting the new sequence value as %d", mappedClass.getName(), tableName, newMaxId);
LOG.warn(log);
StringBuilder insertQuery = new StringBuilder();
insertQuery.append("insert into ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
insertQuery.append(tableName);
insertQuery.append(" (" + segmentColumnName + "," + valueColumnName + ")");
insertQuery.append("values ('" + segmentValue + "','" + String.valueOf(newMaxId) + "')");
int response = em.createNativeQuery(insertQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
}
} else {
String reason = "A data inconsistency has been detected between the " + tableName + " table and one or more entity tables for which it manages current max primary key values.\n" + "The inconsistency was detected between the managed class (" + mappedClass.getName() + ") and the identifier (" + segmentValue + ") in " + tableName + ". Broadleaf\n" + "has stopped startup of the application in order to allow you to resolve the issue and avoid possible data corruption. If you wish to disable this detection, you may\n" + "set the 'detect.sequence.generator.inconsistencies' property to false in your application's common.properties or common-shared.properties. If you would like for this component\n" + "to autocorrect these problems by setting the sequence generator value to a value greater than the max entity id, then set the 'auto.correct.sequence.generator.inconsistencies'\n" + "property to true in your application's common.properties or common-shared.properties. If you would like to provide a default schema to be used to qualify table names used in the\n" + "queries for this detection, set the 'default.schema.sequence.generator' property in your application's common.properties or common-shared.properties. Also, if you are upgrading\n" + "from 1.6 or below, please refer to http://docs.broadleafcommerce.org/current/1.6-to-2.0-Migration.html for important information regarding migrating your SEQUENCE_GENERATOR table.";
LOG.error("Broadleaf Commerce failed to start", new RuntimeException(reason));
System.exit(1);
}
}
}
}
}
}
}Example 6
| Project: commerce-master File: SequenceGeneratorCorruptionDetection.java View source code |
@Override
@Transactional("blTransactionManager")
public void onApplicationEvent(ContextRefreshedEvent event) {
if (detectSequenceGeneratorInconsistencies) {
SessionFactory sessionFactory = ((HibernateEntityManager) em).getSession().getSessionFactory();
for (Object item : sessionFactory.getAllClassMetadata().values()) {
ClassMetadata metadata = (ClassMetadata) item;
String idProperty = metadata.getIdentifierPropertyName();
Class<?> mappedClass = metadata.getMappedClass();
Field idField;
try {
idField = mappedClass.getDeclaredField(idProperty);
} catch (NoSuchFieldException e) {
continue;
}
idField.setAccessible(true);
GenericGenerator genericAnnot = idField.getAnnotation(GenericGenerator.class);
TableGenerator tableAnnot = idField.getAnnotation(TableGenerator.class);
String segmentValue = null;
String tableName = null;
String segmentColumnName = null;
String valueColumnName = null;
if (genericAnnot != null && genericAnnot.strategy().equals(IdOverrideTableGenerator.class.getName())) {
//This is a BLC style ID generator
for (Parameter param : genericAnnot.parameters()) {
if (param.name().equals("segment_value")) {
segmentValue = param.value();
}
if (param.name().equals("table_name")) {
tableName = param.value();
}
if (param.name().equals("segment_column_name")) {
segmentColumnName = param.value();
}
if (param.name().equals("value_column_name")) {
valueColumnName = param.value();
}
}
// to redefine them. If they aren't defined in the annotation, glean them from the defaults
if (StringUtils.isBlank(tableName)) {
tableName = IdOverrideTableGenerator.DEFAULT_TABLE_NAME;
}
if (StringUtils.isBlank(segmentColumnName)) {
segmentColumnName = IdOverrideTableGenerator.DEFAULT_SEGMENT_COLUMN_NAME;
}
if (StringUtils.isBlank(valueColumnName)) {
valueColumnName = IdOverrideTableGenerator.DEFAULT_VALUE_COLUMN_NAME;
}
} else if (tableAnnot != null) {
//This is a traditional Hibernate generator
segmentValue = tableAnnot.pkColumnValue();
tableName = tableAnnot.table();
segmentColumnName = tableAnnot.pkColumnName();
valueColumnName = tableAnnot.valueColumnName();
}
if (!StringUtils.isEmpty(segmentValue) && !StringUtils.isEmpty(tableName) && !StringUtils.isEmpty(segmentColumnName) && !StringUtils.isEmpty(valueColumnName)) {
StringBuilder sb2 = new StringBuilder();
sb2.append("select ");
sb2.append(valueColumnName);
sb2.append(" from ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
sb2.append(tableName);
sb2.append(" where ");
sb2.append(segmentColumnName);
sb2.append(" = '");
sb2.append(segmentValue);
sb2.append("'");
Long maxSequenceId = 0l;
boolean sequenceEntryExists = false;
List results2 = em.createNativeQuery(sb2.toString()).getResultList();
if (CollectionUtils.isNotEmpty(results2) && results2.get(0) != null) {
maxSequenceId = ((Number) results2.get(0)).longValue();
sequenceEntryExists = true;
}
LOG.info("Detecting id sequence state between " + mappedClass.getName() + " and " + segmentValue + " in " + tableName);
StringBuilder sb = new StringBuilder();
sb.append("select max(");
sb.append(idField.getName());
sb.append(") from ");
sb.append(mappedClass.getName());
sb.append(" entity");
List results;
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
try {
context.setInternalIgnoreFilters(true);
results = em.createQuery(sb.toString()).getResultList();
} finally {
context.setInternalIgnoreFilters(false);
}
if (CollectionUtils.isNotEmpty(results) && results.get(0) != null) {
Long maxEntityId = (Long) results.get(0);
if (maxEntityId > maxSequenceId) {
LOG.error(String.format("The sequence value for %s in %s was found as %d (or an entry did not exist) but the actual max sequence in" + " %s's table was found as %d", segmentValue, tableName, maxSequenceId, mappedClass.getName(), maxEntityId));
if (automaticallyCorrectInconsistencies) {
long newMaxId = maxEntityId + 10;
if (sequenceEntryExists) {
String log = String.format("Correcting sequences for entity %s. Updating the sequence value" + " to %d", mappedClass.getName(), newMaxId);
LOG.warn(log);
StringBuilder updateQuery = new StringBuilder();
updateQuery.append("update ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
updateQuery.append(tableName);
updateQuery.append(" set ");
updateQuery.append(valueColumnName);
updateQuery.append(" = ");
updateQuery.append(String.valueOf(newMaxId));
updateQuery.append(" where ");
updateQuery.append(segmentColumnName);
updateQuery.append(" = '");
updateQuery.append(segmentValue);
updateQuery.append("'");
int response = em.createNativeQuery(updateQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
} else {
String log = String.format("Correcting sequences for entity %s. Did not find an entry in" + " %s, inserting the new sequence value as %d", mappedClass.getName(), tableName, newMaxId);
LOG.warn(log);
StringBuilder insertQuery = new StringBuilder();
insertQuery.append("insert into ");
if (!tableName.contains(".") && !StringUtils.isEmpty(defaultSchemaSequenceGenerator)) {
sb2.append(defaultSchemaSequenceGenerator);
sb2.append(".");
}
insertQuery.append(tableName);
insertQuery.append(" (" + segmentColumnName + "," + valueColumnName + ")");
insertQuery.append("values ('" + segmentValue + "','" + String.valueOf(newMaxId) + "')");
int response = em.createNativeQuery(insertQuery.toString()).executeUpdate();
if (response <= 0) {
throw new RuntimeException("Unable to update " + tableName + " with the sequence generator id for " + segmentValue);
}
}
} else {
String reason = "A data inconsistency has been detected between the " + tableName + " table and one or more entity tables for which it manages current max primary key values.\n" + "The inconsistency was detected between the managed class (" + mappedClass.getName() + ") and the identifier (" + segmentValue + ") in " + tableName + ". Broadleaf\n" + "has stopped startup of the application in order to allow you to resolve the issue and avoid possible data corruption. If you wish to disable this detection, you may\n" + "set the 'detect.sequence.generator.inconsistencies' property to false in your application's common.properties or common-shared.properties. If you would like for this component\n" + "to autocorrect these problems by setting the sequence generator value to a value greater than the max entity id, then set the 'auto.correct.sequence.generator.inconsistencies'\n" + "property to true in your application's common.properties or common-shared.properties. If you would like to provide a default schema to be used to qualify table names used in the\n" + "queries for this detection, set the 'default.schema.sequence.generator' property in your application's common.properties or common-shared.properties. Also, if you are upgrading\n" + "from 1.6 or below, please refer to http://docs.broadleafcommerce.org/current/1.6-to-2.0-Migration.html for important information regarding migrating your SEQUENCE_GENERATOR table.";
LOG.error("Broadleaf Commerce failed to start", new RuntimeException(reason));
System.exit(1);
}
}
}
}
}
}
}Example 7
| Project: hibernate-tools-master File: EntityPOJOClass.java View source code |
public String generateAnnIdGenerator() {
KeyValue identifier = clazz.getIdentifier();
String strategy = null;
Properties properties = null;
StringBuffer wholeString = new StringBuffer(" ");
if (identifier instanceof Component) {
wholeString.append(AnnotationBuilder.createAnnotation(importType("javax.persistence.EmbeddedId")).getResult());
} else if (identifier instanceof SimpleValue) {
SimpleValue simpleValue = (SimpleValue) identifier;
strategy = simpleValue.getIdentifierGeneratorStrategy();
properties = c2j.getFilteredIdentifierGeneratorProperties(simpleValue);
StringBuffer idResult = new StringBuffer();
AnnotationBuilder builder = AnnotationBuilder.createAnnotation(importType("javax.persistence.Id"));
idResult.append(builder.getResult());
idResult.append(" ");
//TODO: how to handle generic now??
boolean isGenericGenerator = false;
if (!"assigned".equals(strategy)) {
if (!"native".equals(strategy)) {
if ("identity".equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
builder.addAttribute("strategy", staticImport("javax.persistence.GenerationType", "IDENTITY"));
idResult.append(builder.getResult());
} else if ("sequence".equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue")).addAttribute("strategy", staticImport("javax.persistence.GenerationType", "SEQUENCE")).addQuotedAttribute("generator", clazz.getClassName() + "IdGenerator");
idResult.append(builder.getResult());
builder.resetAnnotation(importType("javax.persistence.SequenceGenerator")).addQuotedAttribute("name", clazz.getClassName() + "IdGenerator").addQuotedAttribute("sequenceName", properties.getProperty(org.hibernate.id.enhanced.SequenceStyleGenerator.SEQUENCE_PARAM, null));
// TODO HA does not support initialValue and allocationSize
wholeString.append(builder.getResult());
} else if (TableGenerator.class.getName().equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue")).addAttribute("strategy", staticImport("javax.persistence.GenerationType", "TABLE")).addQuotedAttribute("generator", "generator");
idResult.append(builder.getResult());
buildAnnTableGenerator(wholeString, properties);
} else {
isGenericGenerator = true;
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
builder.addQuotedAttribute("generator", "generator");
idResult.append(builder.getResult());
}
} else {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
idResult.append(builder.getResult());
}
}
if (isGenericGenerator) {
builder.resetAnnotation(importType("org.hibernate.annotations.GenericGenerator")).addQuotedAttribute("name", "generator").addQuotedAttribute("strategy", strategy);
List<AnnotationBuilder> params = new ArrayList<AnnotationBuilder>();
//wholeString.append( "parameters = { " );
if (properties != null) {
Enumeration<?> propNames = properties.propertyNames();
while (propNames.hasMoreElements()) {
String propertyName = (String) propNames.nextElement();
AnnotationBuilder parameter = AnnotationBuilder.createAnnotation(importType("org.hibernate.annotations.Parameter")).addQuotedAttribute("name", propertyName).addQuotedAttribute("value", properties.getProperty(propertyName));
params.add(parameter);
}
}
builder.addAttributes("parameters", params.iterator());
wholeString.append(builder.getResult());
}
wholeString.append(idResult);
}
return wholeString.toString();
}Example 8
| Project: clinic-softacad-master File: AnnotationBinder.java View source code |
private static void bindGenericGenerators(XAnnotatedElement annotatedElement, Mappings mappings) {
GenericGenerator defAnn = annotatedElement.getAnnotation(GenericGenerator.class);
GenericGenerators defsAnn = annotatedElement.getAnnotation(GenericGenerators.class);
if (defAnn != null) {
bindGenericGenerator(defAnn, mappings);
}
if (defsAnn != null) {
for (GenericGenerator def : defsAnn.value()) {
bindGenericGenerator(def, mappings);
}
}
}Example 9
| Project: hibernate-core-3.6.x-mod-master File: AnnotationBinder.java View source code |
private static void bindGenericGenerators(XAnnotatedElement annotatedElement, Mappings mappings) {
GenericGenerator defAnn = annotatedElement.getAnnotation(GenericGenerator.class);
GenericGenerators defsAnn = annotatedElement.getAnnotation(GenericGenerators.class);
if (defAnn != null) {
bindGenericGenerator(defAnn, mappings);
}
if (defsAnn != null) {
for (GenericGenerator def : defsAnn.value()) {
bindGenericGenerator(def, mappings);
}
}
}Example 10
| Project: hibernate-core-ogm-master File: AnnotationBinder.java View source code |
private static void bindGenericGenerators(XAnnotatedElement annotatedElement, Mappings mappings) {
GenericGenerator defAnn = annotatedElement.getAnnotation(GenericGenerator.class);
GenericGenerators defsAnn = annotatedElement.getAnnotation(GenericGenerators.class);
if (defAnn != null) {
bindGenericGenerator(defAnn, mappings);
}
if (defsAnn != null) {
for (GenericGenerator def : defsAnn.value()) {
bindGenericGenerator(def, mappings);
}
}
}Example 11
| Project: hibernate-orm-master File: AnnotationBinder.java View source code |
private static void bindGenericGenerators(XAnnotatedElement annotatedElement, MetadataBuildingContext context) {
GenericGenerator defAnn = annotatedElement.getAnnotation(GenericGenerator.class);
GenericGenerators defsAnn = annotatedElement.getAnnotation(GenericGenerators.class);
if (defAnn != null) {
bindGenericGenerator(defAnn, context);
}
if (defsAnn != null) {
for (GenericGenerator def : defsAnn.value()) {
bindGenericGenerator(def, context);
}
}
}Example 12
| Project: exit-web-framework-master File: UniversallyUniqueIdentifier.java View source code |
@Id
@Column(length = 32)
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public String getId() {
return this.id;
}Example 13
| Project: cloudtm-data-platform-master File: Breed.java View source code |
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 14
| Project: 5.2.0.RC-master File: IdEntity.java View source code |
@Id
@GenericGenerator(name = "paymentableGenerator", strategy = "native")
@GeneratedValue(generator = "paymentableGenerator")
public Long getId() {
return id;
}Example 15
| Project: hibernate-ogm-master File: Address.java View source code |
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 16
| Project: iMatrix6.0.0Dev-master File: IdEntity.java View source code |
@Id
@GenericGenerator(name = "paymentableGenerator", strategy = "native")
@GeneratedValue(generator = "paymentableGenerator")
public Long getId() {
return id;
}Example 17
| Project: tianti-master File: MysqlSequenceIdEntity.java View source code |
@Id
@Column(length = 32, nullable = true)
@GenericGenerator(name = "sys_uuid", strategy = "uuid")
@GeneratedValue(generator = "sys_uuid")
public String getId() {
return id;
}Example 18
| Project: coner-master File: HandicapGroupSetHibernateEntity.java View source code |
@Id
@Column(name = "id")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 19
| Project: fastdfs-zyc-master File: DownloadFileRecord.java View source code |
@Id
@GeneratedValue(generator = "system_uuid")
@GenericGenerator(name = "system_uuid", strategy = "uuid")
public String getId() {
return id;
}Example 20
| Project: hibernate-search-master File: Tweet.java View source code |
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
public String getId() {
return id;
}Example 21
| Project: pedal-tx-master File: Secundus.java View source code |
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "primus"))
@Id
@GeneratedValue(generator = "generator")
@Column(name = "primus", unique = true, nullable = false)
public long getId() {
return id;
}Example 22
| Project: SocialConnect-master File: Customers.java View source code |
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
@Column(name = "CUSTOMER_ID")
public Long getCustomerId() {
return customerId;
}Example 23
| Project: springlab-master File: IdEntity.java View source code |
@Id
@GeneratedValue(generator = "UIDGenerator")
@GenericGenerator(name = "UIDGenerator", strategy = "org.springside.examples.showcase.common.dao.UIDGenerator")
public String getId() {
return id;
}Example 24
| Project: biobank-master File: AbstractBiobankModel.java View source code |
@Override
@GenericGenerator(name = "generator", strategy = "increment")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "ID", nullable = false)
public Integer getId() {
return this.id;
}Example 25
| Project: dove-master File: DictGroupPo.java View source code |
@Id
@GenericGenerator(name = "systemUUID", strategy = "uuid")
@GeneratedValue(generator = "systemUUID")
@Column(name = "ID", nullable = false, length = 32)
@Override
public String getId() {
return super.getId();
}Example 26
| Project: graniteds-master File: Contact3.java View source code |
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
public BigDecimal getId() {
return id;
}Example 27
| Project: hibernate-ogm-old-master File: Address.java View source code |
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 28
| Project: j360-master File: Entity.java View source code |
@Id
@Column(length = 32, nullable = false)
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
public String getId() {
return id;
}Example 29
| Project: jblog-master File: ArticleCommentSupport.java View source code |
// Property accessors
@GenericGenerator(name = "generator", strategy = "assigned")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "id", unique = true, nullable = false, length = 32)
public String getId() {
return this.id;
}Example 30
| Project: touchgames-master File: EntidadeRaiz.java View source code |
@Id
@GeneratedValue(generator = "tgIdGenerator")
@GenericGenerator(name = "tgIdGenerator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "initial_value", value = "1"), @Parameter(name = "force_table_use", value = "true"), @Parameter(name = "value_column", value = "ID"), @Parameter(name = "sequence_name", value = "HIBERNATE_SEQUENCE") })
public Long getId() {
return this.id;
}Example 31
| Project: webctdbexport-master File: AssmtQuestionSet.java View source code |
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "assmtSectionElement"))
@Id
@GeneratedValue(generator = "generator")
@Column(name = "ID", nullable = false, precision = 20, scale = 0)
public BigDecimal getId() {
return this.id;
}Example 32
| Project: yama-master File: DefaultJpaPersistence.java View source code |
@Id()
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 33
| Project: CMM-data-grabber-master File: DatafileTemplate.java View source code |
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public Long getId() {
return id;
}Example 34
| Project: otr-java-mirror-core-master File: AbstractEntity.java View source code |
@GenericGenerator(name = "hbm-increment", strategy = "increment")
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "hbm-increment")
public Long getId() {
return id;
}Example 35
| Project: rapid-framework-master File: Resource.java View source code |
@Id
@GeneratedValue(generator = "custom-id")
@GenericGenerator(name = "custom-id", strategy = "native")
@Column(name = "resource_id", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
public java.lang.Long getResourceId() {
return this.resourceId;
}Example 36
| Project: screensaver-master File: AttachedFileType.java View source code |
@Id
@org.hibernate.annotations.GenericGenerator(name = "attached_file_type_id_seq", strategy = "sequence", parameters = { @Parameter(name = "sequence", value = "attached_file_type_id_seq") })
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "attached_file_type_id_seq")
public Integer getAttachedFileTypeId() {
return getEntityId();
}Example 37
| Project: studygroup-jbcd-persistence-master File: Event.java View source code |
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public Long getId() {
return id;
}Example 38
| Project: activityinfo-master File: Authentication.java View source code |
/**
* Gets the secure id of this Authentication, which is a 128-bit random
* number represented as a 32-character hexadecimal string.
*
* @return the id of this authentication
*/
@Id
@Column(name = "AuthToken", unique = true, nullable = false, length = 32)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SecureSequenceGenerator")
@org.hibernate.annotations.GenericGenerator(name = "SecureSequenceGenerator", strategy = "org.activityinfo.server.authentication.SecureSequenceGenerator")
public String getId() {
return this.id;
}Example 39
| Project: jrecruiter-master File: Statistic.java View source code |
@Id
@GeneratedValue(generator = "myForeignGenerator")
@org.hibernate.annotations.GenericGenerator(name = "myForeignGenerator", strategy = "foreign", parameters = @Parameter(name = "property", value = "job"))
public Long getId() {
return this.id;
}Example 40
| Project: jresponder-master File: LogEntry.java View source code |
/**
* The PK
* @return
*/
@Id
@GeneratedValue(generator = "native")
@GenericGenerator(name = "native", strategy = "native")
@Column(name = "jr_log_entry_id")
public Long getId() {
return id;
}Example 41
| Project: PokerServer-master File: Player.java View source code |
@JsonIgnore
@Column(name = "player_id")
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 42
| Project: gluster-ovirt-poc-master File: DiskImageDynamic.java View source code |
@Override
@XmlElement(name = "Id")
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "org.ovirt.engine.core.dao.GuidGenerator")
@Column(name = "image_id")
@Type(type = "guid")
public Guid getId() {
return id;
}Example 43
| Project: hibernate-master-class-master File: OverrideIdentifierDefinitionTest.java View source code |
@Override
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
public UUID getId() {
return super.getId();
}Example 44
| Project: midpoint-master File: RTrigger.java View source code |
@Id
@GeneratedValue(generator = "ContainerIdGenerator")
@GenericGenerator(name = "ContainerIdGenerator", strategy = "com.evolveum.midpoint.repo.sql.util.ContainerIdGenerator")
@Column(name = "id")
@IdQueryProperty
public Integer getId() {
return id;
}Example 45
| Project: rainbownlp-master File: MLExampleFeature.java View source code |
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public Integer getExampleFeatureId() {
return exampleFeatureId;
}Example 46
| Project: anudc-master File: UserRegistered.java View source code |
/**
* getId
*
* Gets the id of the user
*
* <pre>
* Version Date Developer Description
* 0.1 17/05/2012 Genevieve Turner (GT) Initial
* </pre>
*
* @return the id of the user
*/
@Id
@GeneratedValue(generator = "user-pk")
@GenericGenerator(name = "user-pk", strategy = "foreign", parameters = { @Parameter(name = "property", value = "user") })
public Long getId() {
return id;
}