Skip to content

Commit

Permalink
feat: allow integer id
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhouti committed Mar 24, 2024
1 parent ffda950 commit ff5c329
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ import java.util.UUID;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
<%_ } _%>
<%_ if (!embedded && primaryKey.hasInteger) { _%>
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
<%_ } _%>

<%_ if (fieldsContainBigDecimal) { _%>
import static <%= packageName %>.web.rest.TestUtil.sameNumber;
Expand Down Expand Up @@ -439,6 +443,11 @@ if (field.fieldTypeString || field.blobContentTypeText) {

private static Random random = new Random();
private static AtomicLong count = new AtomicLong(random.nextInt() + ( 2 * Integer.MAX_VALUE ));
<%_ } _%>
<%_ if (!embedded && primaryKey.hasInteger) { _%>

private static Random random = new Random();
private static AtomicInteger count = new AtomicInteger(random.nextInt() + ( 2 * Integer.MAX_VALUE ));
<%_ } _%>

@Autowired
Expand Down Expand Up @@ -1373,7 +1382,7 @@ _%>
// Disconnect from session so that the updates on updated<%= persistClass %> are not directly saved in db
em.detach(updated<%= persistClass %>);
<%_ } _%>
<%_ if (fluentMethods && fieldsToTest.length > 0) { _%>
<%_ if (fluentMethods && fieldsToTest.filter(f => !f.id).length > 0) { _%>
updated<%= persistClass %><% for (field of fieldsToTest.filter(f => !f.id)) { %>
.<%= field.fieldName %>(<%= 'UPDATED_' + field.fieldNameUnderscored.toUpperCase() %>)<% if (field.fieldTypeBinary && !field.blobContentTypeText) { %>
.<%= field.fieldName %>ContentType(<%= 'UPDATED_' + field.fieldNameUnderscored.toUpperCase() %>_CONTENT_TYPE)<% } %><% } %>;
Expand Down
6 changes: 6 additions & 0 deletions generators/generator-base-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,9 @@ module.exports = class JHipsterBasePrivateGenerator extends Generator {
if (primaryKeyType === TYPE_UUID) {
return this.getJavaValueGeneratorForType(primaryKeyType);
}
if (primaryKeyType === TYPE_INTEGER) {
return `${defaultValue}`;
}
return `${defaultValue}L`;
}

Expand All @@ -1362,6 +1365,9 @@ module.exports = class JHipsterBasePrivateGenerator extends Generator {
if (type === 'Long') {
return 'count.incrementAndGet()';
}
if (type === 'Integer') {
return 'count.incrementAndGet()';
}
throw new Error(`Java type ${type} does not have a random generator implemented`);
}

Expand Down
6 changes: 5 additions & 1 deletion utils/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { CommonDBTypes } = require('../jdl/jhipster/field-types');
const { isReservedTableName } = require('../jdl/jhipster/reserved-keywords');
const constants = require('../generators/generator-constants');

const { BOOLEAN, LONG, STRING, UUID } = CommonDBTypes;
const { BOOLEAN, LONG, STRING, UUID, INTEGER } = CommonDBTypes;
const { NO: NO_DTO, MAPSTRUCT } = MapperTypes;
const { PAGINATION, INFINITE_SCROLL } = PaginationTypes;
const { SERVICE_IMPL } = ServiceTypes;
Expand Down Expand Up @@ -293,6 +293,7 @@ function derivedPrimaryKeyProperties(primaryKey) {
_.defaults(primaryKey, {
hasUUID: primaryKey.fields && primaryKey.fields.some(field => field.fieldType === UUID),
hasLong: primaryKey.fields && primaryKey.fields.some(field => field.fieldType === LONG),
hasInteger: primaryKey.fields && primaryKey.fields.some(field => field.fieldType === INTEGER),
typeUUID: primaryKey.type === UUID,
typeString: primaryKey.type === STRING,
typeLong: primaryKey.type === LONG,
Expand Down Expand Up @@ -361,6 +362,9 @@ function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator, enable
get columnName() {
return idCount === 1 ? field.columnName : `${generator.getColumnName(relationship.relationshipName)}_${field.columnName}`;
},
get columnType() {
return field.columnType;
},
get reference() {
return fieldToReference(entityWithConfig, this);
},
Expand Down

0 comments on commit ff5c329

Please sign in to comment.