Java Code Examples for javax.persistence.Column

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: JPAMember.java

  18 
vote

private static JPAMember findByColumn(Attribute<?,?> att,String columnName,Object target){
  JPAMember rt=JPAMember.create(att,target);
  Column c=rt.getAnnotation(Column.class);
  if (c == null)   return null;
  if (columnName.equals(c.name()))   return rt;
  return null;
}
 

Example 2

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

Source file: JPAEdmGenerator.java

  17 
vote

protected EdmProperty.Builder toEdmProperty(String modelNamespace,SingularAttribute<?,?> sa){
  String name=sa.getName();
  EdmType type;
  if (sa.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED) {
    String simpleName=sa.getJavaType().getSimpleName();
    type=EdmComplexType.newBuilder().setNamespace(modelNamespace).setName(simpleName).build();
  }
 else   if (sa.getBindableJavaType().isEnum()) {
    type=EdmSimpleType.STRING;
  }
 else {
    type=toEdmType(sa);
  }
  boolean nullable=sa.isOptional();
  Integer maxLength=null;
  if (sa.getJavaMember() instanceof AnnotatedElement) {
    Column col=((AnnotatedElement)sa.getJavaMember()).getAnnotation(Column.class);
    if (col != null && Enumerable.<EdmType>create(EdmSimpleType.BINARY,EdmSimpleType.STRING).contains(type))     maxLength=col.length();
  }
  return EdmProperty.newBuilder(name).setType(type).setNullable(nullable).setMaxLength(maxLength);
}
 

Example 3

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

Source file: EntityPlugin.java

  15 
vote

@SuppressWarnings("unchecked") @DefaultCommand(help="Create a JPA @Entity") public void newEntity(@Option(required=true,name="named",description="The @Entity name") final String entityName,@Option(required=false,name="package",type=PromptType.JAVA_PACKAGE,description="The package name") final String packageName,@Option(name="idStrategy",defaultValue="AUTO",description="The GenerationType name for the ID") final GenerationType idStrategy) throws Throwable {
  final PersistenceFacet jpa=project.getFacet(PersistenceFacet.class);
  final JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  String entityPackage;
  if ((packageName != null) && !"".equals(packageName)) {
    entityPackage=packageName;
  }
 else   if (getPackagePortionOfCurrentDirectory() != null) {
    entityPackage=getPackagePortionOfCurrentDirectory();
  }
 else {
    entityPackage=shell.promptCommon("In which package you'd like to create this @Entity, or enter for default",PromptType.JAVA_PACKAGE,jpa.getEntityPackage());
  }
  JavaClass javaClass=JavaParser.create(JavaClass.class).setPackage(entityPackage).setName(entityName).setPublic().addAnnotation(Entity.class).getOrigin().addInterface(Serializable.class);
  Field<JavaClass> id=javaClass.addField("private Long id = null;");
  id.addAnnotation(Id.class);
  id.addAnnotation(GeneratedValue.class).setEnumValue("strategy",idStrategy);
  id.addAnnotation(Column.class).setStringValue("name","id").setLiteralValue("updatable","false").setLiteralValue("nullable","false");
  Field<JavaClass> version=javaClass.addField("private int version = 0;");
  version.addAnnotation(Version.class);
  version.addAnnotation(Column.class).setStringValue("name","version");
  Refactory.createGetterAndSetter(javaClass,id);
  Refactory.createGetterAndSetter(javaClass,version);
  Refactory.createToStringFromFields(javaClass,id);
  Refactory.createHashCodeAndEquals(javaClass);
  JavaResource javaFileLocation=java.saveJavaSource(javaClass);
  shell.println("Created @Entity [" + javaClass.getQualifiedName() + "]");
  shell.execute("pick-up " + javaFileLocation.getFullyQualifiedName().replace(" ","\\ "));
}
 

Example 4

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

Source file: FieldPlugin.java

  15 
vote

@Command(value="custom",help="Add a custom field to an existing @Entity class") public void newCustomField(@Option(name="named",required=true,description="The field name",type=PromptType.JAVA_VARIABLE_NAME) final String fieldName,@Option(name="type",required=true,type=PromptType.JAVA_CLASS,description="The qualified Class to be used as this field's type") final String type){
  try {
    JavaClass entity=getJavaClass();
    String javaType=(type.toLowerCase().endsWith(".java")) ? type.substring(0,type.length() - 5) : type;
    addFieldTo(entity,javaType,fieldName,Column.class);
  }
 catch (  FileNotFoundException e) {
    shell.println("Could not locate the @Entity requested. No update was made.");
  }
}
 

