Java Code Examples for javax.persistence.Temporal

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project odata4j, under directory /odata4j-core/src/main/java/org/odata4j/producer/jpa/.

Source file: JPAEdmGenerator.java

  22 
vote

protected TemporalType getTemporalType(SingularAttribute<?,?> sa){
  Member member=sa.getJavaMember();
  Temporal temporal=null;
  if (member instanceof Field) {
    temporal=((Field)member).getAnnotation(Temporal.class);
  }
 else   if (member instanceof Method) {
    temporal=((Method)member).getAnnotation(Temporal.class);
  }
  return temporal == null ? null : temporal.value();
}
 

Example 2

From project tawus, under directory /tawus-core/src/main/java/com/googlecode/tawus/internal/dataanalyzers/.

Source file: TimeAnalyzer.java

  22 
vote

public String identifyDataType(PropertyAdapter adapter){
  Class<?> clazz=adapter.getType();
  Temporal annotation=adapter.getAnnotation(Temporal.class);
  if (clazz.equals(Date.class) && annotation != null && annotation.value() == TemporalType.TIME) {
    return dataType;
  }
  return null;
}
 

Example 3

From project Core_2, under directory /javaee-impl/src/main/java/org/jboss/forge/spec/javaee/jpa/.

Source file: FieldPlugin.java

  19 
vote

private Field<JavaClass> addTemporalFieldTo(final JavaClass targetEntity,final Class<?> fieldType,final String fieldName,final TemporalType temporalType) throws FileNotFoundException {
  if (targetEntity.hasField(fieldName)) {
    throw new IllegalStateException("Entity already has a field named [" + fieldName + "]");
  }
  JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  Field<JavaClass> field=targetEntity.addField();
  field.setName(fieldName).setPrivate().setType(fieldType).addAnnotation(Temporal.class).setEnumValue(temporalType);
  if (!fieldType.getName().startsWith("java.lang.") && !fieldType.isPrimitive()) {
    targetEntity.addImport(fieldType);
  }
  Refactory.createGetterAndSetter(targetEntity,field);
  updateToString(targetEntity);
  java.saveJavaSource(targetEntity);
  shell.println("Added field to " + targetEntity.getQualifiedName() + ": "+ field);
  return field;
}
 

Example 4

From project Core_2, under directory /javaee-impl/src/test/java/org/jboss/forge/spec/jpa/.

Source file: NewFieldPluginTest.java

  19 
vote

@Test public void testNewTemporalField() throws Exception {
  Project project=getProject();
  JavaClass javaClass=generateEntity(project);
  getShell().execute(ConstraintInspector.getName(FieldPlugin.class) + " temporal --named time --type TIME");
  javaClass=(JavaClass)project.getFacet(JavaSourceFacet.class).getJavaResource(javaClass).getJavaSource();
  assertTrue(javaClass.hasField("time"));
  assertEquals("Date",javaClass.getField("time").getType());
  assertEquals(TemporalType.TIME,javaClass.getField("time").getAnnotation(Temporal.class).getEnumValue(TemporalType.class));
  assertTrue(javaClass.hasImport(TemporalType.class));
  assertTrue(javaClass.hasImport(Date.class));
  assertFalse(javaClass.hasSyntaxErrors());
}
 

Example 5

From project ServiceFramework, under directory /src/net/csdn/jpa/type/impl/.

Source file: MysqlType.java

  19 
vote

public Tuple<Class,Map> dateType(String type,ConstPool constPool){
  type=type.toUpperCase();
  EnumMemberValue emb=new EnumMemberValue(constPool);
  emb.setType("javax.persistence.TemporalType");
  if (type.equals("DATE")) {
    emb.setValue("DATE");
    return new Tuple<Class,Map>(Temporal.class,map("value",emb));
  }
  if (type.equals("DATETIME")) {
    emb.setValue("DATE");
    return new Tuple<Class,Map>(Temporal.class,map("value",emb));
  }
  if (type.equals("TIMESTAMP")) {
    emb.setValue("TIMESTAMP");
    return new Tuple<Class,Map>(Temporal.class,map("value",emb));
  }
  return null;
}