Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ <h1>New Entity Classes from Database Wizard: Mapping Options</h1>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3a1-t4" headers="r1c1-t4">
<p>Date/Time API</p>
</td>
<td align="left" headers="r3a1-t4 r1c2-t4">Select the Java type family used for temporal columns (<code dir="ltr">DATE</code>, <code dir="ltr">TIME</code>, <code dir="ltr">TIMESTAMP</code>).
<p>When <code dir="ltr">java.util.Date</code> is selected, columns are mapped to <code dir="ltr">java.util.Date</code> with a <code dir="ltr">@Temporal</code> annotation. When <code dir="ltr">java.time (Java 8+)</code> is selected, columns are mapped to <code dir="ltr">java.time.LocalDate</code>, <code dir="ltr">java.time.LocalTime</code> and <code dir="ltr">java.time.LocalDateTime</code>, which are mapped natively by JPA 2.2 and later and therefore need no <code dir="ltr">@Temporal</code> annotation. <code dir="ltr">java.util.Date</code> is selected by default.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t4" headers="r1c1-t4">
<p>Fully Qualified Database Table Names</p>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

package org.netbeans.modules.j2ee.persistence.entitygenerator;

/**
* The Java type family used to map temporal database columns
* ({@code DATE}, {@code TIME}, {@code TIMESTAMP}) when generating entity
* classes from a database.
*
* @see <a href="https://github.com/apache/netbeans/issues/3755">NETBEANS-3755</a>
*/
public enum DateTimeType {

/**
* Legacy mapping: every temporal column becomes a {@code java.util.Date}
* annotated with {@code @Temporal}. This is the default for backward
* compatibility.
*/
LEGACY,

/**
* Modern mapping using the {@code java.time} classes introduced in Java 8
* ({@code LocalDate}, {@code LocalTime}, {@code LocalDateTime}). These are
* mapped natively by JPA 2.2+ and therefore need no {@code @Temporal}
* annotation.
*/
JAVA_8;
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ LBL_FETCH_EAGER=eager
LBL_TABLE_NAME=Fully &Qualified Database Table Names
LBL_REGENERATE_TABLES=Attributes for &Regenerating Tables
LBL_COLLECTOIN_TYPE=&Collection Type:
LBL_DATE_TIME_TYPE=&Date/Time API:
LBL_DATE_TIME_LEGACY=java.util.Date
LBL_DATE_TIME_JAVA8=java.time (Java 8+)
TXT_SelectedTables=Selected Tables
TXT_AvailableTables=Available Tables
LBL_Progress_Adding_Classpath=Adding J2EE apis to project classpath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.netbeans.modules.j2ee.persistence.entitygenerator.CMPMappingModel.ColumnData;
import org.netbeans.modules.j2ee.persistence.entitygenerator.EntityClass;
import org.netbeans.modules.j2ee.persistence.entitygenerator.EntityMember;
import org.netbeans.modules.j2ee.persistence.entitygenerator.DateTimeType;
import org.netbeans.modules.j2ee.persistence.entitygenerator.EntityRelation.CollectionType;
import org.netbeans.modules.j2ee.persistence.entitygenerator.EntityRelation.FetchType;
import org.netbeans.modules.j2ee.persistence.entitygenerator.RelationshipRole;
Expand Down Expand Up @@ -150,7 +151,7 @@ public void generateBeans(final ProgressPanel progressPanel,
helper.isFullyQualifiedTableNames(), helper.isRegenTablesAttrs(),
helper.isUseDefaults(),
helper.isGenerateMappedSuperclasses(),
helper.getFetchType(), helper.getCollectionType(),
helper.getFetchType(), helper.getCollectionType(), helper.getDateTimeType(),
handle, progressPanel, helper.getProject());
}

Expand All @@ -159,23 +160,23 @@ void generateBeans(EntityClass[] entityClasses, boolean generateNamedQueries,
boolean generateJAXBAnnotations,
boolean generateValidationConstraints,
boolean fullyQualifiedTableNames, boolean regenTablesAttrs,
FetchType fetchType, CollectionType collectionType,
FetchType fetchType, CollectionType collectionType, DateTimeType dateTimeType,
ProgressContributor progressContributor, ProgressPanel panel, Project prj) throws IOException {
generateBeans(entityClasses, generateNamedQueries, generateJAXBAnnotations,
generateValidationConstraints, fullyQualifiedTableNames, regenTablesAttrs,
false, false, fetchType, collectionType, progressContributor, panel, prj);

generateBeans(entityClasses, generateNamedQueries, generateJAXBAnnotations,
generateValidationConstraints, fullyQualifiedTableNames, regenTablesAttrs,
false, false, fetchType, collectionType, dateTimeType, progressContributor, panel, prj);

}