Example 5

From project Easy-Cassandra, under directory /src/test/java/org/easycassandra/annotations/.

Source file: AnnotationsTest.java

  15 
vote

@Test public void countColumnValueTest(){
  int objective=3;
  int counter=0;
  for (  Field field : Person.class.getDeclaredFields()) {
    if (field.getAnnotation(Column.class) != null) {
      counter++;
    }
  }
  Assert.assertEquals(counter,objective);
}
 

Example 6

From project framework, under directory /impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/template/.

Source file: JPACrud.java

  15 
vote

/** 
 * Support method which will be used for construction of criteria-based queries.
 * @param example an example of the given entity
 * @return an instance of {@code CriteriaQuery}
 */
private CriteriaQuery<T> createCriteriaByExample(final T example){
  final CriteriaBuilder builder=getCriteriaBuilder();
  final CriteriaQuery<T> query=builder.createQuery(getBeanClass());
  final Root<T> entity=query.from(getBeanClass());
  final List<Predicate> predicates=new ArrayList<Predicate>();
  final Field[] fields=example.getClass().getDeclaredFields();
  for (  Field field : fields) {
    if (!field.isAnnotationPresent(Column.class) && !field.isAnnotationPresent(Basic.class) && !field.isAnnotationPresent(Enumerated.class)) {
      continue;
    }
    Object value=null;
    try {
      field.setAccessible(true);
      value=field.get(example);
    }
 catch (    IllegalArgumentException e) {
      continue;
    }
catch (    IllegalAccessException e) {
      continue;
    }
    if (value == null) {
      continue;
    }
    final Predicate pred=builder.equal(entity.get(field.getName()),value);
    predicates.add(pred);
  }
  return query.where(predicates.toArray(new Predicate[0])).select(entity);
}
 

Example 7

From project grails-data-mapping, under directory /grails-datastore-jpa/src/main/groovy/org/grails/datastore/mapping/jpa/config/.

Source file: JpaMappingFactory.java

  15 
vote

@Override public Column createMappedForm(PersistentProperty mpp){
  Field field;
  try {
    field=mpp.getOwner().getJavaClass().getDeclaredField(mpp.getName());
    return field.getAnnotation(Column.class);
  }
 catch (  SecurityException e) {
    return null;
  }
catch (  NoSuchFieldException e) {
    return null;
  }
}
 

Example 8

From project harmony, under directory /harmony.idb/src/main/java/org/opennaas/extensions/idb/database/hibernate/.

Source file: DomSupportedAdaption.java

  15 
vote

/** 
 * @return technology adaption of the domain
 */
@Column(length=40,nullable=false) public String getAdaption(){
  if (this.adaption == null) {
    this.adaption="";
  }
  return this.adaption;
}
 

Example 9

From project harmony, under directory /harmony.idb/src/main/java/org/opennaas/extensions/idb/database/hibernate/.

Source file: DomSupportedSwitch.java

  15 
vote

/** 
 * @return technology switch of the domain
 */
@Column(nullable=false,length=40) public String getSwitch(){
  if (this.switchd == null) {
    this.switchd="";
  }
  return this.switchd;
}
 

Example 10

From project jBilling, under directory /src/java/com/sapienter/jbilling/server/user/db/.

Source file: CustomerDTO.java

  15 
vote

@Column(name="credit_limit") public BigDecimal getCreditLimit(){
  if (creditLimit == null) {
    return BigDecimal.ZERO;
  }
  return creditLimit;
}
 

Example 11

From project jBilling, under directory /src/java/com/sapienter/jbilling/server/user/db/.

Source file: CustomerDTO.java

  15 
vote

@Column(name="dynamic_balance") public BigDecimal getDynamicBalance(){
  if (dynamicBalance == null) {
    return BigDecimal.ZERO;
  }
  return dynamicBalance;
}
 

Example 12

From project ndg, under directory /ndg-server-core/src/main/java/br/org/indt/ndg/server/pojo/.

Source file: NdgUser.java

  15 
vote

@Column(name="userValidated",nullable=false) public void setUserValidated(char userValidated){
  if (userValidated == 'y' || userValidated == 'Y') {
    this.userValidated='Y';
  }
 else {
    this.userValidated='N';
  }
}
 

Example 13

From project OpenID-Connect-Java-Spring-Server, under directory /openid-connect-common/src/main/java/org/mitre/oauth2/model/.

