2013年7月20日土曜日

ESX Serverを利用した仮想環境構築

OSをESX Serverに入れたいとき → ovfファイルを作成後、以下の画像のようにしてデプロイする。



Networkがつながらないとき → DHCPでいったんマシンがどのLAN内に存在するかを確認。

Domainに参加する → LocalDomainのAdministratorでログインしている場合、Passwordが引き継がれる。ログインするときは、参加するDomain名を指定して、Administratorログインすればよい。

WindowsServer2012で.NET3.Xを入れたい → WindowsUpdateで入れる。WindowsUpdateで入れられない場合は、InstallCDが必要。

WindowsUpdateがつながらない → Proxyを確認

MSSQL20XXがInstallできない → OSにServicePackが充ててあるか確認

2013年7月19日金曜日

WindowsServer2012でテスト環境としてActiveDirectoryを簡易構築

WindowsServer2012でクラスタ環境を構築し、検証をする必要がでてきた。
クラスタ環境を構築するためには、ActiveDirectoryを入れる必要がある。

WindowsServer2012は、2008R2などと同様にしてADを追加できる。

手順は、ServerManagementからAdd roles and featuresでADを選択するだけ。

1つ注意すべきは、テスト環境として構築するためには、ADを入れているサーバを
ドメインコントローラーにする必要がある。
このサーバをドメインコントローラーにするには、Add roles and features時に、
ダイアログ操作をするが、そのダイアログ内からリンクでとべ、
ドメインコントローラーの設定が可能だ。

また、ADを入れていると、MSSQL2012をインストールすることは出来たが、
ログインすることができなかった。

調査した所、動作はするとのことだが、推奨しない、とのこと。

2013年6月29日土曜日

RailsのDatabase確認

RailsプロジェクトのRootで
rake dbconsole

もしくは、同じディレクトリで、
sqlite3を使用しているなら、
sqlite3 'DatabaseのPath'

ちなみに、DatabaseのPathは、
config/database.yml

に書いてあります。

2013年6月3日月曜日

複数メソッドに跨ったトランザクション処理

SpringのTransactionを利用せずに、自分でTransactionを制御したい。
SpringのTransactionは、1メソッド内で完結する必要があるが、私がやりたいことは、複数メソッドにまたがってTransactionを維持したいのである。

それをするには、Transactionを持ち回わらなければいけない。
Hibernateでは、EntityManagerからTransactionを取得することが禁止されているようであるが、それを取得するメソッドが公開されている。恐らく設定なのだろう。

java.sql.Connectionクラスを使って、おとなしくDBからデータ取得して、Mapにでも詰めるのがベターなのだろうか。

しかし、私が取得したいデータは複数にまたがっているので、データ取得時に、JOINしないとダメかな。

取りあえず、単純にDBからQuery発行して直接データ取得した後、Objectにデータ詰めたいですって人には、以下のURLが参考になると思います。

http://www.codeproject.com/Tips/372152/Mapping-JDBC-ResultSet-to-Object-using-Annotations

2013年5月31日金曜日

[ Hibernate ] ORDER BYの結果を上から10件取得する

PureJavaで、ORDER BYでソートした後、その結果を、先頭から10件ずつデータを取得したかったので、FROM句以下でサブクエリを作った。

SELECT * FROM (SELECT * FROM table ORDER BY table.date ASC) WHERE ROWNUM <= 10

これを、EntityManagerから、createQuery( query )をCallしてSQLを実行するも失敗。

↓の仕様をみると、


HQL 副問い合わせは、 select または where 節だけで使われることに注意してください。

FROM句で使えないので、はまりました。

で、解決策は、PureJavaのjavax.persistence.QueryのsetMaxResults()を使って引数に10を入れれば、ソート後の結果から10件取得できました。

2013年5月14日火曜日

hamlの準備

rails generate した後に、hamlを使うようにする準備
1.Gemfileに以下の1行を記載
    gem 'haml-rails'
2.bundle install

hamlの準備をしていない時のErrorには、hamlを取り扱えるよ!、という記載がないが、hamlの準備をしたら、取り扱えるようになっていた!


ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):



ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):


あと、MissingTemplateがでる理由だが、ルーティングを間違えていた。

/app/views/コントローラー名/アクション名.html.haml

ex)
/app/views/hello/view.html.haml
の場合、URLは以下のようになる。
http://localhost:3000/hello/view

ちなみに、アクション名は、コントローラでは以下の色付きのところ。

-------


# codinf: utf-8

class HelloController < ApplicationController
  def view
    @msg = 'Hello World from view'
  end
end

2013年1月2日水曜日

herokuでsqlite3からpostgresqlへ

sqlite3 -> postgresql にDBを変更する時のログ。

$ heroku rake db:migrate</ br> ! For Cedar apps, use: `heroku run rake db:migrate` $ heroku run rake db:migrate</ br> Running rake db:migrate attached to terminal... up, run.5672 DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from at /app/Rakefile:9) DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from at /app/Rakefile:9) Connecting to database specified by DATABASE_URL Migrating to CreateMessages (20121222150925) == CreateMessages: migrating ================================================= -- create_table(:messages) NOTICE: CREATE TABLE will create implicit sequence "messages_id_seq" for serial column "messages.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "messages_pkey" for table "messages" -> 0.0589s == CreateMessages: migrated (0.0590s) ========================================