private void generateBeans(EntityClass[] entityClasses, boolean generateNamedQueries,
boolean generateJAXBAnnotations,
boolean generateValidationConstraints,
boolean fullyQualifiedTableNames, boolean regenTablesAttrs,
boolean useDefaults,
boolean generateMappedSC,
FetchType fetchType, CollectionType collectionType,
FetchType fetchType, CollectionType collectionType, DateTimeType dateTimeType,
ProgressContributor progressContributor, ProgressPanel panel, Project prj) throws IOException {

int progressMax = entityClasses.length * 3;
Expand All @@ -200,7 +201,7 @@ private void generateBeans(EntityClass[] entityClasses, boolean generateNamedQue
fullyQualifiedTableNames, regenTablesAttrs,
useDefaults,
generateMappedSC,
fetchType, collectionType,
fetchType, collectionType, dateTimeType,
progressContributor, panel, this).run();
addToPersistenceUnit(result);
progressContributor.progress(progressMax);
Expand Down Expand Up @@ -329,6 +330,7 @@ private static final class Generator {
private final boolean regenTablesAttrs, generateMappedSC;
private final FetchType fetchType;
private final CollectionType collectionType;
private final DateTimeType dateTimeType;
private final Set<FileObject> generatedEntityFOs;
private final Set<FileObject> generatedFOs;
private final PersistenceGenerator persistenceGen;
Expand All @@ -342,7 +344,7 @@ public Generator(EntityClass[] entityClasses, boolean generateNamedQueries,
boolean fullyQualifiedTableNames, boolean regenTablesAttrs,
boolean useDefaults,
boolean generateMappedSC,
FetchType fetchType, CollectionType collectionType,
FetchType fetchType, CollectionType collectionType, DateTimeType dateTimeType,
ProgressContributor progressContributor, ProgressPanel progressPanel,
PersistenceGenerator persistenceGen) {
this.entityClasses = entityClasses;
Expand All @@ -355,6 +357,7 @@ public Generator(EntityClass[] entityClasses, boolean generateNamedQueries,
this.regenTablesAttrs = regenTablesAttrs;
this.fetchType = fetchType;
this.collectionType = collectionType;
this.dateTimeType = dateTimeType;
this.progressContributor = progressContributor;
this.progressPanel = progressPanel;
generatedFOs = new HashSet<FileObject>();
Expand Down Expand Up @@ -811,12 +814,22 @@ protected VariableTree createVariable(EntityMember m) {

String getMemberType(EntityMember m) {
String memberType = m.getMemberType();
if ("java.sql.Date".equals(memberType)) { //NOI18N
memberType = "java.util.Date";
} else if ("java.sql.Time".equals(memberType)) { //NOI18N
memberType = "java.util.Date";
} else if ("java.sql.Timestamp".equals(memberType)) { //NOI18N
memberType = "java.util.Date";
if (DateTimeType.JAVA_8.equals(dateTimeType)) {
if ("java.sql.Date".equals(memberType)) { //NOI18N
memberType = "java.time.LocalDate"; //NOI18N
} else if ("java.sql.Time".equals(memberType)) { //NOI18N
memberType = "java.time.LocalTime"; //NOI18N
} else if ("java.sql.Timestamp".equals(memberType)) { //NOI18N
memberType = "java.time.LocalDateTime"; //NOI18N
}
} else {
if ("java.sql.Date".equals(memberType)) { //NOI18N
memberType = "java.util.Date"; //NOI18N
} else if ("java.sql.Time".equals(memberType)) { //NOI18N
memberType = "java.util.Date"; //NOI18N
} else if ("java.sql.Timestamp".equals(memberType)) { //NOI18N
memberType = "java.util.Date"; //NOI18N
}
}
return memberType;
}
Expand All @@ -834,6 +847,11 @@ private boolean isDecimalType(String type) {
}

private String getMemberTemporalType(EntityMember m) {
// java.time types are mapped natively by JPA 2.2+ and must not
// carry a @Temporal annotation.
if (DateTimeType.JAVA_8.equals(dateTimeType)) {
return null;
}
String memberType = m.getMemberType();
String temporalType = null;
if ("java.sql.Date".equals(memberType)) { //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="3" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand All @@ -98,14 +98,14 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="5" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="paddingPanel">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="8" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="1.0"/>
<GridBagConstraints gridX="0" gridY="9" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>

Expand Down Expand Up @@ -161,7 +161,7 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="5" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="6" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand All @@ -179,7 +179,7 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="6" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="7" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand All @@ -197,7 +197,37 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="7" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="8" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="dateTimeLabel">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="dateTimeComboBox"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties" key="LBL_DATE_TIME_TYPE" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JComboBox" name="dateTimeComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="12" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
Expand Down
Loading