Package org.exoplatform.services.database.annotation

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


      return query.toString();
   }

   public <T extends DBObject> String createInsertQuery(Class<T> clazz, long id) throws Exception
   {
      Table table = clazz.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 createRemoveQuery(Class<T> type, long id) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      StringBuilder builder = new StringBuilder("DELETE FROM ");
      builder.append(table.name()).append(" WHERE ID = ").append(id).toString();
      return builder.toString();
   }
View Full Code Here

      tableManager.createTable(ExoLongID.class, true);
   }

   public ExoLongID loadObjectByName(String name) throws Exception
   {
      Table table = ExoLongID.class.getAnnotation(Table.class);
      StringBuilder builder = new StringBuilder("SELECT EXO_NAME, EXO_START FROM ");
      builder.append(table.name()).append(" WHERE EXO_NAME = '").append(name).append('\'');
      return loadUnique(builder.toString());
   }
View Full Code Here

      exoDatasource = datasource;
   }

   public <T extends DBObject> void createTable(Class<T> type, boolean dropIfExist) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Cannot find the annotation for class " + type.getClass().getName());
      }
      StringBuilder builder = new StringBuilder(1000);
      builder.append("CREATE TABLE ").append(table.name()).append(" (");
      appendId(builder);
      TableField[] fields = table.field();
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         String fieldType = field.type();
         if ("string".equals(fieldType))
         {
            appendStringField(field, builder);
         }
         else if ("int".equals(fieldType))
         {
            appendIntegerField(field, builder);
         }
         else if ("long".equals(fieldType))
         {
            appendLongField(field, builder);
         }
         else if ("float".equals(fieldType))
         {
            appendFloatField(field, builder);
         }
         else if ("double".equals(fieldType))
         {
            appendDoubleField(field, builder);
         }
         else if ("boolean".equals(fieldType))
         {
            appendBooleanField(field, builder);
         }
         else if ("date".equals(fieldType))
         {
            appendDateField(field, builder);
         }
         else if ("binary".equals(fieldType))
         {
            appendBinaryField(field, builder);
         }
         if (i != fields.length - 1)
            builder.append(", ");
      }
      builder.append(")");

      // print out the sql string
      Connection conn = exoDatasource.getConnection();
      conn.setAutoCommit(false);
      Statement statement = conn.createStatement();
      System.out.println("QUERY: \n  " + builder + "\n");
      if (dropIfExist && hasTable(type))
         statement.execute("DROP TABLE IF EXISTS " + table.name());
      statement.execute(builder.toString());
      statement.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here

      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

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.