Source file: OAuth2AccessTokenEntity.java

  15 
vote

/** 
 * @return the idTokenString
 */
@Basic @Column(name="id_token_string") public String getIdTokenString(){
  if (idToken != null) {
    return idToken.toString();
  }
 else {
    return null;
  }
}
 

Example 14

From project riftsaw-ode, under directory /dao-jpa/src/main/java/org/apache/ode/dao/jpa/scheduler/.

Source file: JobDAOImpl.java

  15 
vote

@Lob @Column(name="detailsExt") public byte[] getDetailsExt(){
  if (_details.detailsExt != null && _details.detailsExt.size() > 0) {
    try {
      ByteArrayOutputStream bos=new ByteArrayOutputStream();
      ObjectOutputStream os=new ObjectOutputStream(bos);
      os.writeObject(_details.detailsExt);
      os.close();
      return bos.toByteArray();
    }
 catch (    Exception e) {
      __log.error("Error in getDetailsExt ",e);
    }
  }
  return null;
}
 

Example 15

From project riot, under directory /content/src/org/riotfamily/pages/model/.

Source file: Site.java

  15 
vote

@Column(name="pos") public long getPosition(){
  if (position == 0) {
    position=System.currentTimeMillis();
  }
  return position;
}
 

Example 16

From project savara-core, under directory /bundles/org.savara.monitor.sstore.rdbms/src/main/java/org/savara/monitor/sstore/rdbms/.

Source file: RDBMSSession.java

  15 
vote

@Lob @Column(name="SESSION_IN_BYTE") public byte[] getByteSession(){
  if (this.session != null) {
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    ObjectOutputStream os=null;
    try {
      os=new ObjectOutputStream(bos);
      os.writeObject(this.session);
      return bos.toByteArray();
    }
 catch (    Exception e) {
      logger.log(Level.SEVERE,"Error in getting session in byte.");
    }
 finally {
      try {
        if (os != null) {
          os.close();
        }
      }
 catch (      IOException e) {
        logger.log(Level.SEVERE,"Error in closing ObjectOutputStream.");
      }
    }
  }
  return null;
}
 

Example 17

From project SeavusJB3, under directory /src/java/com/sapienter/jbilling/server/user/db/.

Source file: CustomerDTO.java

  15 
vote

@Column(name="credit_limit") public BigDecimal getCreditLimit(){
  if (creditLimit == null) {
    return BigDecimal.ZERO;
  }
  return creditLimit;
}
 

Example 18

From project SeavusJB3, under directory /src/java/com/sapienter/jbilling/server/user/db/.

Source file: CustomerDTO.java

  15 
vote

@Column(name="dynamic_balance") public BigDecimal getDynamicBalance(){
  if (dynamicBalance == null) {
    return BigDecimal.ZERO;
  }
  return dynamicBalance;
}
 

Example 19

From project SpringLS, under directory /src/main/java/com/springrts/springls/.

Source file: Account.java

  15 
vote

/** 
 * Returns the most recent IP used to log into this account as string. This should be used in persistence and lobby protocol specific parts only.
 * @see #getLastIp()
 */
@Column(name="last_ip",unique=false,nullable=false,insertable=true,updatable=true,length=15) public String getLastIpAsString(){
  if (lastIp == null) {
    return NO_ACCOUNT_LAST_IP_STR;
  }
 else {
    return lastIp.getHostAddress();
  }
}
 

Example 20

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HTextFlow.java

  15 
vote

@Override @NotEmpty @Type(type="text") @AccessType("field") @CollectionOfElements(fetch=FetchType.EAGER) @JoinTable(name="HTextFlowContent",[email protected](name="text_flow_id")) @IndexColumn(name="pos",nullable=false) @Column(name="content",nullable=false) public List<String> getContents(){
  copyLazyLoadedRelationsToHistory();
  if (contents == null) {
    contents=new ArrayList<String>();
  }
  return contents;
}
 

Example 21

From project zanata, under directory /zanata-model/src/main/java/org/zanata/model/.

Source file: HTextFlow.java

  15 
vote

@OneToMany(cascade=CascadeType.ALL,mappedBy="textFlow") @org.hibernate.annotations.MapKey(columns={@Column(name="locale")}) @BatchSize(size=10) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE) public Map<Long,HTextFlowTarget> getTargets(){
  if (targets == null) {
    targets=new HashMap<Long,HTextFlowTarget>();
  }
  return targets;
}