Package org.exoplatform.services.database.annotation

Examples of org.exoplatform.services.database.annotation.Table


      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> void dropTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection conn = exoDatasource.getConnection();
      Statement s = conn.createStatement();
      s.execute("DROP TABLE " + table.name());
      s.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here


      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> boolean hasTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection connection = exoDatasource.getConnection();
      Statement statement = connection.createStatement();
      try
      {
         if (statement.execute("SELECT 1 FROM " + table.name()) == true)
            return true;
      }
      catch (SQLException ex)
      {
         return false;
View Full Code Here

   }

   public void mapResultSet(ResultSet resultSet, T bean) throws Exception
   {
      Class<? extends DBObject> clazz = bean.getClass();
      Table table = clazz.getAnnotation(Table.class);
      TableField[] tableFields = table.field();

      ResultSetMetaData rsmd = resultSet.getMetaData();
      int numberOfColumns = rsmd.getColumnCount();
      for (int i = 1; i <= numberOfColumns; i++)
      {
View Full Code Here

   }

   public void mapUpdate(T bean, PreparedStatement statement) throws Exception
   {
      Class<? extends DBObject> clazz = bean.getClass();
      Table table = clazz.getAnnotation(Table.class);
      TableField[] tableFields = table.field();

      int i = 1;
      for (TableField tableField : tableFields)
      {
         String fieldName = tableField.field().length() == 0 ? tableField.name() : tableField.field();
View Full Code Here

      else
      {
         builder.append(" * ");
      }

      Table table = type_.getAnnotation(Table.class);
      builder.append(" FROM ").append(table.name());
      if (parameters_.size() > 0)
      {
         builder.append(" WHERE ");
         for (int i = 0; i < parameters_.size(); i++)
         {
View Full Code Here

   }

   private String consturctCountQuery(boolean useOR)
   {
      StringBuilder builder = new StringBuilder();
      Table table = type_.getAnnotation(Table.class);
      builder.append("SELECT COUNT(*) FROM  ").append(table.name());
      if (parameters_.size() > 0)
      {
         builder.append(" WHERE ");
         for (int i = 0; i < parameters_.size(); i++)
         {
View Full Code Here

      databaseType = dbType;
   }

   public <T extends DBObject> String createSelectQuery(Class<T> type, long id) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      TableField[] fields = table.field();

      StringBuilder query = new StringBuilder("SELECT ");
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         query.append(field.name());
         if (i != fields.length - 1)
            query.append(", ");
      }
      query.append(" FROM ").append(table.name());
      if (id > -1)
         query.append(" WHERE ID = ").append(id);
      return query.toString();
   }
View Full Code Here

      return query.toString();
   }

   public <T extends DBObject> String createUpdateQuery(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      TableField[] fields = table.field();

      StringBuilder query = new StringBuilder("UPDATE ").append(table.name()).append(" SET ");
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         query.append(field.name()).append(" = '$").append(field.name()).append('\'');
         if (i != fields.length - 1)
View Full Code Here

      return query.toString();
   }

   public <T extends DBObject> String createInsertQuery(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      TableField[] fields = table.field();

      StringBuilder query = new StringBuilder("INSERT INTO ").append(table.name()).append("(ID, ");
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         query.append(field.name());
         if (i != fields.length - 1)
View Full Code Here

      return query.toString();
   }

   public <T extends DBObject> String createUpdateQuery(Class<T> type, long id) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      TableField[] fields = table.field();

      StringBuilder query = new StringBuilder("UPDATE ").append(table.name()).append(" SET ");
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         query.append(field.name()).append(" = ?");
         if (i != fields.length - 1)
View Full Code Here

TOP

Related Classes of org.exoplatform.services.database.annotation.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.